Short answer: three font families
LaTeX divides its text fonts into three families: roman (a serif family), sans serif, and typewriter (monospace). Each family has a switch and a command, so you can change a passage’s family with \textrm{...}, \textsf{...}, or \texttt{...}.
LaTeX also describes a font by its series, shape, and size. Those add more styles on top of the three families, which is why a document can seem to use more than three fonts.
How LaTeX organizes a font
LaTeX’s font system, the New Font Selection Scheme (NFSS), describes each font with a few attributes. For everyday writing, four matter:
- Family: the design group (roman, sans serif, or typewriter)
- Series: the weight (medium or bold)
- Shape: the form (upright, italic, slanted, or small caps)
- Size: the height of the text, relative to the document class
Families
| Family | Switch | Command | Typical use |
|---|---|---|---|
| Roman (serif) | \rmfamily |
\textrm{...} |
Body text by default |
| Sans serif | \sffamily |
\textsf{...} |
Labels, diagrams, and headings in some templates |
| Typewriter | \ttfamily |
\texttt{...} |
Code and file names |
A command takes text as its argument and styles only that text. A switch styles everything after it, until the end of the current group (the braces) or the next switch:
Normal text, \textsf{a sans serif phrase}, and back to normal.
{\ttfamily This whole group is typewriter.} This sentence is roman again.
To make sans serif the default for the whole document, redefine the default family in the preamble:
\renewcommand{\familydefault}{\sfdefault}
Use \rmdefault in place of \sfdefault to return to roman.
Series
LaTeX uses two series in common use:
- Medium:
\textmd{...}or\mdseries, the normal weight - Bold:
\textbf{...}or\bfseries
Shapes
The four common shapes are:
- Upright:
\textup{...}or\upshape, the normal shape - Italic:
\textit{...}or\itshape, a true italic design - Slanted:
\textsl{...}or\slshape, an upright design tilted - Small caps:
\textsc{...}or\scshape, lowercase letters set as small capitals
Series and shapes combine. For example, \textbf{\textit{bold italic}} gives bold italic text.
Not every family has every combination in every font package. When a combination is missing, LaTeX substitutes the nearest one and writes a font warning to the log file.
Sizes
The size commands run from smallest to largest:
\tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge, \Huge
Sizes are relative to the base size you set in \documentclass (10pt, 11pt, or 12pt). For more on classes, see chapters and document classes in LaTeX. Like the other switches, a size applies until the end of its group, so wrap the text in braces:
Normal text, {\large a larger phrase}, and back to normal.
The default font: Computer Modern and Latin Modern
Computer Modern (CM) is the typeface Donald Knuth designed for TeX. A standard article compiled with pdfLaTeX uses it for body text, which is why many people think of it as “the LaTeX font”. The family also includes sans serif and typewriter styles.
Latin Modern is a later reworking of Computer Modern. It keeps the same general design and has wider character coverage, including more accented letters. Most current installations can load it with \usepackage{lmodern}. With XeLaTeX and LuaLaTeX, Latin Modern is generally the default body font, so the page looks like CM but the font files differ. Check your template if you are unsure which one you are getting.
For a short answer on this point, see What font is used for LaTeX?, which also covers how to check a PDF’s fonts.
Changing the font
With pdfLaTeX
Load a font package in the preamble. Good packages set both the text font and a matching math font, so equations look right with the text:
\documentclass{article}
\usepackage{mathptmx} % Times-like text and math
% \usepackage{mathpazo} % Palatino-like text and math
% \usepackage{lmodern} % Latin Modern
\begin{document}
This is body text in the chosen font.
\end{document}
Load only one package that sets the text font. Two of them in the same preamble can conflict.
With XeLaTeX or LuaLaTeX
These engines use fonts installed on your system, through the fontspec package. Replace the names below with fonts you have installed:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Libertinus Serif}
\setsansfont{Libertinus Sans}
\setmonofont{Libertinus Mono}
\begin{document}
This is body text in the main font.
\end{document}
Math needs its own setup with these engines. The unicode-math package loads a math font that you can match to the text font.
The fi ligature problem
What a ligature is
A ligature is one glyph that replaces two or more letters. Many TeX fonts include “fi”, “fl”, “ff”, “ffi”, and “ffl” ligatures. TeX forms them automatically when those letters sit next to each other in a word. The joined shape looks cleaner, because the dot of the i no longer collides with the hook of the f.
Copy, paste, and search
Because a ligature is a single glyph, copied text or a PDF search can show the ligature character (fi) where you typed “f” and “i”. A search for “file” may then fail. On a current TeX installation with the T1 font encoding, copy and paste usually works. If you still see the ligature character:
- Load T1 font encoding with
\usepackage[T1]{fontenc}, which most modern templates already do. - Check the text with your PDF viewer’s search. Testing one word tells you whether the problem is real.
- If the problem remains, the
cmappackage is the classic fix for mapping font glyphs to text characters.
Breaking a ligature with {}
The other common fi problem is a ligature that forms where it should not. This happens most often at the join of two words in a compound. In German, for example, “Auflage” (edition) is built from “Auf” and “Lage”, and the “fl” should not join across the boundary. An empty group {} stops TeX from forming a ligature across it:
Die Auf{}lage des Buches ist vergriffen.
TeX does not form ligatures or kerning across a group boundary, so {} breaks the ligature without adding any visible space. To break an fi ligature in the same way, write f{}i.
Choosing a font
Pick a font for four reasons:
- Your engine: pdfLaTeX works with the classic packages; XeLaTeX and LuaLaTeX use
fontspecand system fonts. See the difference between TeX and LaTeX for how the engines relate. - Your language: check that the font has the accented letters your text needs. Latin Modern covers more of them than the original CM.
- Your math: text and math fonts should come from a matching package. Mixing them can look odd.
- Your medium: Computer Modern can look thin on some screens, and some readers find a heavier or modernized font easier to read on a monitor.
The article How to format text in LaTeX? shows the styling commands in context, and the font commands above work the same way there.
Frequently asked questions
Is Latin Modern the same as Computer Modern?
Latin Modern is based on Computer Modern and keeps its general design. It is a separate font set, though, with wider character coverage. A document set in Latin Modern looks very similar to one set in Computer Modern.
Why does my LaTeX document look different from my Word document?
The two programs use different fonts, line-breaking rules, and spacing. For a wider comparison, see is LaTeX better than MS Word. Matching them exactly is rarely possible. Choose a LaTeX font that suits your text, and expect a different look.
Do I need to choose a font for the math?
Usually not separately. A font package that sets both the text and math fonts handles this for you. With XeLaTeX or LuaLaTeX, use unicode-math to set the math font.