Latexmk --- Automating the document compiling process
In order to explain the various possibilities with Latexmk, we will first briefly discuss versions of the LaTex engine.
Versions of the LaTex engine
* Historically, the command latex <filename> produced output as a .dvi file, a special format that had to be converted into a .ps or a .pdf file, which was, and is, the desired final output.
* pdflatex, a later development which outputs .pdf directly, without needing any conversion. This is the most common verson used at the department, and probably around the world.
* lualatex, the most modern development which also produces .pdf output. This is the recommended versioin for any modern development. It has a number of advantages:
- it has much richer font possibilities than the earlier versions.
- its various capacities are limited only by the host machine, not by arbitrary constants used at build time. This may be important, especially when processing complicated tikz/pgfplots documents.
- parts of its implementation is based on the lua scripting language, which may be accesible directly from the document itself.
Latexmk --- Automating the document compiling process
Latexmk completely automates the process of compiling a LaTeX document. Essentially, it is like a specialized relative of the general make utility, but one which determines dependencies automatically and has some other very useful features. In its basic mode of operation latexmk is given the name of the primary source file for a document, and it issues the appropriate sequence of commands to generate a .dvi, .ps, .pdf and/or hardcopy version of the document.
Command line:
latexmk [options] [file]
The most common options:
- -latex
- Generate dvi version of the document. Do not convert to .ps or .pdf. This is the default if no other option is given.
- -lualatex
- Use the lualatex engine to process the file. Only output .pdf.
- -outdir=FOO
- Sets the directory for the output files to FOO
- Generate .pdf version of the document using pdflatex
- -pv
- Open a viewer for the resulting document.
- -pvc
- Run the document previewer continuously such that every time a source file is saved, the file is processed and then shown in the viewer.
In order to automate the option handling, an initialization file can be used. This file should be called .latexmkrc and put in the user's home directory. For Linux it can also be $HOME/.config/latexmk/latexmkrc. A suitable initialization file is the following:
Download and put in one of the places indicated above. As it stands it puts all output files in a ./build directory, and uses lualatex to process the document. This can easily be changed by opening the file in any suitable text editor.
In order to use latexmk with the TexStudio tool, a few configuration changes should be made to the Build screen so that it looks as follows: