FormaTeX

\compare{xelatex-vs-lualatex}

XeLaTeX vs LuaLaTeX

Both engines speak Unicode natively and load system fonts via fontspec. The real difference is LuaLaTeX's embedded Lua scripting engine and its superior text shaping pipeline. This guide covers every meaningful distinction.

XeLaTeX— fast, Unicode, system fontsLuaLaTeX— Lua scripting + HarfBuzz
Use XeLaTeX when…
  • Compilation speed is a priority
  • You need system fonts with OpenType features
  • RTL scripts (Arabic, Hebrew) with bidi package
  • You don't need Lua scripting at compile time
Use LuaLaTeX when…
  • You need Lua scripting inside your document
  • Advanced text shaping (HarfBuzz) is required
  • Generating dynamic tables or computed content
  • You need luacolor or luatextra features

\section{Technical Differences}

What actually differs under the hood

Lua Scripting Engine

XeLaTeX

XeLaTeX has no embedded scripting language. Document logic must be expressed entirely in TeX macros or packages. This is sufficient for almost all typesetting tasks but limits dynamic content generation at compile time.

LuaLaTeX

LuaLaTeX embeds a full Lua 5.3 interpreter accessible from within your document via luacode. You can compute values, iterate over data, call external Lua libraries, and feed results back into the TeX typesetting stream at compile time.

Text Shaping & Complex Scripts

XeLaTeX

XeLaTeX uses the ICU and SIL text shaping libraries via the XeTeX engine. Complex scripts (Arabic, Devanagari, Thai) are supported through the bidi and polyglossia packages. In practice, this covers most multilingual typesetting requirements.

LuaLaTeX

LuaLaTeX integrates HarfBuzz (via LuaHarfBuzz) — the same shaping engine used by browsers, Android, and macOS. HarfBuzz has broader script coverage and more accurate OpenType feature application, making it the superior choice for documents with complex script requirements or advanced glyph substitution.

Compilation Speed

XeLaTeX is consistently faster than LuaLaTeX. The difference comes from LuaLaTeX's Lua VM initialization overhead and the HarfBuzz shaping pipeline. On simple documents the gap is small; on large, font-heavy documents LuaLaTeX can be 30–50% slower.

XeLaTeX

~1.5s

typical single-pass document

LuaLaTeX

~2.0s

typical single-pass document

Package Compatibility

XeLaTeX

Most CTAN packages that work with pdfLaTeX also work with XeLaTeX, with the exception of pdfLaTeX-specific low-level packages. The fontspec and unicode-math packages are first-class citizens.

LuaLaTeX

LuaLaTeX has the same package support as XeLaTeX, plus access to the Lua ecosystem. Packages like luacode, luacolor, and luatextra are LuaLaTeX-exclusive.

\subsection{Feature Matrix}

Side-by-side comparison

Feature
XeLaTeX
LuaLaTeX
Unicode input
Native
Native
System fonts (fontspec)
Yes
Yes
Lua scripting
No
Yes (luacode)
Compilation speed
Fast (~1.5s)
Moderate (~2s)
OpenType math
Yes (unicode-math)
Yes (unicode-math)
RTL languages
Yes (bidi)
Partial (luabidi)
Dynamic content
No
Yes (Lua at runtime)
Package compat.
Good
Good
LuaHarfBuzz (shaping)
No
Yes
Memory usage
Moderate
Higher

\section{Recommendations}

Which engine for which document type?

The right engine depends on your specific requirements, not on a universal ranking.

Academic paper (Latin text)

XeLaTeX

Faster compilation, excellent fontspec support, and full unicode-math for modern math fonts.

Multilingual report (complex scripts)

LuaLaTeX

HarfBuzz shaping handles Arabic, Devanagari, and Thai more accurately than XeLaTeX's ICU engine.

Automated report generation

LuaLaTeX

Lua scripting lets you loop over data and generate tables or sections at compile time without external pre-processing.

Thesis / dissertation

XeLaTeX

Faster iteration during writing, broad template support, and fontspec covers all typical font requirements.

Book or long-form document

LuaLaTeX

Lua callbacks enable micro-typographic customization beyond what TeX macros allow. HarfBuzz improves glyph quality for custom fonts.

CV or resume

XeLaTeX

Short document, fast compile, and fontspec handles all the custom branding fonts you might need.

\begin{examples}

Minimal working examples

Both examples compile with FormaTeX. Try them directly in the playground.

XeLaTeX
% XeLaTeX — Unicode native, system fonts via fontspec
\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont{Linux Libertine O}
\setmathfont{XITS Math}

\begin{document}
XeLaTeX handles Unicode natively: α β γ — no inputenc needed.
Arabic: \textarabic{مرحبا} \quad Greek: Αλφαβητικό

$\int_0^\infty e^{-x^2}\, dx = \frac{\sqrt{\pi}}{2}$
\end{document}
LuaLaTeX
% LuaLaTeX — Lua scripting + modern font loading
\documentclass{article}
\usepackage{fontspec}
\usepackage{luacode}

\setmainfont{Linux Libertine O}

% Generate content with Lua at compile time
\begin{luacode*}
  local items = {"Introduction", "Methods", "Results", "Discussion"}
  for i, v in ipairs(items) do
    tex.print(i .. ". " .. v .. "\\\\")
  end
\end{luacode*}

\begin{document}
LuaLaTeX: Unicode + Lua scripting in a single engine.
$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n$
\end{document}

\section{FAQ}

Frequently asked questions

XeLaTeX and LuaLaTeX both available

Compile with your preferred engine

FormaTeX runs XeLaTeX, LuaLaTeX, pdfLaTeX, and latexmk. Switch engines with a single API field change — no infrastructure required.

One quick thing

We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.

Cookie policy