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.
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.)