LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

detex

strip LaTeX commands from documents

TLDR

Remove LaTeX commands from a file
$ detex [document.tex]
copy
Process and output to file
$ detex [document.tex] > [output.txt]
copy
Process a single file without following \\input and \\include
$ detex -n [document.tex]
copy
Force LaTeX mode regardless of content
$ detex -l [document.tex]
copy
Replace math with placeholder words to keep sentences readable
$ detex -r [document.tex]
copy
Output a word list (one word per line, e.g. for counting)
$ detex -w [document.tex] | wc -l
copy

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

sudo apt install texlive-binaries
copy
sudo dnf install texlive
copy
sudo apk add texlive
copy
sudo zypper install texlive
copy
brew install texlive
copy

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.

SEE ALSO

latex(1), aspell(1), pandoc(1), tex(1)

RESOURCES

Copied to clipboard
Kai