latexmk
Automatically build LaTeX documents
TLDR
Compile a DVI (Device Independent file) document from every source
Compile a DVI document from a specific source file
Compile a PDF document
Open the document in a viewer and continuously update it whenever source files change
Force the generation of a document even if there are errors
Clean up temporary TEX files created for a specific TEX file
Clean up all temporary TEX files in the current directory
SYNOPSIS
latexmk [OPTION]... [filename]
PARAMETERS
-pdf
Set output to PDF via pdflatex (default in modern setups)
-dvi
Set output to DVI via latex
-ps
Set output to PostScript via latex + dvips
-pdfdvi
PDF via latex + dvipdf
-pvc
Continuously preview and rebuild on file changes
-pv
Preview once after successful build
-f
Force required runs, continue past errors
-FF
Force and remove source aux files if outdated
-c
Clean auxiliary files (but keep main output)
-C
Full clean, including main output files
-jobname=NAME
Set output filename stem
-outdir=DIR
Put output files in DIR
-auxdir=DIR
Put auxiliary files in DIR
-cd
Chdir to source file directory
-e 'CODE'
Execute Perl CODE at startup
-r
Use rules from .latexmkrc exclusively
-verbose
Provide more detailed output
-silent
Reduce output verbosity
-halt-on-error
Stop on compilation errors
-synctex=1
Enable SyncTeX for editor-viewer sync
-use-make
Use make for dependencies
-deps
Output dependency list for make
DESCRIPTION
Latexmk is a powerful Perl-based tool for automating the compilation of LaTeX documents. It intelligently determines the sequence of commands needed to produce output files (DVI, PDF, PS), running programs like pdflatex, bibtex, makeindex, dvips, and others as required by dependencies.
Latexmk excels at handling multi-pass compilations for bibliographies, indices, glossaries, and graphics. It avoids redundant runs by tracking source changes and rule dependencies. Features include continuous preview mode (-pvc) for real-time updates in viewers like xdvi or evince, forceful rebuilds (-f), and cleanup of auxiliary files (-c).
Customization occurs via .latexmkrc files, allowing overrides for commands, directories, and Perl code execution. Widely used in academic and technical writing, it saves time on complex documents and integrates with editors like Vim, Emacs, and TeXShop.
CAVEATS
Requires Perl and full TeX distribution (TeX Live/MiKTeX).
Complex custom workflows may need .latexmkrc tweaks.
Not for plain TeX; LaTeX-focused. Continuous preview (-pvc) demands compatible viewer.
CONFIGURATION FILES
Uses $HOME/.latexmkrc, .latexmkrc, or latexmkrc for settings like
$pdflatex = 'pdflatex -interaction=nonstopmode %O %S';
Supports -rc to read extra RC files.
CUSTOM RULES
Define custom dependencies and subroutines in RC file, e.g.,
add_cus_dep('ntb', 'tb', 0, 'makeindex_ntb');
Ideal for glossaries or custom indices.
HISTORY
Originally developed by David Barnes in 1980s as 'texmake'. Rewritten by Rob Reisner as 'latexmk' in early 1990s. Maintained by John Collins since 1994 with major Perl rewrite in 2002 (version 3). Version 4 (2007+) added PDF support, better dependency tracking. Integral to TeX Live since 2005; current v4.85+ supports LuaLaTeX, XeLaTeX.


