As explained by Andy Roberts, if you need to compile a new document with bibtex citations, then you need to run latex three times, and bibtex once:
latex document
bibtex document
latex document
latex document
Why can't latex figure this out itself, and just do what it needs to do? What is it doing in the later runs that it can't do in the earlier runs?
Best Answer
The reason is as follows:
At the first
latex
run, all\cite{...}
arguments are written in the filedocument.aux
.At the
bibtex
run, this information is taken by bibtex and the relevant entries are put into the.bbl
file, sorted either alphabetically or by citation order (sometimes called "unsorted") and formatted according to the instructions provided by the bibliography style that's in use.At the next run of
latex
, the.bbl
file is included at the point the\bibliography
instructions, and the correct labels for\cite{...}
commands are written in.aux
file.Only at the last run,
latex
knows what the correct labels are and includes them in the document.The reason why TeX and BibTeX have been made this way is that back then, the memories used to be small, and file systems were the only good ways to store files. But you cannot read and write the same file (well, you can, but it's more complicated), that's why you have to run
latex
twice afterbibtex
, as well as you have to run it twice where you cross-reference etc.Some passes can be saved using
biblatex
instead ofbibtex
. Anyways, all references (and cross-references) stabilize during the document preparation since all of us compile our documents many times...