[NTG-context] listings.sty
Aditya Mahajan
adityam at umich.edu
Fri Jul 11 00:02:28 CEST 2008
Quoting Mohamed Bana <abbg770 at city.ac.uk>:
> nico <nicolas.marsgui <at> libertysurf.fr> writes:
>
>>
>> I don't see the point. The native ConTeXt verbatim support seems to cover
>> all what listings can do.
>>
>> The wiki page gives some examples:
>> http://wiki.contextgarden.net/Verbatim_text
>>
>> Regards,
>> BG
>>
>
>
> Hi,
>
> take a look at
> http://vega.soi.city.ac.uk/~abbg770/listing-sample.pdf, note you
> can customize the style of the font numbering, you can place a caption and my
> favourite is the colouring; if you use Eclipse you'll notice that
> it's the same
> colour the editor uses.
This can be done easily with current ConTeXt, for example:
\setupcolors[state=start]
\starttext
\setuplinenumbering[location=intext]
\setuptyping[option=color]
\startJV
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
\stopJV
See the wiki page for adding line numbering and frames (or ask here if
the wiki page is confusing). It is possible to change the color scheme
and the wiki page gives an example. To make sure that the frames break
around pages, you will need to use backgroundtext rather than
framedtext.
The only advantage of listings is that it provides support for a *lot*
of languages out of the box. Writing a syntax highlighter is not easy.
I mean, you need to define all kinds of keywords, write regex or
parser for identifying comments, strings, escape sequences etc. No
matter what language is used to write a syntax highlighter, writing a
good syntax highlighter takes time. And hence the advantage of
listing. In terms of features, I think it is not difficult to add the
required display features in ConTeXt. Line numbering every n lines[1],
using proportional fonts, fancy frames, etc are pretty
straight-forward things.
One option for the long term could be to write a module for mkiv, that
can parse the syntax highlighting files of some editor and use them
directly. Since most decent editors have syntax highlighting files for
lot of languages, we will not have to do the hard work. (well, in case
you don't like any available syntax highlighting, and want to roll
your own, then it is a different matter).
There is a module that uses vim to generate syntax highlighting. Mojca
started the module, and I extended it when I needed syntax
highlighting for a project. After that, I have not really updated it.
It works by using vim to generate a tex file which is then read by
context. The only drawback is the starting and stopping times of vim
are fairly large (few secs for each file to be transformed).
Aditya
[1] Actually, line numbering every n lines is already supported.
More information about the ntg-context
mailing list