detex
TLDR
Remove LaTeX commands from a file
SYNOPSIS
detex [options] [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 typically removed unless -m is specified. With -e, it follows \\input directives to process multi-file documents.
Output is the document text without markup, suitable for piping to spell checkers, word processors, or text analysis tools.
PARAMETERS
-e
Expand \\input and \\include directives.-l
Force LaTeX mode processing.-m
Retain dollar signs and math content.-n
Show names of unknown environments.-s
Replace math with space instead of removing.-t
Force plain TeX mode.-w
Output one word per line.
EXAMPLE
\documentclass{article}
\begin{document}
Hello \textbf{world}! Here is $x^2$ math.
\end{document}
Hello world! Here is math.
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 Langley and later maintained by various contributors. It has been a standard tool in TeX distributions since the 1980s, providing an essential bridge between LaTeX documents and plain text tools. Despite its age, it remains useful for basic LaTeX-to-text conversion.


