How to Compile LaTeX on Windows, Linux, and Overleaf
Português: Leia este tutorial em português.
Compiling LaTeX means transforming one or more .tex source files into a final document, usually a PDF. You can work entirely in Overleaf or install a local distribution on Windows or Linux. The best choice depends on connectivity, project size, collaboration, and the level of control you need.
Option 1: compile on Overleaf
Overleaf combines an editor, a LaTeX distribution, and a PDF viewer in the browser.
- Open or create a project.
- Select the main file, usually
main.tex. - Choose pdfLaTeX, XeLaTeX, or LuaLaTeX in the project settings.
- Click Recompile.
- If compilation fails, start with the first error in the log.
This option is excellent for beginners and collaboration. Large projects, special dependencies, automation, or offline work may favor a local installation.
Option 2: compile on Windows
The best-known Windows distributions are MiKTeX and TeX Live. Download them only from official sources and keep their packages updated.
After installation, open a terminal in the project folder and run:
pdflatex main.tex
For system fonts or extensive Unicode support:
xelatex main.tex
lualatex main.tex
Editors such as TeXstudio and Visual Studio Code with LaTeX Workshop can run these tools through buttons and shortcuts.
Option 3: compile on Linux
On Debian- or Ubuntu-based systems, TeX Live can be installed through the package manager. Choose a collection that fits your disk space and project requirements.
sudo apt update
sudo apt install texlive-latex-extra latexmk biber
Package names vary on Fedora, Arch, and other distributions. Follow your distribution’s official documentation.
Automate compilation with latexmk
latexmk determines how many passes are needed and runs auxiliary tools:
latexmk -pdf main.tex
To remove temporary compilation files:
latexmk -c
Before using cleanup commands, make sure the project folder does not contain important files that match temporary extensions.
Bibliography and cross-references
Some projects require several passes. With BibLaTeX and Biber, a manual sequence is:
pdflatex main.tex
biber main
pdflatex main.tex
pdflatex main.tex
Overleaf and latexmk usually automate this process.
Which compiler should you choose?
- pdfLaTeX: fast and compatible with many traditional templates.
- XeLaTeX: convenient for system fonts and multiple writing systems.
- LuaLaTeX: modern, programmable, and suitable for complex projects.
Common problems
Command not found
Confirm that the distribution is installed and its executable directory is available to the terminal. Restart your editor after installation.
Missing package
Install the package through your distribution manager. On Overleaf, confirm that it exists in the selected TeX Live version.
File not found
Run the command from the project folder and use filenames without spaces or problematic characters.
Outdated PDF
Clean auxiliary files and compile again. Read errors from the beginning because later messages may only be consequences.
Quick comparison
- Overleaf: minimal setup, collaboration, and access from any computer.
- Local Windows: strong editor support and offline work.
- Local Linux: automation, scripting, and detailed environment control.
After configuring your environment, test it with a TexDrop LaTeX template and document the recommended compiler in the project instructions.