While writing a report about SystemTap in LaTeX I had to figure out how to get LaTeX to nicely color my listings, because the report featured some source code.
By default, the Listings package does not support SystemTap (see chapter 2.4 of the Listings Package user guide). Since SystemTap syntax is very similar to C, I first tried that option, but alas no luck. The problem lies in the fact that SystemTap does not use semicolons to end a statement, therefore the C syntax highlighter gets very confused.
However, it is quite simple to extend the Listings package with custom syntax highlighting (defining a new language, to be precise). Here is the snippet I used:
After also setting some colors for keywords, comments et cetera:
I got some nice results:
Here is a full example:
Don’t forget to include the
xcolor package for colored listings, too!
By the way, this is a nice way to create inline source code listings in LaTeX (put the
newcommand in your preamble):