detex
strip LaTeX commands from documents
TLDR
SYNOPSIS
detex [-clnstw] [-e environment-list] [file...]
DESCRIPTION
detex strips LaTeX and TeX commands from documents, leaving plain text. This is useful for spell checking, word counting, text analysis, and extracting readable content from LaTeX source files.The tool handles standard LaTeX constructs: commands, environments, comments, and special characters. Math mode content is removed (use -r to substitute readable placeholders). By default detex follows \\input and \\include directives to process multi-file documents, using the TEXINPUTS environment variable to locate them; -n disables this.Output is the document text without markup, suitable for piping to spell checkers, word processors, or text analysis tools.
PARAMETERS
-c
In LaTeX mode, echo the arguments of \\cite, \\ref, and \\pageref macros.-e environment-list
Comma-separated list of environments to ignore (replaces the defaults: array, eqnarray, equation, longtable, picture, tabular, verbatim).-l
Force LaTeX mode processing.-n
Do not follow \\input and \\include commands (single file processing).-r
Replace math with the placeholder words "noun" and "verbs" to keep sentences readable.-s
Replace control sequences with a space (old behavior; may break accented words).-t
Force plain TeX mode.-w
Output one word per line.
INSTALL
CAVEATS
Complex or non-standard LaTeX may not process correctly. Some packages define commands that detex doesn't recognize. Math removal may affect context in technical documents. The tool doesn't handle bibliographies or index entries specially.
HISTORY
detex was originally written by Daniel Trinkle of the Computer Science Department at Purdue University. It has been a standard tool in TeX distributions since the 1980s and is maintained today as OpenDetex. Despite its age, it remains useful for basic LaTeX-to-text conversion.
