# how to cause unix 'make' to know how many times to run *tex

Is there a clever way to cause the unix `make` command to run a tex variant as many times as are required to resolve all references? I've used tex for a long time, and I still don't know which of all those extra files (`.aux`, `.log`, etc) should be checked, so I usually just run (pdf)latex 3 times, but that is slow for a 400 page document. I am thinking that a fragment such as the line below might be a starting point ... maybe I should just string 3 or so of these together?

``````(pdflatex oar | grep -vq 'here were undefined references')
``````
-
Also have a look at the answers on a related question about automating document compilation –  Juan A. Navarro Jan 5 '11 at 12:08

I've used in the past this Makefile, from Yannick Copin.

But, I guess latexmk also has some advantage over `make` (although I like using custom `Makefile`).

-
@Yannick: Thanks. I like `make` because I'm doing a lot of extra things in there, besides the *tex work. Maybe I should use `latexmk` and `make` together, though. –  dank Jan 5 '11 at 11:53
@dan, definitely, having `make` use `latexmk` to build *tex documents is the way to go. –  Juan A. Navarro Jan 5 '11 at 12:00
@dan Yes, I also use custom Makefile for compiling extra stuff (like Asymptote code) and calling external program, e.g. pdfnup. Never tried to combine latexmk and make, though. –  chl Jan 5 '11 at 12:13

You also get an undefined reference, when it is an unknown one ...

You can delete the time stamp line from the logfile and then build the md5 sum or whatever. When it didn't change then you have no changes in the document. You can also speedup your compilation time, when you do not build a pdf in the first or two run: `pdflatex -draftmode ...`, then only the `aux|idx|...-files` will be created to get correct labels/references.

-
Thanks, I didn't know about `-draftmode`. It speeds up my compilation by 10 percent. –  dank Jan 5 '11 at 11:51
+1 for `-draftmode` . –  lockstep Jan 5 '11 at 11:51
(+1) All good things to know, thx. –  chl Jan 5 '11 at 12:23