\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.
- 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
- 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
\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)
XeLaTeXFaster compilation, excellent fontspec support, and full unicode-math for modern math fonts.
Multilingual report (complex scripts)
LuaLaTeXHarfBuzz shaping handles Arabic, Devanagari, and Thai more accurately than XeLaTeX's ICU engine.
Automated report generation
LuaLaTeXLua scripting lets you loop over data and generate tables or sections at compile time without external pre-processing.
Thesis / dissertation
XeLaTeXFaster iteration during writing, broad template support, and fontspec covers all typical font requirements.
Book or long-form document
LuaLaTeXLua callbacks enable micro-typographic customization beyond what TeX macros allow. HarfBuzz improves glyph quality for custom fonts.
CV or resume
XeLaTeXShort 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 — 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 — 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
Compile with your preferred engine
FormaTeX runs XeLaTeX, LuaLaTeX, pdfLaTeX, and latexmk. Switch engines with a single API field change — no infrastructure required.

