Using XeTeX for Unicode and OpenType Fonts in LaTeX Documents
Learn how XeTeX reads UTF‑8 source, hands Unicode glyphs to HarfBuzz, and lets you use any OpenType font via fontspec—complete with a minimal working example and notes on font embedding.
17 Aug 2026, 18:23 UTC

Problem: Typesetting Unicode and OpenType fonts in plain LaTeX
Traditional pdfLaTeX expects input in a limited encoding and relies on TFM files for font metrics, which makes it difficult to typeset characters outside the basic Latin range or to use modern OpenType features such as contextual ligatures or variable fonts. When a document contains Chinese characters, emoji, or a font with advanced typographic tables, pdfLaTeX either fails or requires complex work‑arounds.
How XeTeX handles Unicode and OpenType
XeTeX changes the pipeline in two key ways:
- Unicode input – XeTeX reads the source file as UTF‑8 (or UTF‑16) and passes each character’s Unicode code point directly to the shaping stage.
- HarfBuzz shaping – Instead of converting glyphs to TFM, XeTeX sends Unicode glyph IDs to the HarfBuzz library, which looks up the OpenType tables in the supplied .otf or .ttf file and returns positioned glyphs.
The shaped glyphs are written to an intermediate XDV file; xdvipdfmx then converts XDV to PDF while preserving the original font outlines. This means the PDF contains the actual OpenType outlines, not bitmap substitutions, and retains PDF features such as metadata and hyperlinks.
Unicode input
Because the source is treated as UTF‑8, you can type any character your editor supports—accented letters, Greek, Cyrillic, CJK symbols, or emoji—without extra packages or inputenc declarations.
Font loading with fontspec
The fontspec package provides a simple interface to system fonts. After loading it, \setmainfont{} (or \newfontfamily) tells XeTeX to locate the corresponding .otf/.ttf file, hand it to HarfBuzz, and use its OpenType features via options like Ligatures=TeX, Numbers=OldStyle, or Variant=1.
Worked example
The following minimal file demonstrates Unicode text and an OpenType font.
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\begin{document}
Hello, 世界! 🎉
\end{document}
To compile, run the command in a terminal where a recent TeX distribution is available:
xelatex hello.tex
This produces hello.xdv and then hello.pdf. No intermediate TFM conversion occurs; the font file is read directly.
Trade‑off and limitation
While XeTeX gives broad Unicode and OpenType access, a few practical points deserve attention:
- HarfBuzz version – The shaping quality depends on the HarfBuzz version bundled with the TeX engine. Older TeX Live releases (before 2015) may lack recent fixes for complex scripts such as Indic or Arabic.
- Font embedding license – XeTeX does not automatically embed fonts; embedding relies on the font’s license and whether the
fontspeccall includes options that allow subsetting. If the license forbids embedding, the resulting PDF will reference the font externally, which may cause missing‑font errors on other systems. - Engine availability – XeTeX is not present in every minimal TeX installation; you need a full TeX Live (≥2015) or MikTeX (≥2.9) package that includes the XeTeX binary.
You can verify that the shaping engine is being used and that the font is loaded directly:
- Compile with
xelatex -no-pdf hello.texto leave only the XDV file. - Run
xdvipdfmx -vv hello.xdvand look for lines likeReading font file …/LatinModernRoman.otf. - Open the resulting PDF in a viewer that shows font information (e.g., Adobe Reader → File → Properties → Fonts) and confirm that Latin Modern Roman appears as an OpenType font with subsets for the Unicode ranges used.
Actionable closing
If you need to typeset multilingual text or want to take advantage of modern OpenType features, switch to XeTeX (or its LuaTeX counterpart) and use fontspec to load the desired .otf/.ttf files. Keep your TeX distribution up to date to benefit from the latest HarfBuzz improvements, and always check the font’s license before distributing the PDF. With these steps, you gain a straightforward path from Unicode source to high‑quality PDF output.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.