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.
showexplpackage provides this functionality. It is also included inydocwhich is however not stable yet. – Martin Scharrer May 07 '11 at 19:09lstdoc. However, reading the developers' docs forlistingshas alerted me to the\newdocenvironmentcommand, which solves a different problem that had bothered me. – Ryan Reich May 08 '11 at 13:15