Before preparing a document for printing, I use a BASH script, like the following:


xelatex document.tex % compile 1
makeglossaries document
xelatex document.tex % compile 2
xelatex document.tex % compile 3
xelatex document.tex % compile 4

Some documents contain a lot of cross-references, so they need to be compiled repeatedly.

If I created a script which recorded the MD5 checksum of the PDF after each compile and compared this to the MD5 checksum of the previously created PDF (e.g. compared the PDF from compile 4 against that of compile 3), and I have not put any rapidly changing information in my document (such as the current time) would this be a flawless indicator that my document is completely finished compiling and it need not receive additional compiles?


I looked into checksums of LaTeX PDFs a while ago, but then for version control and verification purposes. I couldn't make it work. It was for pdflatex, but most of it might be identical for xelatex.

The PDF contains the creation time which will change at every run. You could overwrite this with a static value, but there is still an unique ID in the PDF which depends on the current time (the current minute, i.e. not counting seconds). This will give you a different ID at least every minute, but I don't guarantee that it will be identical inside the same minute.

There was once also some pseudo-random influence in the font system which changed some variables according to the time (again, without the seconds). Last time I checked this was not longer the case, at least for my test files.

Therefore this approach should not work in general. You could use latexmk which does this repeated compiling for you. It looks at the log file to see if further runs are required, AFAIK.

  • 1
    latexmk actually does a lot more, it tries to determine all files used by the project, keep track of any changes do these (i.e. md5 sums of each file), and from this determine if it need to run latex (or say makeindex again) – daleif Dec 9 '11 at 15:00
  • @daleif: Yes, but it uses MD5 sums for the source file, not for the output PDF, doesn't it? – Martin Scharrer Dec 9 '11 at 15:20
  • Why should it, it would not make much sense as for example the compilation time goes into the PDF file, so the md5 sum will always be different. It does md5 for all files included (as seen from the log and perhaps the aux). For example datatool, when it read from a csv file, that information is not recorded in the log, and thus latexmk cannot see if the csv has changed (that has annoyed me several times. – daleif Dec 9 '11 at 16:27
  • I usually use latexmk in continous preview mode (automatic compilation whenever I save), it is quite handy when writing sty files, just leave it running on a test file, and whenever I save the sty file latexmk will compile the test file. – daleif Dec 9 '11 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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