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.

  • 2
    The showexpl package provides this functionality. It is also included in ydoc which is however not stable yet. Commented May 7, 2011 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
    Commented May 8, 2011 at 13:15

1 Answer 1


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.

  • 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
    Commented May 8, 2011 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.
    – yannisl
    Commented May 8, 2011 at 3:18
  • I see; it's good to know how that is done. Thanks!
    – Ryan Reich
    Commented May 8, 2011 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .