LaTeX basics
pdfLaTeX vs XeLaTeX vs LuaLaTeX: Which Engine to Use
The same .tex file can be compiled by different programs, called engines. pdfLaTeX is the classic default, while XeLaTeX and LuaLaTeX were built for Unicode text and system fonts. For most documents the choice comes down to fonts and languages. Here is what actually differs, and how to move a document between engines.
The short answer
| pdfLaTeX | XeLaTeX | LuaLaTeX | |
|---|---|---|---|
| Input | 8-bit; Unicode via inputenc for common accents | Native UTF-8 | Native UTF-8 |
| Fonts | TeX fonts installed as packages | Any OpenType/TrueType font via fontspec | Any OpenType/TrueType font via fontspec |
| Non-Latin scripts | Limited | Good (Devanagari, Arabic, CJK with packages) | Good |
| Speed | Fastest | Fast | Slower, especially at start-up |
microtype | Full | Protrusion only | Full |
| Scripting | No | No | Lua inside the document |
Choose pdfLaTeX for a classic English document with Computer Modern or another TeX font. Choose XeLaTeX or LuaLaTeX when you want your own fonts, or write in a language beyond Western European accents. Choose LuaLaTeX only if you need Lua scripting or full microtype.
Fonts: the biggest practical difference
With pdfLaTeX a font must exist as a LaTeX package, such as \usepackage{libertine}. XeLaTeX and LuaLaTeX load any OpenType or TrueType font by name through fontspec:
\usepackage{fontspec}
\setmainfont{Inter}
\setmonofont{JetBrains Mono}[Scale=MatchLowercase]That is why résumés and designed documents are often compiled with XeLaTeX: the font you see in a design tool is the font you get.
Unicode and languages
XeLaTeX and LuaLaTeX read UTF-8 natively, so you can type é, ß, ₹, ∑ or a whole sentence in Hindi directly, provided the font has the glyphs. With pdfLaTeX, characters outside the supported encodings fail with errors like Unicode character … not set up for use with LaTeX.
- For multilingual documents, pair
fontspecwithpolyglossiaorbabelto get the right hyphenation and conventions. - Pick fonts per script with
\newfontfamily, for example a Devanagari font for Hindi passages.
Moving a pdfLaTeX document to XeLaTeX
Most pdfLaTeX documents compile unchanged with XeLaTeX. The lines worth checking are the ones about encodings and fonts:
| Line | What to do |
|---|---|
\usepackage[utf8]{inputenc} | Harmless; you can remove it. |
\usepackage[T1]{fontenc} | Works, but for full Unicode switch to fontspec. |
\usepackage{lmodern} | Not needed: fontspec defaults to Latin Modern. |
Font packages like times or helvet | Use \setmainfont{…} with an OpenType font instead. |
\pdfoutput=1 or other \pdf… primitives | pdfTeX only; remove them or guard them with iftex. |
To keep one source for several engines, load \usepackage{iftex} and branch with \ifPDFTeX … \else … \fi.
Which engine Lemma uses
Lemma compiles with Tectonic, a modern XeTeX-based engine, entirely on your phone. Documents written for XeLaTeX work as they are, most pdfLaTeX documents work unchanged, and fontspec loads fonts by name. With Lemma Pro you can add your own .ttf or .otf files in Settings → Fonts and use them in any project with \setmainfont.
Two desktop tools aren't available: Biber and makeindex. For biblatex, add backend=bibtex, as explained in BibTeX vs biblatex. Moving a project from Overleaf? See Overleaf projects on Android.