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.