I am a big fan of latexmk
and lately I have been looking a bit towards LuaTeX. However I am yet to find a way to get the functionality of latexmk (mainly recompilation on changes and automatic rerun an appropriate number of times to resolve cross references and such) for LuaTex. Is there something similar and if not how do you LuaTeX people survive without it? :)
5 Answers
You can use Lua(La)TeX
with latexmk
by setting the -pdflatex
parameter:
-pdflatex=<program>
- set program used for pdflatex.
(replace '<program>
' by the program name)
So latexmk
should call lualatex
instead of pdflatex
if you invoke it like this:
latexmk -pdflatex=lualatex -pdf <texfile>
or with newer versions of latexmk
there is direct Lua(La)TeX
/XeLaTeX
support:
-lualatex
Use lualatex. That is, use lualatex to process the source file(s) to pdf (in place of pdflatex).
This option is exactly equivalent to specifying the following sequence of options:
-pdflatex="lualatex %O %S" -pdf -dvi- -ps-
-
4
Instead of adding the -lualatex
flag to each application of latexmk
, you could
place the following
$pdflatex = 'lualatex -file-line-error %O %S'; $pdf_mode = 1;
in an '.latexmkrc' file. This file should reside in your home folder, if you use
lualatex
in all your jobs, or in the folder(s) where your lualatex
jobs are.
More generally, you will find a host of examples and boilerlate code for .latexmkrc
in the respective CTAN repository
Since version 4.51
of latexmk, you can use the following .latexmkrc
:
$pdf_mode = 4;
$postscript_mode = $dvi_mode = 0;
-
1For the second line
$postscript_mode = $dvi_mode = 0;
, I think both default to false/0 anyway. Commented Mar 23, 2019 at 22:17 -
1For more info latexmk man page: "$pdf_mode [0] ... If equal to 4, generate a pdf version of the document using lualatex".– eugenhuCommented Oct 2, 2021 at 7:04
The following syntax is valid, as of latexmk
4.80. To have latexmk
use LuaLaTeX to build a PDF file (the usual choice), just do
latexmk -pdflua foo.tex
Alternatively you could use the seemingly equivalent -lualatex
option instead of -pdflua
. To add the -shell-escape
option, since this was asked about in a comment, just do
latexmk -pdflua -shell-escape foo.tex
This is directly from the documentation one obtains from texdoc latexmk
, namely the latexmk
manual. One can get a shorter help summary from latexmk -h
or latexmk --help
. There is also some additional documentation in the latexmk
source file, which is a Perl script, specifically about how latexmk
detects build dependencies.
Additional comment. The current manual says the following
-lualatex
Use lualatex. That is, use lualatex to process the source file(s) to pdf. The generation of dvi and postscript files is turned off. This option is equivalent to using the following set of options
-pdflua -dvi- -ps-
This appears to be incorrect or out of date. Perhaps it was correct once. But just using -pdflua
does not generate any DVI or PostScript files. It would be surprising if it did. So I presume the -lualatex
and the -pdflua
options are the same. At any rate, I cannot see any differences between them.
-
Technically, if everything is as it appears,
-lualatex
does do the same thing as-pdflua -dvi- -ps-
(and both these options are equivalent to-pdflua
). It is inaccurate to say the manual is "incorrect"; maybe it would be more accurate to say the manual is "misleading" because it adds the extra-dvi- -ps-
when there is no need to do so. Commented Jul 15, 2023 at 4:33
I currently run MacTeX under macOS Ventura, and I use lualatex
as my default engine for everything nowadays. This is my current .latexmkrc
file, which I keep in my home directory.
# Custom .latexmkrc file.
# Always create PDFs and set default engine to LuaLaTeX.
$pdf_mode = 4;
# Set the lualatex variable.
$lualatex = 'lualatex --file-line-error %O %S';
# The next two preview variables are mutually exclusive!
# Preview after each build.
# Equivalent to -pv on command line.
# $preview_mode = 1;
# Preview continuously.
# Equivalent to -pvc on command line.
# $preview_continuous_mode = 1;
# Comment out to use Preview.app.
# Give -pv on the command line.
$pdf_previewer = 'open -a Skim.app %S';
# Special latexmk makeindex line for .dtx files.
$makeindex = "makeindex -s gind.ist %O -o %D %S";
# Files to be cleaned.
$clean_ext = "deriv equ glo gls gsprogs hd listing lol" .
" _minted-%R/* _minted-%R nav snm synctex.gz tcbtemp vpprogs";
The very last line is treated as having a comment by the code formatting here, but it is not a comment in the .latexmkrc
file.