[texhax] listings' alignment function

Neal H. Walfield neal at walfield.org
Wed Jan 11 11:43:41 CET 2012


Hi,

I like the listings package a lot, in particular, I like that I don't
need to use an ugly monospace font to have the code reasonably well
aligned.  I'd like to improve the alignment a bit.  Consider the
following C code:

  for (s = list;
       s;
       s = g_slist_next (s))
    ...

The three s's are supposed to be aligned.  Unfortunately, they are
not.  listings does not realize that an open parenthesis indicates
where the text on the following line should start.  It instead formats
the code as follows:

  for (s = list;
          s;
          s = g_slist_next (s))
    ...

It's acceptable, but not pretty.

Is there a way to do what I want?  Perhaps some function that I'm
overlooking that says, align here, e.g.:

  for (\alignhere{}s = list;
       s;
       s = g_slist_next (s))
    ...

Thanks,

Neal


More information about the texhax mailing list