A Guide To Finding And Using Custom Fonts In Latex
Why Use Custom Fonts?
LaTeX comes with a set of default fonts, but you may want to use custom fonts for greater design control or to match branding guidelines. Custom fonts allow you to:
- Choose font families, shapes, weights not included in default LaTeX
- Create a specific visual style for your documents
- Match fonts used in other branded materials
- Emphasize headings and text hierarchy
- Enhance readability and appeal for your readers
Checking if a Font is Installed
Before using a font in LaTeX, verify it is installed on your system. Here's how:
Linux/Unix
On Linux systems, fonts are usually installed system-wide in directories like /usr/share/fonts. Use commands like ls
, find
, or locate
to search these directories. For example:
ls /usr/share/fonts/truetype
locate "myfont.ttf"
Windows
On Windows, installed fonts can be found in C:\Windows\Fonts. You can also use the FC-list command in cmd or PowerShell:
FC-list | findstr "myfont"
MacOS
On Macs, system fonts are stored in /Library/Fonts and /System/Library/Fonts. Use Finder or the ls
command to browse them. You can also use:
fc-list | grep "myfont"
Installing New Fonts
If a font you want to use isn't available on your system, you'll need to install it. Here's how:
Linux
On Linux, copy font files (.ttf, .otf) to ~/.fonts for user-level access or /usr/local/share/fonts for system-wide access. Refresh the font cache with:
fc-cache -f -v
Windows
On Windows, install fonts by double-clicking the font files and clicking "Install" in the preview. Or, copy fonts to C:\Windows\Fonts.
MacOS
On Macs, install fonts by double-clicking and using the Font Book app. Or, copy font files to /Library/Fonts or ~/Library/Fonts.
Enabling Fonts in LaTeX
To use custom fonts in LaTeX, you need to enable them using LaTeX packages. The available options are:
- Native LaTeX Fonts - Only fonts that come preinstalled in LaTeX distributions.
- System Fonts - All fonts installed on your operating system.
- Specific External Fonts - Individual fonts accessed from font packages.
Native LaTeX Fonts
Native LaTeX fonts like Times and Computer Modern don't require packages. Just set them using \fontfamily. For more advanced options, use fontspec or lmodern:
\usepackage{fontspec}
\usepackage{lmodern}
System Fonts
To access all system-installed fonts, use:
\usepackage{fontspec}
\setmainfont{Arial}
This will enable global use of Arial. Other system fonts can then be set document-wide or per-section.
External Fonts
For individual external fonts, use font-specific packages from CTAN or other sources. For example:
\usepackage{amsthm} % ams font package
\usepackage[no-math]{fontspec}
\setmainfont{MyCustomFont.ttf}[Path=/fonts/]
This provides access to the external MyCustomFont.ttf file.
Font Package Options
Font packages provide advanced control over text font styling. Some key options include:
Font Family
The font package determines the font family used. For example:
\usepackage{helvet} % Helvetica font
Font Shape
Shape refers to upright vs italic style. Set via \textit or \textup:
\textit{Italic text}
\textup{Upright text}
Font Series
Series controls font weight and variation - like bold or light. Set via \textbf:\
\textbf{Bold text}
Font Size
Font size is controlled via document classes or direct size commands:
\tiny\scriptsize\footnotesize\small\normalsize\large\LARGE\huge\Huge
Importing Font Packages
To import a font package in LaTeX:
- Get the .sty package files, usually from CTAN
- Save the .sty files in your document's texmf folder
- Refresh filename database
- Add \usepackage{package-name} in the LaTeX document preamble
For example, to use MyCustomFont:
\usepackage{MyCustomFont}
\setmainfont{MyCustomFont-Regular}
Then specify MyCustomFont variants like bold, italic etc. as needed.
Setting Document Fonts
To set overall text fonts for a LaTeX document, use \setmainfont. For specific elements, use:
- \setsansfont - for sans serif text
- \setmonofont - for monospaced text
- \setmathfont - mathematical formulas
- \setmathrm - for Roman text
- \settextbf - for bold text
- \settextit - for italic text
For example:
\setmainfont{MyCustomFont}
\setsansfont{MySansFont}
\setmonofont{MyMonoFont}
Set these after importing font packages.
Changing Fonts Mid-Document
To change fonts within a LaTeX document, delimit commands by text block:
{\setmainfont{Font2}
Text block with Font2
}{\setmainfont{Font1}
Remaining text with Font1
}
Or use grouping:
{\fontfamily{ptm}\selectfont
Text block with Times font}
{\fontfamily{phv}\selectfont
Text with Helvetica font}
Save font changes for titles, headers, captions etc. Normal text uses the main font.
Example Code
Here is basic LaTeX font usage with the TexGyre fonts:
\usepackage[default]{lato} % Lato font package
\setmainfont{Lato-Reg}[Scale=1.0] % Set main font
\begin{document}
{\huge\bfseries Chapter Title} % Large bold chapter
\section{Introduction} % Bold section
Here is a sample paragraph with the \textbf{Lato Regular} font...
{\itshape italic text}\par
{\scshape small caps text}
\end{document}
Other variants like Lato Black, Bold, Light, Italic etc. can be set similarly.
Troubleshooting Font Issues
Some common font usage issues and fixes:
- Missing glyph/character errors - Install missing fonts, enable unknown character boxes
- Font not found errors - Verify font path locations and filenames
- Changed output font - Check font name capitalization and styling
- Text encoding issues - Use fontenc packages like T1, use inputenc options
- Limitations of basic LaTeX fonts - Use fontspec and Unicode fonts like lmodern and texgyre
For errors, check LaTeX logs. Enable verbosity for debugging info.
Finding More Fonts
Sources for LaTeX fonts:
- CTAN font catalog
- LaTeX font packages on GitHub
- Adobe Fonts Library
- Google Fonts
- Commercial font vendors
Choose .otf or .ttf fonts. Use font package readme files for installation instructions.
Test fonts before major usage to confirm compatibility. Restrict to documented LaTeX font packages whenever possible.