If you look carefully at the output from the run, you'll see that on the first run, pdflatex
detects a first missing file. Since nonstopmode is being used, that causes a fatal error, and pdflatex
goes no further. Then latexmk
sees a message about a single missing file, makes it, and repeats the run. Then an error comes up about the second missing file, etc, with the annoying phenomenon you observed. The situation is different when \include
is used instead of \input
. This macro behaves differently: the missing file is no longer a fatal error; instead there are messages in the log file for all the missing files, all on the first run.
There are two solutions. One is to run pdflatex
in its normal mode, where it will stop and ask you to correct the filename. Just hitting the enter key will cause pdflatex
to continue, ignoring the missing file. To automate this, change the second line of your Makefile
to
latexmk -pdf -pdflatex="cat responses | pdflatex -interaction=nonstopmode" -use-make test.tex
where responses
is a file containing many blank lines.
A more systematic solution is to replace \input
by a macro which gives a warning instead of a fatal error when a file is missing:
\documentclass{article}
\newcommand\inputA[1]{%
\InputIfFileExists{#1}{}{\typeout{No file #1.}}%
}
\begin{document}
\inputA{foo1}
\inputA{foo2}
\inputA{foo3}
\inputA{foo4}
\inputA{foo5}
\inputA{foo6}
\end{document}
I've used this trick quite a few times.
This isn't latexmk automagic, but it avoids recompiling if the source .tex file hasn't changed:
latexmk -pdf file.tex
make -n -f file.makefile > /dev/null | grep pdflatex > /dev/null
if [ $? -eq 0 ] ; then
make -f file.makefile
latexmk -g -pdf file.tex
fi
If the auto-generated makefile isn't actually going to compile any figures, the string "pdflatex" won't appear in the output of the dry-run; otherwise, the figures are compiled and latexmk is forced to do at least one more compilation.
Alternatively, here is a latexmkrc file that works most of the time: it runs the external makefile once per latexmk invocation, after the first time pdflatex is called.
If you are compiling the document from scratch, latexmk will most likely run pdflatex multiple times, and so the figures will be included after the first run. If you are not building from scratch, then there is a good chance that latexmk will recognize that the external figures are being included, see that they have been updated by the external makefile, and then decide to run pdflatex again because of the changing dependencies.
Warning: this is the first time I've written perl:
our %externalflag = ();
$pdflatex = 'internal mypdflatex %O %S %B';
sub mypdflatex {
our %externalflag;
my $n = scalar(@_);
my @args = @_[0 .. $n - 2];
my $base = $_[$n - 1];
system 'pdflatex', @args;
if ($? != 0) {
return $?
}
if ( !defined $externalflag->{$base} ) {
$externalflag->{$base} = 1;
system ("$make -j8 -f $base.makefile");
}
return $?;
}
Best Answer
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 ofxelatex
were made, starting in v. 4.52.Latexmk
now does exactly what the question asked for, without any special configuration. For details, see thelatexmk
documentation, in the explanations of the option-pdfxe
and the variable$xelatex
.So if you invoke a current version of
latexmk
bylatexmk -pdfxe
orlatexmk -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 makingpdf
files. You do this by getting the 'xdv' file copied to a 'dvi' file. The following lines in an initialization file implement this: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.Notes
The tail
&& cp %Z%R.xdv %D
of the command line defined in$latex
uses an idiom of thesh
/bash
shells: The part to the right of the&&
is run only if the command on the left (i.e.,xelatex
) succeeded. Thecp
part does the copying (under UNIX-type operating systems) of thexdv
file to thedvi
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., thedvi
file; these will be replaced by the correct values bylatexmk
, as explained in its documentation.