Sarmate.net Sarmate.net
Home Features Pricing Documentation Contact
Log in Sign up

Choose the right compiler

This is the error that trips up the most beginners: the wrong compiler. LaTeX offers three of them — pdfLaTeX, XeLaTeX, LuaLaTeX — and a single drop-down menu is enough to switch from one to another. Let us see when to use which.

Which one to choose?

  • pdfLaTeX — the default choice, fast, suited to the majority of documents. Always start with it.
  • XeLaTeX / LuaLaTeX — required as soon as the document uses fontspec (system fonts, .otf/.ttf files) or advanced Unicode (Arabic, Cyrillic…).
Compile Most documents work in pdfLaTeX. Compile this one as is (the compiler is already set to pdfLaTeX).

The classic case: fontspec requires XeLaTeX

If a document loads \usepackage{fontspec} and you compile it in pdfLaTeX, it stops dead on: "Fatal Package fontspec Error: The fontspec package requires either XeTeX or LuaTeX". The solution requires no change to the code: you simply switch compilers.

Fix This document loads fontspec and fails in pdfLaTeX (look at the log). In the compiler drop-down menu (at the top of the editor), choose XeLaTeX, then recompile: it works, without touching the code.
Show the solution
% !TEX program = xelatex
\documentclass{article}
\usepackage{fontspec}
\begin{document}
This document loads fontspec: it requires XeLaTeX or LuaLaTeX.
\end{document}
A lasting trick: add % !TEX program = xelatex as the very first line. The editor will automatically select the right compiler when the file is opened — you will no longer have to think about it.

XeLaTeX's reward: system fonts

Once in XeLaTeX (or LuaLaTeX), you can typeset with any installed font, via \setmainfont{...}.

Compile This example is already set to XeLaTeX. Compile it: the text is typeset with the system font Lato — impossible in pdfLaTeX in this way.
Key point: fontspec or a system font → XeLaTeX or LuaLaTeX. Otherwise, pdfLaTeX is fine. The compiler menu is always a click away — and % !TEX program = ... makes the choice permanent.

This error comes up so often that we have devoted a dedicated page to it: old packages & compiler →