During a discussion of this question, I looked a bit into the pkgindoc.sty buried in ltclass.dtx (docstrip option afterpreamble). While I understand how this works (and it works in an ugly way IMHO), I am quite curious if anybody knows what the original purpose of it was (and whether it's documented anywhere)? (It seems that pkgindoc.sty is not generated during normal LaTeX installation, and I've never heard about it from anywhere, including the previous two answers to the above-mentioned question.)
Here is the relevant section from ltclass.dtx for reference:
71 After Preamble
Finally we declare a package that allows all the commands declared above to be
\@onlypreambleto be used after\begin{document}.⟨*afterpreamble⟩ \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{pkgindoc} [1994/10/20 v1.1 Package Interface in Document (DPC)] \def\reserved@a#1\do\@classoptionslist#2\do\filec@ntents#3\relax{% \gdef\@preamblecmds{#1#3}} \expandafter\reserved@a\@preamblecmds\relax ⟨/afterpreamble⟩