TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Could you quantify the improvement in execution time from making an xdv file instead of a pdf file. – John Collins Apr 2 '14 at 12:19
@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. – egwene sedai Apr 2 '14 at 12:51
up vote 2 down vote accepted

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.

share|improve this answer
Thanks! Can you elaborate on the && cp %Z%R.xdv part? – egwene sedai Apr 2 '14 at 14:32
@davidsedai: I've added some comments. – John Collins Apr 2 '14 at 16:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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