[Tex/LaTex] Documentation Generator for LaTeX

documentationtex-general

Is there Documentation Generator for LaTeX like Javadoc for Java or Doxygen for C++?

Especially when defining macros or environments for LaTeX-files throughout a big project it would be useful for the team to have a nice documentation at best auto generated from commentary in the LaTeX-file.

Best Answer

The LaTeX Project have developed a series of tools to help documenting (La)TeX code: this is hardly surprising given the fact hat LaTeX itself is a large and complex piece of software. The combination of various pieces of the 'jigsaw' leads to a file format known as .dtx ('documented (La)TeX source' or something like that). This format combines the ability to extract code from the source using DocStrip with mark-up tools for creating documentation using the doc package. I've written about the format before and provided a starting point for creating an 'all in one' .dtx. A minimal-ise version might look something like

% \iffalse meta-comment
%<*driver>
\documentclass{ltxdoc}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% 
% \section{The documentation}
% 
% \DescribeMacro{\examplemacro}
%   Some text about an example macro called \cs{examplemacro}, which
%   might have an optional argument \oarg{arg1} and mandatory one
%   \marg{arg2}. 
%
% \section{The code}
%
% Start the DocStrip guard for extracting the code.
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%    
% \begin{macro}{\examplemacro}
%   Something about the implementation here, perhaps.
%    \begin{macrocode}
\newcommand*\examplemacro[2][]{%
  Some code here, probably
}
%    \end{macrocode}
%\end{macro} 
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}

where I've not provided the .ins file necessary to extract the code from the source, just the necessary set up to typeset some comments.

This format is used a lot by LaTeX package authors, so there are many variations on the standard set up on CTAN.