Ads by Google

Wednesday, June 4, 2008

Listing code snippets in LaTeX

There are a number of ways and packages that provide for code listings in LaTeX. One that I personally prefer and that has enough options to customise is the listings package. It provides a multitude of options to pretty print code snippets. It has support for a number of languages which is more along the lines of keywords that is just about enough for code listings.

It has features to
  • Number the lines
  • keyword highlighting
  • Ability to add your own keywords
  • provide background colour
  • whitespace identification for languages that need them
  • labeling them for cross reference
One other feature is the ability to reuse the definitions into a style format, so that the same environment can be reused with a minimal of code repetition. And the documentation is excellent with lots of examples and feature setting explanation. For code which is indented, it also allows the verbatim code to be shrunk to fit the page(in the default font size, it does scroll off the page), though it does affect the readability of the page.

No comments: