latexpand
Expand LaTeX documents by inlining included files
TLDR
Simplify the specified source file and save the result to the specified output file
Do not remove comments
Do not expand \includes, \inputs etc.
Expand \usepackages as far as the corresponding STY files can be found
Inline the specified BBL file
SYNOPSIS
latexpand [options]
PARAMETERS
--version
Show version number and exit.
--help
Show help message and exit.
-d
Specify a directory to search for included files. This option can be used multiple times.
-f
Read variable assignments from the specified file.
-D
Define a variable to be substituted in the LaTeX source. This can be used to override variable definitions in files given using -f.
-I
Add directory to the list of directories to search for include files (same as -d).
The input LaTeX file to be expanded.
The output file to write the expanded LaTeX code. If omitted, the output is written to standard output.
DESCRIPTION
latexpand is a preprocessor for LaTeX documents that resolves \include
, \input
, and \usepackage
directives by inlining the contents of the referenced files into a single output file. This facilitates easier compilation, debugging, and distribution of complex LaTeX projects. It recursively expands all dependencies to create a self-contained LaTeX file. It also allows for variable substitution within the LaTeX source using a macro-like system, which can be valuable for customizing builds. This command is helpful for situations where external programs need to process LaTeX source or for generating reports from existing LaTeX documents with dynamic content.
CAVEATS
latexpand might not handle all edge cases of LaTeX syntax perfectly.
It's primarily designed for relatively standard LaTeX documents using \include
, \input
, and \usepackage
. Complex macro definitions or unusual package usage might lead to unexpected results.
VARIABLE SUBSTITUTION
latexpand supports variable substitution using a simple syntax. Variables are defined using -D
or -f
and referenced in the LaTeX source using a specific delimeter (details about the correct syntax can be found in the latexpand documentation). This allows for dynamic generation of LaTeX documents based on external data or configuration files.
EXAMPLE USAGE
latexpand -D title="My Report" -I /path/to/includes input.tex output.tex
This expands input.tex
, searching for include files in /path/to/includes
, defines the variable title
as 'My Report' and writes the result to output.tex
.
SEE ALSO
latex(1)