latexmk
perl script that automates LaTeX document compilation
TLDR
Compile a LaTeX document to PDF
SYNOPSIS
latexmk [-pdf|-xelatex|-lualatex] [-pvc] [-c|-C] [options] [file.tex]
DESCRIPTION
latexmk is a Perl script that automates LaTeX document compilation. It determines the correct sequence and number of runs needed, automatically running latex, bibtex/biber, makeindex, and other tools as required.
LaTeX documents often need multiple passes: cross-references, bibliographies, and indexes require running latex/bibtex repeatedly. Latexmk analyzes log files and auxiliary files to determine when recompilation is needed and in what order.
The preview continuously mode (-pvc) watches source files and recompiles on changes. Combined with a PDF viewer that auto-refreshes (like Zathura, Skim, or SumatraPDF), this provides a live preview workflow.
Configuration can be set in latexmkrc files (system-wide, user, or project-specific). Common settings include default options, custom rules for specialized processing, and viewer preferences.
For complex documents with custom build steps, latexmk supports custom dependency rules and processing scripts, making it adaptable to most LaTeX workflows.
PARAMETERS
-pdf
Generate PDF via pdflatex.-xelatex
Generate PDF via xelatex.-lualatex
Generate PDF via lualatex.-dvi
Generate DVI file.-ps
Generate PostScript file.-pvc
Preview continuously (watch mode).-pv
Preview after compilation.-c
Clean up auxiliary files.-C
Clean up all generated files including output.-f
Force processing past errors.-g
Force full processing (ignore timestamps).-silent
Reduce output verbosity.-verbose
Increase output verbosity.-interaction= mode
Set interaction mode: nonstopmode, batchmode, errorstopmode.-shell-escape
Enable shell escape (for packages like minted).-output-directory= dir
Output directory for generated files.-auxdir= dir
Directory for auxiliary files.-jobname= name
Set output base name.-bibtex
Run bibtex/biber when needed.-recorder
Enable recorder to track file dependencies.
CAVEATS
Requires Perl. Some packages may need special latexmkrc rules. Preview mode viewer support varies by platform. Shell escape enables arbitrary code execution - use only with trusted documents. May not detect all dependency changes.
HISTORY
latexmk was written by John Collins, building on earlier work by Evan McLean and others. The script has been continuously maintained and updated since the 1990s, becoming the standard automation tool for LaTeX compilation. It's included in TeX Live and MiKTeX distributions.
