pdfLaTeX vs XeLaTeX vs LuaLaTeX

pdfLaTeX vs XeLaTeX vs LuaLaTeX is the question every LaTeX editor dropdown asks, and the answer depends on fonts, scripts and who will read the PDF.

The short answer

On LaTeX.to you do not have to decide up front. Leave the dropdown on Auto and the compiler reads the document:

What is the same

More than people expect. All three take the same \documentclass, the same sections, the same math, the same figures and tables, and the same packages for nearly everything above the font level. A document's body does not change when you move it between engines. What changes is the preamble, a handful of font-related packages, and what the engine can do with text that is not plain ASCII.

pdfLaTeX

The pdfTeX engine with the LaTeX format loaded, and the default everywhere since the late 1990s. It starts fastest, because it loads no font shaper and no scripting language, and it has the deepest package compatibility: every package on CTAN was tested against it first. It is also the only engine with full microtypography through microtype, protruding punctuation past the margin and stretching glyphs by fractions of a percent so justified text looks calm.

Its limit is fonts. pdfLaTeX works with 8-bit TeX fonts: Computer Modern, Latin Modern, the classic Times and Palatino clones, and whatever has been packaged for TeX. A font you own cannot be used without converting it, and text in Greek, Cyrillic, Arabic or CJK is a fight with encodings. Accented Latin letters are fine.

XeLaTeX

The XeTeX engine, written by Jonathan Kew in 2004, with the LaTeX format loaded. It reads your file as Unicode and loads OpenType fonts by name through fontspec: \setmainfont{TeX Gyre Pagella} and the whole document is set in that face, ligatures and small capitals included. Any font inside TeX Live works, and a font file you upload can be loaded by its file name. Text shaping is done by HarfBuzz built into the engine, which is why complex scripts and right-to-left languages work so well.

XeLaTeX does not write PDF itself. It writes XDV and the xdvipdfmx driver converts it in the same run, which is why a few pdfTeX-only packages complain and why microtype gives you protrusion but not font expansion. The engine is no longer developed, and the LaTeX team has said it will never be able to produce tagged PDFs.

LuaLaTeX

The LuaTeX engine (in TeX Live, the luahbtex binary) with the LaTeX format loaded. It has everything XeLaTeX has, Unicode input and fontspec fonts, and adds a Lua interpreter inside the engine: \directlua runs code in the middle of the typesetting pass and pastes the result into the page, so a document can compute a table or loop over data. It writes PDF directly, allocates memory dynamically so very large documents do not hit "TeX capacity exceeded", and it is the engine the LaTeX team's automatic tagging is built on.

The cost is startup time. LuaLaTeX starts more slowly than the other two, and the first compile that meets a new font builds a cache for it, which is a one-time wait per font. A handful of old packages that poke at pdfTeX internals do not work on it.

Fonts, speed and accessibility side by side

Switching an existing document

From pdfLaTeX to LuaLaTeX or XeLaTeX:

  1. Delete \usepackage[utf8]{inputenc} and \usepackage[T1]{fontenc} (harmless but pointless).
  2. Replace the font packages with \usepackage{fontspec} and a \setmainfont.
  3. For math, load unicode-math with a \setmathfont.
  4. Leave everything below the preamble as it is.

The reverse move is the same in mirror image, plus finding a TeX font that matches what fontspec was loading. Between XeLaTeX and LuaLaTeX, most documents move with no change at all, because the fontspec commands are identical; what can need a touch is polyglossia (LuaLaTeX users often prefer babel), anything that used \XeTeX... primitives, and, going the other way, any \directlua.

Each engine has its own page: pdfLaTeX, XeLaTeX, LuaLaTeX and all engines.