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

It appears that the listings package provides another package, called lstdoc, which in some unknown fashion provides facilities for printing TeX code samples while simultaneously TeXing them into the documentation itself. Looking at listings.dtx, it seems that the samples in listings.pdf itself were typeset in this manner. In fact, most package documentation provides such samples (code side-by-side with its effect) though I don't know how they all do it. This is actually a tricky thing to get right by hand, so lstdoc looks like it would be useful; alas, I cannot find a single documented reference to it, neither in listings.pdf itself nor anywhere on CTAN or the Internet in general.

My question, then: how does this package work? How can I learn about it? Even a cursory glance at listings.dtx tells me nothing other than that it is somewhere in there.

share|improve this question
The showexpl package provides this functionality. It is also included in ydoc which is however not stable yet. – Martin Scharrer May 7 '11 at 19:09
@Martin: This looks rather more complete than lstdoc. However, reading the developers' docs for listings has alerted me to the \newdocenvironment command, which solves a different problem that had bothered me. – Ryan Reich May 8 '11 at 13:15
up vote 6 down vote accepted

It is in listings.dtx. Search for:

             [\filedate\space\fileversion\space(Carsten Heinz)]

It is a useful package, besides its presentational aspects. I use quite often, its sorting routine. See for example Adding a list of bios to the book class.

share|improve this answer
I found that line, but it doesn't seem to indicate anything special in the way of documentation. Where are the publicly-accessible macros in lstdoc defined? – Ryan Reich May 8 '11 at 1:51
@Ryan Reich To print the developer's guide and all documentation there are instructions at the end of the general guide. You need to create a lstdoc.cfg file. If you just want to read through in the dtx read from line 14905, the macro you looking is lstxsample. – Yiannis Lazarides May 8 '11 at 3:18
I see; it's good to know how that is done. Thanks! – Ryan Reich May 8 '11 at 13:09

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.