There are really only four passes that are necessary. If you're trying to build something similar to an ant script or makefile, I would say that you should look for changes to the source .tex file and then fire off this process:
- Run LaTeX (finds all the bibliographical references, figure entries, etc.)
- Run BibTeX (creates an initial set of text for the bibliographic entries)
- Run LaTeX (populates the document with bibliography, figure references)
- Run LaTeX (general good luck: there are some corner cases when references need two passes to fully populate)
If Latex doesn't need to do extra work for any of these passes, it won't do it.
Responding to the OP:
Note that I can't say "3 or 4 times",
since it builds continuously. If an
input changes, I may need to run it 3
or 4 times, but more likely I'll only
need to run it once. In a rare
situation, an input will change
something like a reference, which will
need maybe 3 builds. I'm trying to
find out how I know when this happens.
An ant script or makefile is your friend here: make your final output product (.dvi file, for example) depend on your source .tex and .bib files. Seriously, though, you need those four passes to be certain that you have avoided getting trapped by any corner cases.
Responding to the comment:
Suppose I fix a typo in some
paragraph, I run latex, and now have a
perfect version. Is there not some way
to tell that it hasnt updated the .aux
file, or the .bbl file, etc, and so
doesnt need to full set of passes.
It is possible to build the ant script or makefile such that each step depends on the appropriate intermediate file and, thus, would only fire if there was a change. I would recommend against doing this for two reasons:
- You're duplicating the work and file management that LaTeX is already doing for you.
- If you change your document structure, you're going to have to update those dependencies.
For example, when I was writing my dissertation, at one point I decided that it would be helpful to split one chapter into two and add another appendix. All I had to do was change my \include section from this:
\include{chapter1.tex}
\include{chapter2.tex}
\include{chapter3.tex}
\include{chapter4.tex}
\include{appendix.tex}
to this:
\include{chapter1.tex}
\include{chapter2a.tex}
\include{chapter2b.tex}
\include{chapter3.tex}
\include{chapter4.tex}
\include{appendix.tex}
\include{appendix2.tex}
If I was attempting to duplicate the multi-pass implementation of LaTeX in a build script, I would have to update all the dependencies for .tex, .aux, etc., every time I made a similar change.
Instead, I just continued to run my four passes (using an alias at the command line) and carried on writing my text.