ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* numbered programlistings
@ 2002-06-12 17:45 Kris Hermans
  2002-06-12 20:00 ` Berend de Boer
  2002-06-13  7:29 ` Hans Hagen
  0 siblings, 2 replies; 3+ messages in thread
From: Kris Hermans @ 2002-06-12 17:45 UTC (permalink / raw)


Hi again!

I'm writing a programming tutorial with ConTeXt. Therefore I have
programlistings that I want to reference in my text. My idea is to labels
together with verbatim text.

For instance:

\definelabel[programlisting][text=listing,
                             location=inmargin,
                             headstyle=small]

And in my text I write:

\listing\starttyping
/* first.c : my first C program */
#include <stdio.h>

int main()
{
  puts("Hello Everybody!");
  return 0;
}
\stoptyping

This all works fine, but I expected the label ("listing 1.1") to appear in
the margin AT THE SAME LINE as the first line of my programlisting (/*
first.c ... */). However, the label is somewhat above the actual verbatim
text.

Any tips on how to solve this are welcome!

thanks in advance,

Kris Hermans


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: numbered programlistings
  2002-06-12 17:45 numbered programlistings Kris Hermans
@ 2002-06-12 20:00 ` Berend de Boer
  2002-06-13  7:29 ` Hans Hagen
  1 sibling, 0 replies; 3+ messages in thread
From: Berend de Boer @ 2002-06-12 20:00 UTC (permalink / raw)
  Cc: ConTeXt Mailing List

"Kris Hermans" <KrisHermans@advalvas.be> writes:

> I'm writing a programming tutorial with ConTeXt. Therefore I have
> programlistings that I want to reference in my text. My idea is to labels
> together with verbatim text.

No idea how to solve this (ask a TeX guru :-), but two things that
might help you, in case you didn't know them:

1. You can use \typefile to type a .c file directly. This way, you can
   make sure your programs actually compile and that there is no
   mismatch between the sources and the document.

2. It is not that difficult to add syntax high-lighting for C. Perhaps
   someone has already done that? That way you can get pretty
   printing for free, another advantage of batch typesetting above
   WYSIWG systems.

-- 
Live long and prosper,

Berend de Boer


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: numbered programlistings
  2002-06-12 17:45 numbered programlistings Kris Hermans
  2002-06-12 20:00 ` Berend de Boer
@ 2002-06-13  7:29 ` Hans Hagen
  1 sibling, 0 replies; 3+ messages in thread
From: Hans Hagen @ 2002-06-13  7:29 UTC (permalink / raw)
  Cc: ConTeXt Mailing List

At 07:45 PM 6/12/2002 +0200, Kris Hermans wrote:
>Hi again!
>
>I'm writing a programming tutorial with ConTeXt. Therefore I have
>programlistings that I want to reference in my text. My idea is to labels
>together with verbatim text.
>
>For instance:
>
>\definelabel[programlisting][text=listing,
>                              location=inmargin,
>                              headstyle=small]
>
>And in my text I write:
>
>\listing\starttyping
>/* first.c : my first C program */
>#include <stdio.h>
>
>int main()
>{
>   puts("Hello Everybody!");
>   return 0;
>}
>\stoptyping
>
>This all works fine, but I expected the label ("listing 1.1") to appear in
>the margin AT THE SAME LINE as the first line of my programlisting (/*
>first.c ... */). However, the label is somewhat above the actual verbatim
>text.

This is because there is a \blank line preceding the typing, so better is:

\definelabel[programlisting][text=listing,
                              headstyle=small]

And in my text I write:

\margintitle{\programlisting}

\starttyping
/* first.c : my first C program */
#include <stdio.h>

int main()
{
   puts("Hello Everybody!");
   return 0;
}
\stoptyping

However, i would go for:

\definetyping
   [listing]
   [before=\margintitle{\programlisting}\blank,
    after=\blank]

\startlisting
/* first.c : my first C program */
#include <stdio.h>

int main()
{
   puts("Hello Everybody!");
   return 0;
}
\stoplisting

Which is (1) more structured, (2) can be adapted without changing the 
source, (3) saves keystrokes, and (4) looks nicer in the source code.

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-06-13  7:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-12 17:45 numbered programlistings Kris Hermans
2002-06-12 20:00 ` Berend de Boer
2002-06-13  7:29 ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).