My .latexmkrc is set up for passing -synctex=1 to pdflatex in order to be able to jump back from my pdf viewer to the sources:

$pdflatex='pdflatex -synctex=1 %O %B';
$pdf_previewer="start okular %O %S";

This works well. However, I need to use lualatex to compile some document, as one of the packages it uses is not supported by pdflatex. I can use latexmk -lualatex -synctex=1 document.tex to have synctex enabled in that case, but I'd like to tweak my .latexmkrc in order to be able to only have to type latexmk -lualatex document.tex while still getting synctex information (and keeping pdflatex as the default if -lualatex is not specified on the command line). I haven't succeeded so far. In particular, adding the line

$lualatex='lualatex -synctex=1 %O %B';

either before or after the definition of $pdflatex in .latexmkrc does not do anything. Is such thing possible?

NB: in case it matters, my version of latexmk (as reported by -v) is 4.41

  • The latexmk author is on the site, so he'll probably give his take on this at some point. Sounds odd that the lualatex line should not work, but I cannot test until tomorrow. Exactly which OS are you using?
    – daleif
    Commented Nov 21, 2016 at 20:05
  • @daleif I'm using Linux (Debian testing). In case it matters, perl -v reports 5.24.1 +60 Debian patches
    – Virgile
    Commented Nov 22, 2016 at 10:04
  • If you look in the code there is no $lualatex, the -lualatex option actually mess with $pdflatex (I looked in the latest version on CTAN). You probably need to send a feature request to the author. I agree there ought to be a $lualatex variable to play with.
    – daleif
    Commented Nov 22, 2016 at 10:34
  • You're right. I was mislead by your answer here mentioning $lualatex in the configuration file. That said, I'd be comfortable with @extra_pdflatex_options if I can get some assurance that its name and behavior is somewhat stable.
    – Virgile
    Commented Nov 22, 2016 at 15:59
  • 2
    The situation will change in the next release of latexmk. There'll be $lualatex that will do what you want. (There'll also be a similar $xelatex variable.) Commented Dec 7, 2016 at 13:19

4 Answers 4


With latexmk version 4.61, you can run

latexmk -showextraoptions

to get a list of options that may be given to latexmk and passed through to (pdf)latex. Amongst these options you can find synctex, so

latexmk -lualatex -synctex=1

in one off situations. In a latexmkrc file the section of the man page on advanced configurations shows that one can use set_tex-commands for setting options to all versions of latex. So one can write

set_tex_cmds( '-synctex=1 %O %S' );

and latexmk -lualatex will run lualatex with synctex.

  • I had to put a & in front of the set_tex_cmds to make it work
    – user313032
    Commented Jun 14, 2023 at 22:54
  • 1
    It works fine for me without & and the above form is given in the documentation of latexmk. The perl documentation says that & is optional when the name is unambiguous, so adding it should do no harm. Commented Jun 15, 2023 at 10:10
  • ahh I had forgotten a semicolon on the line before, that was the problem. now it also works w/o &
    – user313032
    Commented Jun 15, 2023 at 19:54

Would creating a latexmkrc file containing $pdflatex='lualatex -synctex=1 %O %B';in the same directory as your source file not do the job?

  • Yes, but it means that I'd have to remember to copy it in each directory where I need to use lualatex, and since it won't be very often, I'll of course forget to do it. Granted, this is a minor annoyance, but I'd prefer a non-local-directory solution.
    – Virgile
    Commented Nov 21, 2016 at 18:27

After exploring /usr/bin/latexmk, I've come up with the following .latexmkrc which seems to do the trick:

push @extra_pdflatex_options, '-synctex=1' ;
$pdf_previewer="start okular %O %S";

i.e., instead of directly redefining $pdflatex, I just add an extra option to be passed to it, and let latexmk decide which command it should launch. The only thing that worries me is that as far as I can see extra_pdflatex_options is not documented on latexmk's man page, so that I'm unsure about the robustness of this solution against latexmk evolution.

  • This isn't documented in the latest version, either. But especially with xelatex, this seems to be the safest way to ensure -synctex=1 and -c-style-error, as it uses -no-pdf as yet another default switch. The manpage and the official website doesn't mention those arrays.
    – polemon
    Commented May 16, 2017 at 5:31

I recommend just creating a .latexmkrc file in your home directory: Put these two commands or at least the pdflualatex command.

$pdflatex = 'pdflatex -interaction=nonstopmode -synctex=1 %O %S;';
$pdflualatex = 'lualatex -interaction=nonstopmode -synctex=1 %O %S;';

Then just call latexmk with: latexmk -lualatex in any directory and it will use the settings from the home directory.

To override that just put a new latexmkrc file in the compile directory or use the -r command of latexmk to pass in a latexmkrc file. I don't put a default latexmkrc but I have an alias in my bash to run the command with -r pointing to a default one so this is an option too.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .