How to Compile LaTeX to PDF
Compilation is the process that turns your .tex source code into a finished PDF. Unlike a word processor, LaTeX doesn't show you the result in real time—you write the source, then compile it. Understanding this workflow is key to working effectively with LaTeX.
What Compilation Means
LaTeX is a markup language. A compiler reads your .tex file, processes all commands, resolves references, and produces a PDF. Think of it like compiling code: source in, finished document out.
% Your source file (main.tex)
\documentclass{article}
\begin{document}
Hello, world!
\end{document}Using pdfLaTeX from the Command Line
The most common compiler is pdfLaTeX. Open a terminal, navigate to your file's directory, and run:
% In your terminal / command prompt:
% pdflatex main.tex
%
% This produces main.pdf in the same directory.
% You will also see auxiliary files: main.aux, main.logCloud Compilation with Overleaf or Bibby AI
Online editors compile for you with a single click. Upload or paste your .tex code and hit the compile button—no local installation required.
% In Overleaf / Bibby AI:
% 1. Create or open a project
% 2. Edit your .tex file in the browser
% 3. Click "Compile" (or press Ctrl+S / Cmd+S)
% 4. The PDF preview updates automaticallyMulti-Pass Compilation for Citations & References
Cross-references (\ref, \cite) need multiple passes. The first pass collects labels; subsequent passes resolve them. BibTeX/Biber adds an extra step for bibliographies.
% Full build sequence when using citations:
% pdflatex main.tex (1st pass — collects labels)
% bibtex main (processes .bib file)
% pdflatex main.tex (2nd pass — inserts citations)
% pdflatex main.tex (3rd pass — finalises references)Troubleshooting Compilation Errors
When compilation fails, check the .log file for the first error. Common issues include missing packages, unmatched braces, and math-mode mistakes.
% Common fixes:
% 1. "Undefined control sequence" → check spelling or add \usepackage{}
% 2. "Missing $ inserted" → wrap math in $...$
% 3. "File not found" → verify file names & paths
% 4. "Too many }'s" → count your braces
%
% Tip: search the .log file for lines starting with "!"💡 Tips
- •Use latexmk to automate multi-pass builds: latexmk -pdf main.tex
- •Cloud editors handle multi-pass compilation automatically
- •Delete auxiliary files (.aux, .log, .toc) and recompile if you encounter strange errors
- •XeLaTeX and LuaLaTeX are alternative compilers with full Unicode and system font support
Try This in Bibby AI
Write LaTeX faster with AI auto-complete and instant compilation.
Start Writing Free