Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
4  
I recommend latexmk (Homepage/CTAN), which does what you're demanding: It figures out what needs to be run how often all by itself. It works well with BibTeX and Biber, but might need some fine-tuning for other things, e.g. glossaries, about which you'll find questions on here. The author is also very responsive and actually answers questions here on tex.sx. –  doncherry Apr 25 '12 at 9:46
    
@doncherry: I actually use pdflatex, does latexmk output to pdf? –  naught101 Apr 25 '12 at 10:26
2  
Yes, use it like this: 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

1 Answer 1

up vote 22 down vote accepted

The reason is as follows:

  1. At the first latex run, all \cite{...} arguments are written in the file document.aux.

  2. 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.

  3. 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.

  4. 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...

share|improve this answer
4  
biblatex doesn't avoid the need of multiple pass processing. –  egreg Apr 25 '12 at 8:58
    
I have always thought that it reduces at least one pass... –  tohecz Apr 25 '12 at 9:02
1  
Yes, it may avoid one pass. But it's not so important to always do all passes: it's quite often only a waste of time. Cross references will stabilize during document preparation and it's not necessary that they are always correct. Just remember to run BibTeX (or Biber) when citations are added. –  egreg Apr 25 '12 at 9:15
1  
I've taken the liberty of providing a bit more information about the output of the bibtex run. Hope you agree. –  Mico 20 hours ago
1  
I've already upvoted the answer for you. -:) –  Mico 4 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.