What is the DTX file format?
A .dtx file is a Documented LaTeX Source file - the standard format for distributing LaTeX packages on CTAN (the Comprehensive TeX Archive Network). The format implements a literate programming approach: a single .dtx file interleaves the package's runnable source code with its full typeset documentation in one self-contained plain-text file.
The mechanism relies on DocStrip, a utility included with every TeX distribution. Guard comments in the form % <guard> mark which lines belong to the implementation and which are pure documentation. Running latex package.ins (using the companion .ins installer file) strips out documentation markers and extracts the usable .sty or .cls package files. Running pdflatex package.dtx instead typesets the full manual - complete with annotated, syntax-highlighted source code.
Nearly every CTAN package ships as a .dtx + .ins pair. The .ins file is a short DocStrip script that tells the extractor what output files to produce and where to place them.
.dtx files are plain UTF-8 (or ASCII) text and open in any text editor, though TeX-aware editors such as TeXstudio or Texmaker provide syntax highlighting. The ltxdoc document class, part of the LaTeX kernel, is used to typeset .dtx documentation and provides environments for annotating macro definitions alongside their source code.
Security & safety
RISK: LOWDTX files are plain-text source files; they pose no direct execution risk when opened in a text editor. Compiling an untrusted .dtx with LaTeX carries the same risk as running any LaTeX document: malicious TeX code could execute shell commands if --shell-escape is enabled. Do not compile .dtx files from untrusted sources with shell-escape enabled.
Format details
in a nutshellPrograms that open DTX files
latex package.ins via the Tools menu to extract .sty files. latex package.ins in terminal to extract .sty/.cls; run pdflatex package.dtx to build PDF docs. Technical details
deep spec| Encoding | Plain text - ASCII or UTF-8 |
| Mechanism | DocStrip literate programming system (Frank Mittelbach, 1989) |
| Guard syntax | % <guard> comments control which lines are extracted as code vs. typeset as documentation |
| Companion file | .ins installer script drives DocStrip extraction process |
| Extraction command | latex package.ins - produces .sty or .cls output files |
| Documentation command | pdflatex package.dtx - typesets annotated source manual |
| Documentation class | ltxdoc (part of LaTeX kernel); provides \DescribeMacro and \DescribeEnv environments |
| Typical file size | 5 KB - 500 KB (large packages with full documentation can reach several MB) |
| Distribution platform | CTAN (Comprehensive TeX Archive Network) - virtually all CTAN packages use .dtx |
| Operating systems | Windows, Linux, macOS |
| Output files | .sty (package) or .cls (document class) extracted by DocStrip from the .dtx source |
| Container | Plain text; no binary wrapper or compression |
| Released | 1989 (DocStrip mechanism introduced with LaTeX2e era) |
| Latest version | no versioned format spec; governed by current DocStrip and ltxdoc packages in TeX Live |
| Open standard | Yes · royalty-free |
| Specification | ctan.org |
DTX conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about DTX files.
Frequently asked questions
How do I install a .dtx package into LaTeX?
latex package.ins (the companion installer file) to extract the .sty file, then move it to your local texmf tree and run texhash. Or use your distribution's package manager (tlmgr / MiKTeX Package Manager).Can I open a .dtx file without LaTeX installed?
What is the difference between .dtx and .ins?
How do I read the documentation of a .dtx package?
pdflatex package.dtx to generate a PDF manual. Many CTAN packages also host the pre-built PDF.