TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing some documentation for a LaTeX package, in which I am going to be including some example LaTeX code. What is the best way to typeset that code? I know I could just use verbatim, but it would be nice to get syntax highlighting. I realize that this is a duplicate of this question, in which the consensus was to use the listings package. The problem with listings is that it seems to only have a driver for TeX, not LaTeX. For example, when I typeset something like this:

  This is a test!

it results in something like this:

  This is a test!

which is obviously messed up.

Is there a LaTeX-specific driver for listings? If not, is there another package that does syntax highlighting for LaTeX code?

share|improve this question
up vote 27 down vote accepted

You need to give the 'sub-language' for TeX:

language = [LaTeX]{TeX}

As you are writing a package, you might also want to use the moretexcs key to add 'new' LaTeX commands. For example, in my siunitx I have very long list:

  moretexcs    = 

to cover all of the new macros it adds, plus ones from other packages that are in the documentation and are not known to listings.

share|improve this answer

minted uses the pygments interpreter, which understands TeX, so this might be a valid option.

share|improve this answer
The problem with using minted is that this document is going to be distributed as a .dtx and many users won't have minted installed (and will thereby not be able to compile the documentation). – ESultanik Nov 24 '10 at 19:02

Just for reference, another solution using the pygments interpreter is texments

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.