LinuxCommandLibrary

latexmk

Automatically build LaTeX documents

TLDR

Compile a DVI (Device Independent file) document from every source

$ latexmk
copy

Compile a DVI document from a specific source file
$ latexmk [path/to/source.tex]
copy

Compile a PDF document
$ latexmk -pdf [path/to/source.tex]
copy

Open the document in a viewer and continuously update it whenever source files change
$ latexmk -pvc [path/to/source.tex]
copy

Force the generation of a document even if there are errors
$ latexmk -f [path/to/source.tex]
copy

Clean up temporary TEX files created for a specific TEX file
$ latexmk -c [path/to/source.tex]
copy

Clean up all temporary TEX files in the current directory
$ latexmk -c
copy

SYNOPSIS

latexmk [options] [target...]

PARAMETERS

-pdf
    Produce PDF output.

-ps
    Produce PostScript output.

-dvi
    Produce DVI output.

-pdflatex=PROG
    Specify the program to use instead of pdflatex.

-latex=PROG
    Specify the program to use instead of latex.

-bibtex=PROG
    Specify the program to use instead of bibtex.

-makeindex=PROG
    Specify the program to use instead of makeindex.

-c
    Clean auxiliary files.

-C
    Clean more aggressively.

-f
    Force recompilation.

-pvc
    Preview, continuously update, and exit when previewer is closed.

-silent
    Run silently.

-version
    Show version number.

-help
    Show help message.

DESCRIPTION

Latexmk automates the process of compiling LaTeX documents. It monitors source files for changes and automatically reruns LaTeX, BibTeX, MakeIndex, and other necessary programs until all cross-references are resolved and the document is up-to-date. This simplifies the compilation process, especially for complex documents with bibliographies, indexes, and multiple cross-references. Latexmk can be configured through command-line options and configuration files to handle a wide variety of LaTeX workflows. It greatly reduces the manual effort required to produce a correctly typeset document by iteratively executing LaTeX and related tools. It also correctly handles errors produced by the compilers and can provide suggestions to fix them. Furthermore, it handles external programs automatically. Latexmk is very flexible and extensible; new dependency rules can be added, along with pre- and post-processing routines. It is highly customizable to adapt to different build systems and project structures, eliminating the need for complex makefiles.

CAVEATS

Latexmk requires Perl to be installed and configured correctly. Complex configurations may require advanced knowledge of LaTeX and build processes.

CONFIGURATION FILES

Latexmk can be configured using configuration files, allowing users to customize its behavior and specify project-specific settings. Configuration files are typically named .latexmkrc or latexmk.ini. These files can be used to define custom rules, specify different compilers, and configure various other aspects of the build process.

These files can exist system-wide, per-user or project specific. The system-wide file is usually located under /etc folder.

DEPENDENCY TRACKING

Latexmk automatically tracks dependencies between source files, ensuring that only the necessary files are recompiled when changes are made. This significantly speeds up the build process for large documents. It examines the log file to see what source files are required.

HISTORY

Latexmk was created to automate the tedious and error-prone process of compiling LaTeX documents. It grew out of the need to simplify the build process for large and complex documents with many cross-references, bibliographies, and indexes. Over time, it has evolved to support a wide range of LaTeX workflows and build systems, becoming a popular tool for both novice and experienced LaTeX users.

SEE ALSO

latex(1), pdflatex(1), bibtex(1), makeindex(1)

Copied to clipboard