views:

51

answers:

2

Hello everyone.

I'm trying to determine when a re-run of Xe(La)TeX is required because of undefined references. I've posted a related question on the SCons mailing list, and the problem is as follows:

Page counts and other references that require multiple runs of XeLaTeX are sometimes not at present detected by SCons and other build systems. Here's an example file (which we'll call job.tex):

\documentclass[ones​ide,12pt]{memoir}
\usepackage{xltxtra}
\usepackage[T1]{fontenc}
\makepagestyle{plain}
\makeoddfoot{plain}{}{}{Page \thepage\ of \arabic{lastpage}}
\makeevenfoot{plain}{}{}{Page \thepage\ of \arabic{lastpage}}
\begin{document}
\pagestyle{plain}
Page 1
\newpage
Page 2
\newpage
Page 3
\newpage
\end{document}

If you run xelatex job, the .pdf that's produced has page numbers "Page 1 of 0", "Page 2 of 0", and "Page 3 of 0" for the three pages. If you run xelatex job a second time you get "Page 1 of 3", etc. (i.e. the correct page count).

To fix this, I've suggested on the SCons mailing list that the check for whether to run xelatex to resolve undefined references is to change the following regular expression (in SCons.Tools.tex at line 71 of version 2.0.1.beta.20100627.r5064):

- warning_rerun_str = '(^LaTeX Warning:.*Rerun)|(^Package \w+ Warning:.*Rerun)'
+ warning_rerun_str = '(^LaTeX Warning:.*Rerun)|(^Package \w+ Warning:.*Rerun)'\
+                     '|(^No file \w+\.\w{3}\.$)'

In practice, this is a check for "No file job.aux". It turns out this works in all cases because Xe(La)TeX will always print "No file job.aux" on the first run, and therefore Xe(La)TeX always runs twice. In effect, this is the same as having job.aux become an interim build target between job.tex and job.pdf.

Therein lies the problem: Even if there is no undefined reference (e.g. remove the \arabic{lastpage} from job.tex above) Xe(La)TeX is called twice, once to produce the .aux, once to produce the .pdf. Obviously, if there are no undefined references, this second call is superfluous.

Thus my question: how can one detect - presumably by way of a regular expression testing against the job.log - when there are or are not undefined references (e.g. \arabic{lastpage}) that require recompilation.

Thank you for reading.

Best regards,

Brian

+1  A: 

Can you not just copy the .aux file to a backup, and compare whether the backup is the same as the newly generated .aux file at the end of Xetex's run?

Charles Stewart
+1  A: 

The solution you probably want is to reference the last page in such a way that a warning is given when the counter "lastpage" is undefined. This would then be picked up by the original rerun regular expression.

An alternative approach that I use, is to keep running LaTeX until the aux-file does not change anymore (conceptually, the aux-file is both an input and output of the LaTeX run, and you keep running LaTeX until you reach a fixpoint for the aux-file). This should give the guarantee that rerunning LaTeX does not change the resulting document anymore.

I don't know if you can incorporate this behavior into scons. From a Makefile, it is fairly easy with some shell logic.

Bruno De Fraine