Program listings

There are some things to watch out for when doing program listings. Let's say that we want to put the following fragment of code into DocBook:

#include <stdio.h>
int main ()
        int count = 3;
        while (count--)
                printf ("Count is now %d\n", count);

To do this you need to enclose it in a programlisting tag, and also make it into CDATA (i.e. literal text) so that <stdio.h> isn't interpreted as an SGML tag. The tags you need for this are:


The next thing to bear in mind is that Tab characters will not be expanded to spaces, so you will need to do all the indenting with spaces.


There seems to be a bug in jade at the moment that causes incorrect TeX output for "--" (i.e. two dashes). For the work-around that I'm using, see the source for this document.