UK TeX FAQ -- question label dtx

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

LaTeX2e, and many support 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 (see books on TeX), 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.

`.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.

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

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