8

The ltxdoc class, designed for documenting LaTeX source files, is based on the article class. Beyond a certain threshold, the documentation may need to be divided in chapters and another class, e.g. the report one, would be more appropriate.

Hence my question: is there a way to document LaTeX source files using the ltxdoc class but with report as underlying class? Or is the best way to build the documentation in a separate document where the class can be chosen?

Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85

1 Answers1

8

You can use scrlfile from KOMA-script.

\listfiles
\RequirePackage{scrlfile}
\ReplaceClass{article}{report}
\documentclass{ltxdoc}
\begin{document}
\section{test}
\end{document}

That gives me the following

*File List*
scrlfile.sty    2012/06/15 v3.12 KOMA-Script package (loading files)
  ltxdoc.cls    2007/11/11 v2.0u Standard LaTeX documentation class
  report.cls    2007/10/19 v1.4h Standard LaTeX document class
  size10.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
     doc.sty    2010/02/04 v2.1e Standard LaTeX documentation package (FMi)
multicol.sty    2011/06/27 v1.7a multicolumn formatting (FMi)
 ***********

Unfortunately, as soon as a \maketile command is run, everything breaks. There is a pretty simple reason for that. ltxdoc loads the package doc as well, which is redefining maketitle. This way, you can use multiple titles in one document (according to the documentation of doc). Loading package titlepage lets the error dissappear. But there is one drawback: The command \maketitle isn't doing anything now.
But: You can save the original definition of maketitle (by the report class) and later (after doc is processed) you can restore it.

\listfiles
\RequirePackage{scrlfile}
\ReplaceClass{article}{report}
\BeforePackage{doc}{\let\oldmaketitle\maketitle}
\documentclass{ltxdoc}
\author{Some one}
\title{some thing}
\usepackage{blindtext}
\let\maketitle\oldmaketitle
\begin{document}
\maketitle
\blinddocument
\end{document}

If you want to do this is for you to decide.
By the way: \BeforePackage is also provided by scrlfile.

Johannes_B
  • 24,235
  • 10
  • 93
  • 248