[Tex/LaTex] How does the LaTeX compile chain work exactly

compiling

This might be a simple or out of place question, but I have run into so many subtleties of document compilation, that I really just need to understand this from the ground up.

Could someone please explain to me what a standard LaTeX compile chain / chain of events / latex make works? I'd also like to know where font-loading fits in, when tikz gets run, labels get assigned, why pdflatex vs latex etc.

I've seen some online references to 2 * latex, 1 * bibtex, 1 * latex, but I'm looking for a diagram to explain to me how this works, or a reference that explains this in-depth, so I can debug this myself on the command line, instead of being annoyed by an editor with insufficient error message (Process started,Process exited with error(s))

This may sound like a very basic question, but I need an answer – as trying to fix this caused almost a day of writing downtime that could hopefully be avoided in future, if I had a causal chain I could check. My apologies for not doing everything through the CLI to begin with.

Best Answer

The standard LaTeX 'recipe':

  1. latex <filename>
  2. bibtex <filename>
  3. latex <filename>
  4. latex <filename>

comes about as follows. During the first run, there is only the .tex file. During the run, LaTeX writes any citation keys and \label information to the .aux file. BibTeX then reads the .aux file and extracts the citations, looks those up in the .bib file(s) and writes the formatted references as a .bbl file. The second LaTeX run reads the .aux file as well as the .tex file, and is able to use this to resolve cross-refs. It also reads the .bbl file, which inserts the references into the output and also sets up the necessary information for the final LaTeX run to put the citation labels (numbers, author-date, ...) into the output.

Life gets more complex in some cases, as it's possible that additional LaTeX or BibTeX runs are needed, for example if there are multiple bibliographies, citations inside references, etc. Thus there are a number of ways support tools try to detect whether more runs are needed. These are broadly either (1) a fixed 'recipe' or (2) looking for changes in the .aux and other 'derived' files.

If your editor is failing to pick up the need to run BibTeX, and it normally does, then either the 'recipe' is corrupted or the scripts it uses are missing something in the auxiliary files. The detail will depend on the exact tool you use.

Related Question