Typography lies at the heart of any beautifully crafted document. While LaTeX is celebrated for its default Computer Modern fonts and rock-solid mathematics typesetting, many users crave more expressive, modern, or institution-branded typefaces. Thanks to the power of fontspec
, microtype
, and unicode-math
(in XeLaTeX or LuaLaTeX engines), you can effortlessly tap into your system’s font library, refine spacing and kerning, and achieve professional-grade math face consistency.
In this comprehensive guide, we’ll explore how to select, load, and configure custom fonts in LaTeX; fine-tune your typography with micro-typographic adjustments; and ensure that your mathematical expressions match the style of your body text. Whether you’re preparing an academic journal article, a corporate white paper, or a visually stunning presentation, mastering these tools will elevate your documents to a new level of polish.
Good typography goes beyond selecting a pretty font. It encompasses the harmonious interplay of typeface design, spacing, line length, and mathematical consistency. In academic and professional settings, the right typeface can:
While LaTeX’s default Computer Modern is timeless, modern literature often calls for serif, sans-serif, or monospaced fonts beyond the basics. With the emergence of OpenType and TrueType system fonts, it’s never been easier to expand LaTeX’s typographic palette.
fontspec
The fontspec
package is your gateway to system fonts in XeLaTeX or LuaLaTeX. It provides intuitive commands to select, tweak, and define font families without wrestling with low-level TeX mechanisms.
Basic Usage:
\usepackage{fontspec} % Load a font by name \setmainfont{TeX Gyre Termes} \setsansfont{TeX Gyre Heros} \setmonofont{Inconsolata}
In this example, TeX Gyre Termes
serves as a Times-like serif, TeX Gyre Heros
as a Helvetica-style sans-serif, and Inconsolata
as a programmer’s monospaced font. If your system supports multiple font features (ligatures, alternate glyphs, small caps), you can activate them with options:
\setmainfont[ Ligatures=TeX, SmallCapsFeatures={Letters=SmallCaps}, Numbers=OldStyle ]{Linux Libertine O}
Notice how Ligatures=TeX
restores traditional TeX ligature behavior, while Numbers=OldStyle
switches to more elegant non-lining numerals. Such fine-grained control can be invaluable for high-end publishing.
microtype
While fontspec
enables font selection, microtype
perfects the spacing. It applies micro-typographic adjustments such as character protrusion (margin kerning) and font expansion, significantly improving justification and optical alignment.
To activate microtype:
\usepackage[protrusion=true,expansion=true]{microtype}
By default, microtype loads settings calibrated for Computer Modern. For system fonts, you may need to generate custom configuration files using mtcfgopt
(supplied with microtype) or rely on community-provided presets. Many fonts work beautifully out of the box, but for the highest polish, consider:
protrusion=true
: Allows punctuation marks to hang slightly into margins for optical alignment.expansion=alltext
: Permits subtle font expansion/shrinkage for better justification..cfg
files: Define character-specific adjustments for unique glyph shapes.Well-tuned micro-typography often goes unnoticed—but readers subconsciously appreciate the fluid, professional texture of perfectly justified paragraphs.
unicode-math
After you select a serif font for body text, you’ll likely want matching math symbols. The unicode-math
package brings OpenType math fonts (e.g., Asana Math, Latin Modern Math, STIX Two Math) into your document, ensuring consistency between text and formulas.
Sample configuration:
\usepackage{unicode-math} \setmathfont{STIX Two Math}
With this setup, Greek letters, operators, and specialized symbols adopt the same stroke weight and design language as your main font. You can even mix multiple math fonts:
\setmathfont{XITS Math}[range={up/{latin,Latin,greek,Greek}}] \setmathfont{Asana Math}[range={\int,\sum,\prod,\coprod}]
Splitting ranges allows you to choose the best glyphs from different fonts, crafting a bespoke math palette tailored to your document’s needs.
Not all fonts are created equal when it comes to typesetting. Here are some guidelines:
fc-list
(Linux) or Font Book (macOS) to identify exact names.When loading, always specify fallback options:
\setmainfont[ Path = /usr/share/fonts/truetype/libertine/, UprightFont = *-Roman, BoldFont = *-Bold, ItalicFont = *-Italic, BoldItalicFont = *-BoldItalic ]{LinuxLibertine}
This approach ensures that LaTeX locates the correct font files even in environments where system‐wide font caches differ.
To maintain consistency across projects:
typography.sty
to centralize your fontspec
, microtype
, and unicode-math
settings.By systematizing your font management, you minimize “it compiles on my machine” problems and ensure that every collaborator sees the same polished output.
Elevate Your LaTeX Typography Today!
Ready to transform your documents with custom fonts and micro-typographic finesse? Sign up now for our free LaTeX typography workshop and gain access to ready-to-use style templates and video tutorials.
Mastering font management in LaTeX unlocks a new realm of design possibilities. By combining fontspec
for font selection, microtype
for spacing perfection, and unicode-math
for math consistency, you can produce documents that are as beautiful as they are rigorous. Whether you’re an academic, designer, or technical writer, these tools empower you to craft compelling, professional-quality typesetting.
Dive into the world of custom LaTeX typography, experiment with different typefaces, and share your favorite configurations with the community. Happy typesetting!