1

I have a latexmkrc file that looks like this:

$xelatex = 'xelatex -interaction=nonstopmode  -synctex=1 %O %S; (sleep 10) && (test -f "%Z%R.synctex.gz") && (cp "%Z%R.synctex.gz" "%R.synctex.gz"); (test -f "%D") && (cp "%D" "%R.pdf")';
$pdflatex = 'pdflatex -interaction=nonstopmode -synctex=1 %O %S; (test -f "%Z%R.synctex.gz") && (cp "%Z%R.synctex.gz" "%R.synctex.gz"); (test -f "%D") && (cp "%D" "%R.pdf")';
$out_dir = '/tmp';

Latexmk automatically adds -no-pdf since the %O is specified. If this is the case, then it seems the commands after the xelatex command are run before the conversion of the extended dvi to pdf using xdvipdfmx. My .pdf file is always corrupted in the local folder but if I open it in the /tmp folder it is fine. Is there a way to run these copy commands after the command for xdvipdfmx when using the -no-pdf.

Here is an image of what happens at the end. This is run after the copy commands above are already run. The pdf file copied is always corrupted.

command line output showing the problem

J Spen
  • 2,614
  • 4
  • 26
  • 41

2 Answers2

1

As stated in the question, the problem is that the definitions given in the question assume that xelatex is used by latexmk to make a pdf file. In fact, latexmk arranges for xelatex to make an xdv file, and then calls xdvpdfmx to make the pdf file from the xdv file. (The reason that latexmk does this is that for a graphics intensive documents, this can result in substantial shortening of run time if multiple runs of xelatex are needed.)

A suitable solution is to redefine also the command for the xdv-to-pdf conversion as follows

$xelatex = 'xelatex -synctex=1 -interaction=nonstopmode %O %S; (test -f "%Z%R.synctex.gz") && (cp "%Z%R.synctex.gz" "%R.synctex.gz")';
$xdvipdfmx = 'xdvipdfmx -o %D %S; (test -f "%D") && (cp "%D" "%R.pdf")';

(Note some of the lines in the code sample are long, so scroll the box to see all of the codes.)

John Collins
  • 126
  • 3
0

Using latexmk to run your document in a temporary directory and then convincing it to copy the result back to your working folder seems unnecessarily complicate. I suggest to use ltx2any instead. This is an automation tool like latexmk, just with the advantage that it will use a temporary folder by default and automatically deal with copying the pdf and synctex files back.

Usage:

ltx2any -synctex -e xelatex filename