[Tex/LaTex] making latexmk use -synctex=1 by default with lualatex

forward-inverse-searchlatexmkluatex

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_mode=1;
$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

Best Answer

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.