Skip to content

Guide

XeLaTeX vs pdfLaTeX vs LuaLaTeX: which engine to use

By Vishnu KumarPublished 5 min read

Every LaTeX distribution ships several engines, and the one you pick decides whether you can type é or हिन्दी directly, whether you can use the fonts installed on your computer, and how fast your document builds. Here is what actually differs, with preambles that work, from the team that put XeTeX on Android in Lemma.

Three engines, one language

You write the same LaTeX for all three; the engine is the program that turns it into a PDF. pdfTeX descends from Knuth's original 8-bit TeX and adds direct PDF output and fine typography. XeTeX was built to read Unicode and use system OpenType fonts directly. LuaTeX also reads Unicode and uses OpenType fonts, and embeds the Lua scripting language so packages can program the typesetting process itself. pdflatex, xelatex and lualatex are those engines with the LaTeX format loaded.

pdfLaTeX: fast, compatible, 8-bit at heart

pdfLaTeX is still the default in many templates, and the safest choice for a document that must compile on any journal's build system. Its limit is fonts and scripts: internally it works with 256-glyph font encodings, so non-Latin scripts need special packages and fonts must be prepared in TeX's own formats rather than picked from your system.

\documentclass{article}
\usepackage[T1]{fontenc}   % proper hyphenation and glyphs for accented Latin
\usepackage{lmodern}       % scalable Latin Modern fonts
\usepackage{microtype}     % character protrusion and font expansion
\begin{document}
Café, naïve, Zürich: accented Latin text works.
\end{document}

Since 2018, LaTeX assumes UTF-8 input by default, so you no longer need \usepackage[utf8]{inputenc} for accented Latin letters. What pdfLaTeX still cannot do is use an arbitrary OpenType font from your system, or shape complex scripts such as Devanagari, Arabic or Tamil properly.

XeLaTeX: Unicode and system fonts

XeLaTeX reads UTF-8 natively and, with the fontspec package, uses any OpenType or TrueType font installed on the machine or sitting next to the document. XeTeX shapes text with the HarfBuzz library (since around TeX Live 2013), which is what correctly forms conjuncts and vowel signs in Indic scripts.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}
\setmonofont{JetBrains Mono}[Scale=MatchLowercase]
\begin{document}
Any installed font, by name. Ligatures, old-style figures and
other OpenType features are options to \verb|\setmainfont|.
\end{document}

Use font names exactly as your system reports them, or load a font file by name with Path=./fonts/ when you want the document to build the same everywhere.

LuaLaTeX: Unicode, fonts and a programming language

LuaLaTeX offers what XeLaTeX does (Unicode input, fontspec, OpenType fonts) plus Lua scripting, which modern packages use for things that are impossible or fragile in TeX macros. Much of the LaTeX Project's newer work, such as tagged PDF for accessibility, targets LuaLaTeX first, and some newer packages require it.

Two trade-offs. LuaLaTeX is usually the slowest of the three, especially on the first run when it builds its font cache. And its default font loader does not shape complex scripts as well as HarfBuzz does. Since TeX Live 2020, LuaLaTeX includes HarfBuzz too (the LuaHBTeX engine), but you have to ask fontspec for it; for Indic or Arabic text, do so explicitly, as in the example below.

Hindi and other Indic scripts

This is where the engine choice decides whether text is readable. Devanagari needs shaping: consonant clusters form conjuncts (क + ् + ष becomes क्ष), and the vowel sign ि is written before the consonant it follows in speech. pdfLaTeX cannot do this with ordinary fonts. With XeLaTeX:

% Compile with xelatex
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{hindi}
\setmainfont{Noto Serif}
\newfontfamily\devanagarifont[Script=Devanagari]{Noto Serif Devanagari}

\begin{document}
English text, then Hindi:
\begin{hindi}
भारत एक विशाल देश है। क्षमा, ज्ञान और श्रद्धा।
\end{hindi}
\end{document}

With LuaLaTeX, the same document works if the Devanagari font is loaded with the HarfBuzz renderer:

% Compile with lualatex
\newfontfamily\devanagarifont[Script=Devanagari, Renderer=HarfBuzz]{Noto Serif Devanagari}

polyglossia switches hyphenation patterns, fonts and conventions per language. babel, the older language package, also supports Hindi and other Indic languages with XeLaTeX and LuaLaTeX and is the default in many templates; either works, but do not load both.

If you see dotted circles (◌) or vowel signs in the wrong place, the text is not being shaped: you are on pdfLaTeX, the font lacks the script, or LuaLaTeX is using its default renderer for that font.

microtype and fine typography

The microtype package improves justified text by letting characters hang slightly into the margin (protrusion) and by stretching or shrinking glyphs imperceptibly (font expansion), which reduces bad line breaks. Engine support differs:

microtype features by engine
FeaturepdfLaTeXLuaLaTeXXeLaTeX
Character protrusionYesYesYes
Font expansionYesYesNo
Tracking (letter-spacing)YesYesNo

If a document is long, justified and Latin-script only, pdfLaTeX or LuaLaTeX with microtype gives the most even text colour.

Choosing

Which engine fits which document
Your situationUse
Submitting to a journal with a fixed templateWhatever the template specifies, usually pdfLaTeX
Latin-script text with the standard fontspdfLaTeX (fastest) or LuaLaTeX
You want a specific system or brand fontXeLaTeX or LuaLaTeX with fontspec
Hindi, Marathi, Tamil, Bengali, Arabic and other complex scriptsXeLaTeX, or LuaLaTeX with Renderer=HarfBuzz
Mixing many scripts in one documentXeLaTeX or LuaLaTeX with polyglossia or babel
New, long-lived documents; tagged, accessible PDFsLuaLaTeX
Compiling on a phone or low-power deviceXeLaTeX: Unicode and fonts without LuaLaTeX's start-up cost
  • Switching engines is usually a one-line change in your editor or build command, plus replacing fontenc and inputenc with fontspec when moving away from pdfLaTeX.
  • Packages that depend on pdfTeX internals (rare today) are the main compatibility risk when leaving pdfLaTeX; test a build before a deadline, not on it.

Considering leaving LaTeX entirely? Typst vs LaTeX compares the two side by side.