### Documented LaTeX sources (`.dtx` files)

LaTeX2e, and most contributed macro packages, are now written in a literate programming style, with source and documentation in the same file. This format, known as ‘doc’, in fact originated before the days of the LaTeX project as one of the “Mainz” series of packages. The documented sources conventionally have the suffix `.dtx`, and should normally be stripped of documentation before use with LaTeX. Alternatively you can run LaTeX on a `.dtx` file to produce a nicely formatted version of the documented code. An installation script (with suffix `.ins`) is usually provided, which needs the standard LaTeX2e docstrip package (among other things, the installation process strips all the comments that make up the documentation for speed when loading the file into a running LaTeX system). Several packages can be included in one `.dtx` file, with conditional sections, and there facilities for indices of macros etc. Anyone can write `.dtx` files; the format is explained in The LaTeX Companion, and a tutorial is available from CTAN (which comes with skeleton `.dtx` and `.ins` files).

Composition of `.dtx` files is supported in emacs by Matt Swift’s swiftex system: it provides a `doc-tex` mode which treats `.dtx` files rather better than AUC-TeX manages.

Another useful way of generating `.dtx` files is to write the documentation and the code separately, and then to combine them using the makedtx system. This technique has particular value in that the documentation file can be used separately to generate HTML output; it is often quite difficult to make LaTeX to HTML conversion tools deal with `.dtx` files, since they use an unusual class file.

`.dtx` files are not used by LaTeX after they have been processed to produce `.sty` or `.cls` (or whatever) files. They need not be kept with the working system; however, for many packages the `.dtx` file is the primary source of documentation, so you may want to keep `.dtx` files elsewhere.

An interesting sideline to the story of `.dtx` files is the docmfp package, which extends the model of the doc package to Metafont and MetaPost, thus permitting documented distribution of bundles containing code for Metafont and MetaPost together with related LaTeX code.

`clsguide.pdf`
  macros/latex/doc/clsguide.pdf
`docmfp.sty`
  macros/latex/contrib/docmfp (gzipped tar, browse)
`docstrip.tex`
  Part of the LaTeX distribution
`DTX tutorial`
  info/dtxtut (gzipped tar, browse)
`makedtx`
  support/makedtx (gzipped tar, browse)
`swiftex.el`
  support/emacs-modes/swiftex (gzipped tar, browse)

This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=dtx