Contents

Technical Guide: How to Compile LaTeX Documents Completely and Efficiently

Compilation is the process of translating LaTeX commands into a ready-to-print document. This article discusses how LaTeX compilation works, types of compilers available, the compilation sequence, and how to resolve errors efficiently.


">LaTeX is a document preparation system that produces high-quality output, especially for scientific and technical text. Unlike conventional word processors, a LaTeX document must be compiled before a .tex file can be converted into the final format such as .pdf, .dvi, or .ps.
Note
Note: This article was generated with the help of AI technology and has been manually reviewed to ensure accuracy and clarity.

LaTeX compilation is the process performed by a compiler to read the source file (usually with the .tex extension), interpret the commands inside (\section{}, \usepackage{}, etc.), and produce an output file such as .pdf. In short:

document.tex → [compiler] → document.pdf

Here are some commonly used LaTeX compilers:

CompilerMain OutputAdvantagesDisadvantages
pdfLaTeXPDF directlyFast, stable, compatible with most packagesLimited to TeX fonts and ASCII input
XeLaTeXPDFSupports Unicode and system fonts (TTF/OTF)Slightly slower
LuaLaTeXPDFSupports Lua scripting, high performanceLess stable with older packages
LaTeX → DVI → PS → PDFPDF/DVIClassic method, suitable for legacy projectsLong process and rarely used today

💡 Recommendation: Use pdfLaTeX for standard documents, XeLaTeX for non-Latin languages (e.g., Indonesian, Japanese, Arabic), and LuaLaTeX for projects involving advanced graphics or scripting.


When compiling, LaTeX goes through several stages:

  1. Reads the .tex file — the compiler processes the preamble (\usepackage{}) and the main document body.
  2. Builds document structure — generates the table of contents, labels, references, and indexes.
  3. Processes math symbols, images, and tables.
  4. Creates auxiliary files such as:
    • .aux → for cross-references (\ref, \cite)
    • .toc → for the table of contents
    • .log → for error logs
  5. Produces the final output (.pdf or .dvi). Because of these auxiliary files, LaTeX documents often need to be compiled more than once, especially when using cross-references, tables of contents, or bibliographies.

For local system users (Windows, macOS, Linux), compilation can be performed via the command line. Example:

pdflatex document.tex
bibtex document
pdflatex document.tex
pdflatex document.tex

Steps:

  1. First compilation: generates .aux and .toc.
  2. Run bibtex (if a bibliography is used).
  3. Recompile to update references.
  4. Final compilation for the finished output.

⚙️ If you’re using biber (with biblatex), replace bibtex with biber document.


Besides the terminal, compilation can also be done directly from LaTeX editors. Common options include:

overleaf
Overleaf interface

"latex-workshop.latex.recipes": [
  {
    "name": "pdflatex -> bibtex -> pdflatex x2",
    "tools": ["pdflatex", "bibtex", "pdflatex", "pdflatex"]
  }
]

Here are common LaTeX compilation errors and how to fix them:

Error MessageCauseSolution
! Undefined control sequence.Unknown commandEnsure the required package is loaded (\usepackage{})
! LaTeX Error: File 'xxx.sty' not found.Missing packageInstall using a package manager (tlmgr install xxx)
! Missing $ inserted.Math mode errorWrap math expressions with $...$ or \[...\]
Package hyperref Warning: Token not allowed in a PDF stringInvalid characters in hyperlinkUse {} or replace special characters
Output incomplete / references missingNot enough compilation runsCompile 2–3 times

🧩 Tip: Check the document.log file for detailed error messages and line numbers.


For efficiency, many users rely on automated compilation tools, such as:


Related Content