I want to know how to use latexmk with xelatex and tell it to write to xdv file a number of times until all the references are correct, then use xdvipdfmx once to generate the final output. This is practical because for manuscripts with a lot of figures and references and needs several passes to get all the references right, writing to xdv files are way, way faster than writing to pdf every pass.

  • Could you quantify the improvement in execution time from making an xdv file instead of a pdf file. Apr 2, 2014 at 12:19
  • 1
    @JohnCollins For my 100+ pages thesis with a lot of eps figures, making a pdf takes about 10 minutes, while xdv finishes in a minute. Apr 2, 2014 at 12:51

1 Answer 1


Important update to old answer

The old answer (below) was appropriate when it was written (in April 2014), but it uses a nasty trick. Since then, changes in latexmk's support of xelatex were made, starting in v. 4.52. Latexmk now does exactly what the question asked for, without any special configuration. For details, see the latexmk documentation, in the explanations of the option -pdfxe and the variable $xelatex.

So if you invoke a current version of latexmk by latexmk -pdfxe or latexmk -xelatex, it will now do exactly what was asked.

Old Answer

With the present latexmk, a simple trick is to arrange to treat this by the dvi-pdf route for making pdf files. You do this by getting the 'xdv' file copied to a 'dvi' file. The following lines in an initialization file implement this:

$pdf_mode = 3;
$postscript_mode = $dvi_mode = 0;
$latex = 'xelatex --no-pdf %O %S && cp %Z%R.xdv %D';
$dvipdf = 'xdvipdfmx %O -o %D %S';
$clean_full_ext .= ' xdv';

The definition of $latex is appropriate for UNIX-like operating systems (e.g., linux and OS-X), and will need to be changed for MS-Windows.

Given the improved performance by this method, I should enhance latexmk to do it properly, with a -pdfxdv option in addition to its current -pdfdvi option.


The tail && cp %Z%R.xdv %D of the command line defined in $latex uses an idiom of the sh/bash shells: The part to the right of the && is run only if the command on the left (i.e., xelatex) succeeded. The cp part does the copying (under UNIX-type operating systems) of the xdv file to the dvi file. %Z denotes the output directory with any necessary trailing separator, %R denotes the rootname of the 'tex' file, and %D denotes the destination file, i.e., the dvi file; these will be replaced by the correct values by latexmk, as explained in its documentation.

  • Thanks! Can you elaborate on the && cp %Z%R.xdv part? Apr 2, 2014 at 14:32
  • @davidsedai: I've added some comments. Apr 2, 2014 at 16:03

You must log in to answer this question.

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