2

I usually want latexmk to use pdflatex and synctex by default, so I have the following in my RC file and everything works hunky-dory:

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

However, some documents I want to compile into PDFs using xelatex and synctex. How can I change my RC file so that latexmk still uses pdflatex and synctex by default, but if I pass a single command-line option, it will instead use xelatex and synctex?

I tried (among many other things) the following RC file:

$pdf_mode = 1;
$pdflatex = 'pdflatex -interaction=nonstopmode -synctex=1 %O %S';
$xelatex = 'xelatex -interaction=nonstopmode -synctex=1 %O %S';

With this file, invoking latexmk without arguments still works as expected, but running latexmk -xelatex or latexmk -pdfxe throws an error message:

Latexmk: Log file says output to 'foo.pdf'
Latexmk: ===For rule 'xelatex', actual output 'foo.pdf'
       ======appears not to match expected output 'foo.xdv'
Failure to make 'foo.xdv'
Latexmk: Errors, so I did not complete making targets
Collected error summary (may duplicate other messages):
  xelatex: failed to create output file
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs of latex/pdflatex.

There is a previous similar thread on this subject but the solution given there works only for older versions of latexmk. According to a comment by the author, the behaviour of the program has since changed, and latexmk should now "do what you want", though I haven't been able to figure it out.

  • 1
    Try xelatex -no-pdf -synctex=1 %O %S. – Ulrike Fischer Jan 4 '18 at 13:43
  • @UlrikeFischer: That works, thanks! If you want to post it as an answer, I will accept it. – Psychonaut Jan 4 '18 at 13:46
  • 1
    There is nothing to stop you from defining $pdflatex from using xelatex instead of pdflatex. – Herb Schulz Jan 4 '18 at 18:16
  • @HerbSchulz: There is if I don't want xelatex to be the default. – Psychonaut Jan 4 '18 at 20:30
2

latexmk splits the xelatex compilation. From the documentation

Latexmk first uses xelatex to make an xdv file, and does all the extra runs needed (including those of bibtex, etc). Only after that does it make the pdf file from the xdv file, using xdvipdfmx.

To get this behaviour the original definition for the variable $xelatex contains the -no-pdf switch:

# xelatex is used to give xdv file, not pdf file
$xelatex = 'xelatex -no-pdf %O %S';

If you want to change the variable you should use the switch too.

2

In v4.54c, in addition to adding an $xelatex variable, the process was change to run xelatex with the -no-pdf flag and only run xdvipdfmx once at the end of the job, which apparently speeds up compile time. Hence, when running with the -xelatex flag, latexmk expects an xdv output.

There are a couple of options here:

  1. Change your $xelatex to $xelatex = -no-pdf -interaction=nonstopmode -synctex=1 %O %S
  2. Not dissimilar to the answer in the question you linked, don't overwrite the $xelatex variable but instead add push @extra_xelatex_options, '-synctex=1' ;.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.