The reason is as follows:
At the first latex
run, all \cite{...}
arguments are written in the file document.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 after bibtex
, as well as you have to run it twice where you cross-reference etc.
Some passes can be saved using biblatex
instead of bibtex
. Anyways, all references (and cross-references) stabilize during the document preparation since all of us compile our documents many times...
latexmk -pdf foo.tex
. There are many more options available, e.g. latexmk can automatically compile whenever you save the .tex file (that's the-pvc
[preview continuously] option). Check out its manual, it's fairly comprehensible. – doncherry Apr 25 '12 at 10:46