I use a simple rule in all my LaTeX makefiles
.DELETE_ON_ERROR: %.pdf %.aux %.idx: %.tex pdflatex $< while grep 'Rerun to get ' $*.log ; do pdflatex $< ; done
This repeats pdflatex as often as possible. I found that all of the various LaTeX messages that require re-writing contain a common “Retry to Receive” line in the log file, so you can simply check for the presence of this file with grep in the while loop.
The value ".DELETE_ON_ERROR:" is important: it ensures that any remaining incomplete pdf / aux / idx files are automatically deleted whenever TeX is interrupted with an error, so they cannot confuse make the next time you invoke it.
When I use DVI and not PDF as the output format, I use the equivalent
%.dvi %.aux %.idx: %.tex latex $< while grep 'Rerun to get ' $*.log ; do latex $< ; done -killall -USR1 -r xdvi || true
The last line causes any xdvi to restart its input file for instant visual control.
Markus kuhn
source share