### Build and install fontspec from source
Source: https://github.com/latex3/fontspec/blob/develop/doc/install.md
Utilizes the l3build tool to compile documentation and install the package files into the local texmf tree.
```bash
l3build install
```
--------------------------------
### Installation and Updates
Source: https://github.com/latex3/fontspec/blob/develop/README.md
Instructions on how to install and update the fontspec package using different methods.
```APIDOC
## Installation and Updates
### Description
Instructions on how to install and update the fontspec package using different methods.
### Methods
- **Using TeX Live Manager (tlmgr):**
```bash
tlmgr install fontspec
```
- **Manual Installation from CTAN:**
1. Download the TDS zip package from CTAN: `http://mirror.ctan.org/install/macros/unicodetex/latex/fontspec.tds.zip`
2. Extract the contents into your local `texmf` tree.
3. Update the filename database (e.g., using `texhash`).
- **Using Development Version from GitHub:**
1. Clone the repository:
```bash
git clone git://github.com/latex3/fontspec.git
```
2. Install the package:
```bash
cd fontspec
l3build install
```
3. Update the filename database (e.g., using `texhash`).
```
--------------------------------
### Document Font Setup
Source: https://github.com/latex3/fontspec/blob/develop/doc/user.md
Commands to configure the primary document fonts (main, sans, and mono).
```APIDOC
## COMMAND \setmainfont
### Description
Sets the default main document font.
### Parameters
- **font name** (string) - Required - The font to use as the main document font.
- **font options** (key-value) - Optional - Features to apply to the font.
### Request Example
\setmainfont{Times New Roman}[Ligatures=TeX]
```
--------------------------------
### Build Documentation with l3build
Source: https://github.com/latex3/fontspec/blob/develop/doc/dev.md
Command to build the PDF documentation for the fontspec package using the l3build tool. This command assumes l3build is installed and configured.
```bash
l3build doc
```
--------------------------------
### Defining Document Fonts and Features
Source: https://context7.com/latex3/fontspec/llms.txt
A complete example showing how to set global font defaults, define custom font families, and apply specific OpenType features like small caps and number styles.
```latex
\documentclass{article}
\usepackage{fontspec}
\usepackage{microtype}
% Set up default features
\defaultfontfeatures{Ligatures=TeX}
\defaultfontfeatures[\rmfamily]{Numbers=OldStyle}
% Document fonts
\setmainfont{EB Garamond}[
Numbers=OldStyle,
Contextuals=Alternate
]
\setsansfont{Source Sans Pro}[Scale=MatchLowercase]
\setmonofont{Fira Code}[
Scale=MatchLowercase,
Contextuals=Alternate
]
% Custom font families
\newfontfamily\titlefont{EB Garamond}[
Letters=SmallCaps,
LetterSpace=5,
Scale=1.2
]
\newfontface\dropcapfont{EB Garamond}[
Scale=3.0,
Color=8B0000
]
\begin{document}
{\titlefont\Large Chapter One: Introduction}
\bigskip
{\dropcapfont T}his document demonstrates the fontspec package
features. Numbers like 1234567890 appear in old-style. The
quick brown fox jumps over the lazy dog --- with proper
ligatures for ``fi'' and ``fl'' combinations.
\bigskip
{\sffamily Sans serif text for contrast, with numbers 1234567890
in lining style by default.}
\bigskip
{\ttfamily Monospaced code: function() { return 42; }}
\bigskip
{\addfontfeatures{Numbers=Lining}
When we need lining numbers for tables: 1234567890}
\end{document}
```
--------------------------------
### Install fontspec via TeX Live
Source: https://github.com/latex3/fontspec/blob/develop/doc/install.md
Uses the TeX Live Manager (tlmgr) to automatically download and install the latest version of the fontspec package from the repository.
```bash
tlmgr install fontspec
```
--------------------------------
### Define New Scripts and Languages for Fonts
Source: https://context7.com/latex3/fontspec/llms.txt
This example demonstrates how to register new OpenType script and language tags using `\newfontscript` and `\newfontlanguage`. This is essential for supporting fonts that utilize non-standard or newly defined script and language identifiers, ensuring correct rendering for diverse linguistic content.
```latex
\documentclass{article}
\usepackage{fontspec}
% Define new script tag
\newfontscript{Egyptian Hieroglyphs}{egyp}
% Define new language with fallback tags
\newfontlanguage{Turkish}{TRK,TUR} % Try TRK first, then TUR
% Use the newly defined script/language
\setmainfont{Noto Sans Egyptian Hieroglyphs}[Script=Egyptian Hieroglyphs]
\begin{document}
Text using custom script definition.
\end{document}
```
--------------------------------
### Install fontspec Package from CTAN
Source: https://github.com/latex3/fontspec/blob/develop/README.md
Manually installs the latest release version of the fontspec package from CTAN. This involves downloading the TDS package and extracting it into the local texmf tree.
```bash
http://mirror.ctan.org/install/macros/unicodetex/latex/fontspec.tds.zip
```
--------------------------------
### Optimize Font Definitions with `FontFace` Options (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Implements two optimizations to reduce the time required for defining fonts that use a large number of `FontFace` options. This improves compilation speed for complex font setups.
```LaTeX
% Optimizations reduce time for font definitions with many FontFace options
```
--------------------------------
### Clone fontspec source from GitHub
Source: https://github.com/latex3/fontspec/blob/develop/doc/install.md
Downloads the latest development version of the fontspec repository using git for local compilation and installation.
```bash
git clone git://github.com/latex3/fontspec.git
```
--------------------------------
### Add `ontspec-set-encoding` and `ontspec-get-encoding` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces macros for setting and getting the current font encoding, providing programmatic control over encoding management within `fontspec`.
```LaTeX
\fontspec-set-encoding:n
\fontspec-get-encoding:V
```
--------------------------------
### Remove AAT Font Examples (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Removes examples related to AAT fonts from the documentation due to apparent support issues with recent macOS versions. This reflects the practical limitations of using certain AAT fonts with current systems.
```LaTeX
% Remove AAT font examples from documentation
```
--------------------------------
### OpenType Number Features with fontspec
Source: https://context7.com/latex3/fontspec/llms.txt
Explains and demonstrates the 'Numbers' OpenType feature in fontspec, controlling numeral appearance. It shows examples for default lining numbers, old-style numbers, tabular (monospaced) numbers, and slashed zeros.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}
\begin{document}
% Default lining numbers
Default: 0123456789
% Old-style (lowercase) numbers
{\addfontfeature{Numbers=OldStyle}
Old-style: 0123456789}
% Monospaced (tabular) numbers for tables
{\addfontfeature{Numbers=Monospaced}
Tabular: 0123456789}
% Combined features
{\addfontfeature{Numbers={OldStyle,Monospaced}}
Old-style tabular: 0123456789}
% Slashed zero
{\addfontfeature{Numbers=SlashedZero}
With slashed zero: 0123456789}
\end{document}
```
--------------------------------
### Check Active Font Features with \IfFontFeatureActiveTF
Source: https://context7.com/latex3/fontspec/llms.txt
This example illustrates how to query whether specific OpenType features are currently active in the selected font using `\IfFontFeatureActiveTF`. This is useful for conditional formatting, such as applying specific number styles or adapting text based on available font capabilities. It allows for dynamic text styling within a document.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}[Numbers=OldStyle]
\begin{document}
\IfFontFeatureActiveTF{Numbers=OldStyle}{
Old-style numbers are active: 1234567890
}{
Lining numbers are active: 1234567890
}
% Conditional formatting based on features
\newcommand{\smartnums}[1]{%
\IfFontFeatureActiveTF{Numbers=Monospaced}{#1}{%
{\addfontfeatures{Numbers=Monospaced}#1}%
}%
}
In tables: \smartnums{12345}
\end{document}
```
--------------------------------
### Adjust Letter Spacing (Tracking) with Fontspec
Source: https://context7.com/latex3/fontspec/llms.txt
This example shows how to control the spacing between letters using the `LetterSpace` feature in fontspec. It is particularly useful for enhancing the readability and aesthetic appeal of headings and display text. The `LetterSpace` value can be positive for increased spacing or negative for tighter spacing.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Heros}
\begin{document}
% Default letter spacing
UPPERCASE HEADING
% Increased letter spacing for display text
{\addfontfeature{LetterSpace=5.0}
UPPERCASE HEADING}
% Subtle tracking for small caps
{\scshape\addfontfeature{LetterSpace=3.0}
Small Caps With Tracking}
% Negative tracking (tighter)
{\addfontfeature{LetterSpace=-1.0}
Tighter letter spacing}
\end{document}
```
--------------------------------
### Apply Font Color and Opacity
Source: https://context7.com/latex3/fontspec/llms.txt
Demonstrates applying colors using hexadecimal values or named colors via the xcolor package. It also shows how to set transparency using the Opacity feature.
```latex
\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\begin{document}
{\fontspec{TeX Gyre Heros}[Color=FF0000]
Red text}
{\fontspec{TeX Gyre Heros}[Color=0000FF80]
Semi-transparent blue text}
{\fontspec{TeX Gyre Heros}[Color=purple]
Purple text}
{\fontspec{TeX Gyre Heros}[Color=green, Opacity=0.5]
Semi-transparent green}
\definecolor{MyBlue}{rgb}{0.2,0.4,0.8}
{\fontspec{TeX Gyre Heros}[Color=MyBlue]
Custom blue text}
\end{document}
```
--------------------------------
### Configure Font Families with Mixed Extensions
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Demonstrates how to define a font family using specific files for different font shapes, such as upright and bold, which is useful when font files have varying extensions.
```latex
\setmainfont{MyLato}
[
UprightFont = Lato-Regular.ttf ,
BoldFont = FiraSans-Bold.otf ,
]
```
--------------------------------
### Add `ontspec-set-size` and `ontspec-get-size` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces macros for setting and retrieving font size information, including scaling factors.
```LaTeX
\fontspec-set-size:n
\fontspec-get-size:n
```
--------------------------------
### Using the Ad-hoc fontspec Command
Source: https://context7.com/latex3/fontspec/llms.txt
Demonstrates the \fontspec command for loading a font for immediate, temporary use without defining a new font family. This is useful for one-off applications or testing specific fonts and features.
```latex
\documentclass{article}
\usepackage{fontspec}
\begin{document}
Normal document font.
{\fontspec{Linux Libertine O}
This text uses Linux Libertine temporarily.}
Back to normal font.
% With features
{\fontspec{TeX Gyre Termes}[Numbers=OldStyle, Ligatures=Rare]
Text with old-style numbers 1234567890 and rare ligatures.}
\end{document}
```
--------------------------------
### Configure Default Font Features
Source: https://context7.com/latex3/fontspec/llms.txt
Demonstrates how to set global or family-specific default font features using \defaultfontfeatures. This ensures consistent typography across the document.
```latex
\documentclass{article}
\usepackage{fontspec}
% Global defaults for all fonts
\defaultfontfeatures{Ligatures=TeX}
% Defaults for specific font families
\defaultfontfeatures[\rmfamily,\sffamily]{Ligatures=TeX}
\defaultfontfeatures[\ttfamily]{HyphenChar=None}
% Defaults for a specific font (by name)
\defaultfontfeatures[TeX Gyre Pagella]{Numbers=OldStyle}
% Append to existing defaults with +
\defaultfontfeatures+{Color=330033}
% Font-specific defaults by filename
\defaultfontfeatures[texgyrepagella-regular.otf]{
Numbers=OldStyle,
Ligatures=Rare
}
\setmainfont{TeX Gyre Pagella}
\begin{document}
This text inherits all the default features.
Numbers: 1234567890
\end{document}
```
--------------------------------
### Loading Fonts by Filename with fontspec
Source: https://context7.com/latex3/fontspec/llms.txt
Illustrates loading fonts explicitly by filename, including specifying bold, italic, and bold-italic variants. It also shows how to use wildcards and the 'Path' feature to load fonts from custom locations.
```latex
\documentclass{article}
\usepackage{fontspec}
% Load fonts by explicit filenames
\setmainfont{texgyrepagella-regular.otf}[
BoldFont = texgyrepagella-bold.otf,
ItalicFont = texgyrepagella-italic.otf,
BoldItalicFont = texgyrepagella-bolditalic.otf
]
% Using wildcard substitution with UprightFont
\setsansfont{texgyreheros}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic
]
% Loading from a custom path
\setmonofont{MyFont}[
Path = /Users/me/Fonts/,
Extension = .ttf,
UprightFont = *-Regular,
BoldFont = *-Bold
]
\begin{document}
Sample text in different fonts.
\end{document}
```
--------------------------------
### Add `ontspec-set-script` and `ontspec-get-script` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces macros for setting and retrieving the script tag, crucial for fonts supporting multiple scripts.
```LaTeX
\fontspec-set-script:n
\fontspec-get-script:n
```
--------------------------------
### Creating Font Family Commands with fontspec
Source: https://context7.com/latex3/fontspec/llms.txt
Shows how to create custom font-switching commands using \newfontfamily for full font families (including bold/italic) and \newfontface for single font faces. These commands can then be used like standard LaTeX font commands.
```latex
\documentclass{article}
\usepackage{fontspec}
% Create a new font family with full bold/italic support
\newfontfamily\headingfont{TeX Gyre Adventor}[
Scale=1.1,
Letters=SmallCaps
]
% Create a single font face (no bold/italic)
\newfontface\logofont{Zapfino}
% Define a text command using the font family
\newcommand\textheading[1]{{\headingfont #1}}
\begin{document}
\headingfont This is a heading font.\\
\textbf{Bold} and \textit{italic} work automatically.
\logofont This is for logos only.
Normal text with \textheading{inline heading style}.
\end{document}
```
--------------------------------
### Documentation Access
Source: https://github.com/latex3/fontspec/blob/develop/README.md
How to access the comprehensive documentation for the fontspec package.
```APIDOC
## Documentation Access
### Description
How to access the comprehensive documentation for the fontspec package.
### Access Methods
- **PDF Documentation (User Information):**
```bash
texdoc fontspec
```
- **Online Documentation:**
``
- **Code Documentation (PDF):**
```bash
texdoc fontspec-code
```
```
--------------------------------
### Setting Document Fonts with fontspec
Source: https://context7.com/latex3/fontspec/llms.txt
Demonstrates how to set the main roman, sans-serif, and monospaced fonts for a document using \setmainfont, \setsansfont, and \setmonofont. The package automatically detects bold and italic variants.
```latex
\documentclass{article}
\usepackage{fontspec}
% Set document fonts with automatic bold/italic detection
\setmainfont{TeX Gyre Pagella}
\setsansfont{TeX Gyre Heros}[Scale=MatchLowercase]
\setmonofont{Inconsolata}[Scale=MatchLowercase]
\begin{document}
\rmfamily This is the main font. \textbf{Bold} and \textit{italic}.\
\sffamily This is sans serif. \textbf{Bold} and \textit{italic}.\
\ttfamily This is monospaced. \textbf{Bold} and \textit{italic}.
\end{document}
```
--------------------------------
### Enable Automatic Fractions
Source: https://context7.com/latex3/fontspec/llms.txt
Enables the Fractions feature to automatically convert standard slash-separated numbers into professional fraction glyphs.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}[Fractions=On]
\begin{document}
% Automatic fraction formatting
1/2 cup of flour, 3/4 teaspoon of salt
% Works with various denominators
1/3 + 1/6 = 1/2
% Complex fractions
47/100 and 99/100
% Disable fractions temporarily
{\addfontfeature{Fractions=Off}
Not a fraction: 1/2}
\end{document}
```
--------------------------------
### Add `ontspec-get-fontlicenseurl` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve the URL for the font's license.
```LaTeX
\fontspec-get-fontlicenseurl:n
```
--------------------------------
### Add `ontspec-get-fontsampletextscript` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve the script associated with the font's sample text.
```LaTeX
\fontspec-get-fontsampletextscript:n
```
--------------------------------
### Add `indingchar` and `
obreakspace` Support (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Adds support for `\bindingchar` and `\nobreakspace` to ensure correct handling of these characters, especially when dealing with different encodings or font features.
```LaTeX
% Add support for \bindingchar and \nobreakspace
```
--------------------------------
### Add `ontspec-get-fontdescription` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve a description of the font.
```LaTeX
\fontspec-get-fontdescription:n
```
--------------------------------
### Add `ontspec-get-fontmetrics` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve font metrics information.
```LaTeX
\fontspec-get-fontmetrics:n
```
--------------------------------
### Apply Small Caps and Letter Variants
Source: https://context7.com/latex3/fontspec/llms.txt
Demonstrates how to use the Letters feature to apply small caps, petite caps, and unicase variants to text. This requires the fontspec package and a font that supports these OpenType features.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Termes}
\begin{document}
\textsc{Small Caps Text}
{\addfontfeature{Letters=SmallCaps}
small caps via feature}
{\addfontfeature{Letters=UppercaseSmallCaps}
NASA and FBI become small caps}
{\addfontfeature{Letters=PetiteCaps}
Petite caps if available}
{\addfontfeature{Letters=Unicase}
Unicase mixing}
\end{document}
```
--------------------------------
### Add `ontspec-get-fontlicense` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve the license information for a font.
```LaTeX
\fontspec-get-fontlicense:n
```
--------------------------------
### Save Test Case with l3build
Source: https://github.com/latex3/fontspec/blob/develop/doc/dev.md
Commands to save the output of a specific fontspec test case using l3build. This allows for later comparison and verification. It supports specifying the engine (luatex or xetex).
```bash
l3build save
l3build save -e luatex
```
--------------------------------
### Add `ontspec-get-fontscripts` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve all supported script tags for a given font.
```LaTeX
\fontspec-get-fontscripts:n
```
--------------------------------
### Add `ontspec-set-raw` and `ontspec-get-raw` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides macros for setting and retrieving raw font feature strings, allowing for direct manipulation of OpenType feature settings.
```LaTeX
\fontspec-set-raw:n
\fontspec-get-raw:n
```
--------------------------------
### Programmatic Font Family Creation and Feature Querying
Source: https://context7.com/latex3/fontspec/llms.txt
This snippet showcases the expl3 programming interface provided by fontspec for creating font families programmatically and querying font/feature status. It includes functions for defining families with specific features and scales, checking if a font is loaded via fontspec, and testing for OpenType feature availability.
```latex
\documentclass{article}
\usepackage{fontspec}
\ExplSyntaxOn
% Create a font family programmatically
\fontspec_set_family:Nnn \l_my_family_tl
{Numbers=OldStyle, Scale=1.1}
{TeX~ Gyre~ Pagella}
% Use the created family
\cs_new:Npn \myfont { \fontfamily{\l_my_family_tl}\selectfont }
% Test if current font is fontspec-loaded
\cs_new:Npn \checkfontspec {
\fontspec_if_fontspec_font:TF
{fontspec~font}
{not~fontspec~font}
}
% Test for OpenType feature availability
\cs_new:Npn \checkfeature #1 {
\fontspec_if_feature:nTF {#1}
{feature~#1~available}
{feature~#1~not~available}
}
\ExplSyntaxOff
\begin{document}
{\myfont This uses the programmatically created family.}
\setmainfont{TeX Gyre Termes}
Is this fontspec? \checkfontspec
\checkfeature{smcp}
\end{document}
```
--------------------------------
### Define Font with Specific Upright File
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Shows the syntax for loading a font by name while explicitly specifying the filename for the upright shape, ensuring correct font mapping.
```latex
\setmainfont{pagella}[ UprightFont = texgyrepagella-regular.otf ]
```
--------------------------------
### Add `ontspec-set-features` and `ontspec-get-features` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides macros for setting and retrieving font features, enabling detailed control and inspection of OpenType features applied to fonts.
```LaTeX
\fontspec-set-features:n
\fontspec-get-features:n
```
--------------------------------
### Conditionally Load Fonts with \IfFontExistsTF
Source: https://context7.com/latex3/fontspec/llms.txt
This code snippet demonstrates how to use `\IfFontExistsTF` to check for the existence of a font before loading it. This allows for portable documents that can fall back to alternative fonts if the primary choice is not available on the system. It supports nested checks for multiple fallback options.
```latex
\documentclass{article}
\usepackage{fontspec}
% Check if font exists before using
\IfFontExistsTF{Minion Pro}{
\setmainfont{Minion Pro}
}{
\setmainfont{TeX Gyre Pagella} % Fallback
}
\IfFontExistsTF{Fira Code}{
\setmonofont{Fira Code}
}{
\IfFontExistsTF{Inconsolata}{
\setmonofont{Inconsolata}
}{
\setmonofont{Latin Modern Mono}
}
}
\begin{document}
Document text using available fonts.
\end{document}
```
--------------------------------
### Define New Font Families and Faces
Source: https://github.com/latex3/fontspec/blob/develop/doc/user.md
Use these commands to create custom font switches for specific font families or faces. The commands require a control sequence for the switch, the font name, and optional font features.
```latex
\newfontfamily\myfont{FontName}[BoldFont=FontName-Bold]
\newfontface\myface{FontName}[Scale=1.2]
```
--------------------------------
### Add `ontspec-get-fontsampletextlanguage` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve the language associated with the font's sample text.
```LaTeX
\fontspec-get-fontsampletextlanguage:n
```
--------------------------------
### Add `ontspec-get-fontsampletextfontinfo` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve general information about the font used in the sample text.
```LaTeX
\fontspec-get-fontsampletextfontinfo:n
```
--------------------------------
### Define and Manage Font Families and Faces (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces new commands for defining, setting, and renewing font families and faces. These commands provide more granular control over font selection and management within LaTeX documents.
```LaTeX
\providefontfamily
\setfontface
\renewfontface
\providefontface
```
--------------------------------
### Apply OpenType Stylistic Features
Source: https://context7.com/latex3/fontspec/llms.txt
Explains how to access stylistic alternates, swashes, stylistic sets, and character variants. These features allow for highly customized typography based on specific font capabilities.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{EB Garamond}
\begin{document}
Normal: Q R g
{\addfontfeature{Style=Alternate}
Alternate: Q R g}
Normal italic: \textit{Victoria}
{\addfontfeature{Style=Swash}
Swash italic: \textit{Victoria}}
Normal text
{\addfontfeature{StylisticSet=1}
Stylistic Set 1}
{\addfontfeature{StylisticSet=2}
Stylistic Set 2}
{\addfontfeature{StylisticSet={1,3,5}}
Combined sets 1, 3, and 5}
{\addfontfeature{CharacterVariant=1}
Character variant 1}
{\addfontfeature{CharacterVariant={4,5:2}}
Variants for glyphs 4 and 5 (option 2)}
\end{document}
```
--------------------------------
### Add `ontspec-get-fonttables` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve information about the tables within an OpenType font.
```LaTeX
\fontspec-get-fonttables:n
```
--------------------------------
### Add `ontspec-get-fontinfo` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve general information about a font.
```LaTeX
\fontspec-get-fontinfo:n
```
--------------------------------
### Configuring Variable Fonts in LuaTeX
Source: https://context7.com/latex3/fontspec/llms.txt
Demonstrates how to manipulate variable font axes such as weight, width, and slant, as well as custom axes and named instances in LuaLaTeX. This requires a variable-capable font file and the LuaTeX engine.
```latex
\documentclass{article}
\usepackage{fontspec}
\begin{document}
% Variable weight
{\fontspec{Source Sans Variable}[Weight=200]
Extra Light}\\
{\fontspec{Source Sans Variable}[Weight=400]
Regular}\\
{\fontspec{Source Sans Variable}[Weight=700]
Bold}\\
{\fontspec{Source Sans Variable}[Weight=900]
Black}
% Variable width
{\fontspec{Noto Sans}[Width=75]
Condensed}\\
{\fontspec{Noto Sans}[Width=100]
Normal}
% Variable slant
{\fontspec{Roboto Flex}[Slant=-12]
Slanted}
% Custom axes using RawAxis
{\fontspec{Recursive}[RawAxis={CASL=1,MONO=1}]
Casual monospace}
% Named instances
{\fontspec{Source Serif Variable}[Instance=Bold Italic]
Bold Italic instance}
\end{document}
```
--------------------------------
### Query Font Features and Scripts
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
These commands allow developers to check for the existence of specific font features, languages, or scripts within the current font context. They follow the standard expl3 conditional naming convention.
```latex
\fontspec_if_feature:nTF {feature} {true} {false}
\fontspec_if_language:nTF {language} {true} {false}
\fontspec_if_current_script:nTF {script} {true} {false}
\fontspec_if_current_language:nTF {language} {true} {false}
\fontspec_glyph_if_exist:NnTF \font_cs {glyph_name} {true} {false}
```
--------------------------------
### Add Features to Active Font
Source: https://context7.com/latex3/fontspec/llms.txt
Shows how to apply font features on-the-fly to the currently active font using \addfontfeatures or \addfontfeature without reloading the font.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}[Numbers=Proportional]
\begin{document}
Default proportional numbers: 1234567890
% Add old-style numbers
{\addfontfeatures{Numbers=OldStyle}
Now old-style: 1234567890}
% Useful for tables - switch to monospaced numbers
\begin{tabular}{r}
\addfontfeatures{Numbers=Monospaced}
12345 \\
67890 \\
11111 \\
\end{tabular}
% Multiple features at once
{\addfontfeatures{Numbers=OldStyle, Letters=SmallCaps}
Old-style small caps: 1234567890 ABC}
% Can also use singular form
{\addfontfeature{Color=CC0000}
Red text}
\end{document}
```
--------------------------------
### Add `ontspec-get-fontsampletext` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve sample text associated with the font.
```LaTeX
\fontspec-get-fontsampletext:n
```
--------------------------------
### Add `ontspec-get-fontsampletextsize` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve the size used for the font's sample text.
```LaTeX
\fontspec-get-fontsampletextsize:n
```
--------------------------------
### Add `ontspec-get-fonttrademark` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve trademark information for a font.
```LaTeX
\fontspec-get-fonttrademark:n
```
--------------------------------
### Add `Scale=MatchLowercase` and `Scale=MatchUppercase` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces `Scale=MatchLowercase` and `Scale=MatchUppercase` features for matching the scaling of lowercase and uppercase characters respectively. This allows for finer control over font proportions.
```LaTeX
Scale=MatchLowercase
Scale=MatchUppercase
```
--------------------------------
### Check Test Cases with l3build
Source: https://github.com/latex3/fontspec/blob/develop/doc/dev.md
Command to check the results of fontspec test cases using l3build. The --shuffle option randomizes the test order, and --halt stops execution after the first failure.
```bash
l3build check
l3build check --shuffle --halt
```
--------------------------------
### Add `ontspec-get-fontvariants` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve all available font variants for a given font.
```LaTeX
\fontspec-get-fontvariants:n
```
--------------------------------
### Use `\familydefault` for Scaling Parameters (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Modifies the calculation of scaling parameters in `Scale=MatchLowercase` and `Scale=MatchUppercase` to use `\familydefault` instead of `\rmdefault`. This provides more consistent scaling behavior across different font families.
```LaTeX
% Use \familydefault instead of \rmdefault for scaling parameters
```
--------------------------------
### Add `ontspec-get-fontversion` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve the version number of a font.
```LaTeX
\fontspec-get-fontversion:n
```
--------------------------------
### Add `ontspec-set-locale` and `ontspec-get-locale` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides macros for setting and retrieving locale information, which influences language-specific typographic rules and features.
```LaTeX
\fontspec-set-locale:n
\fontspec-get-locale:n
```
--------------------------------
### Add `ontspec-get-fontsampletextfontlocales` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve all supported locale tags for the font used in the sample text.
```LaTeX
\fontspec-get-fontsampletextfontlocales:n
```
--------------------------------
### Apply Artificial Font Transformations with Fontspec
Source: https://context7.com/latex3/fontspec/llms.txt
This snippet demonstrates how to apply artificial transformations such as fake bold, fake slant, and horizontal stretching when a font lacks proper variants. It's useful for achieving desired text effects when specific font files are unavailable. Use sparingly to maintain text integrity.
```latex
\documentclass{article}
\usepackage{fontspec}
\begin{document}
% Fake slant (when no italic available)
{\fontspec{TeX Gyre Heros}
Normal text}\
{\fontspec{TeX Gyre Heros}[FakeSlant=0.2]
Artificially slanted text}
% Fake bold (use sparingly)
{\fontspec{TeX Gyre Heros}
Normal weight}\
{\fontspec{TeX Gyre Heros}[FakeBold=1.5]
Artificially emboldened}
% Fake stretch
{\fontspec{TeX Gyre Heros}[FakeStretch=1.2]
Horizontally stretched 20\%}
% Auto-fake for missing shapes
\setmainfont{MyFont}[
AutoFakeBold=1.5, % Fake bold if no bold font
AutoFakeSlant=0.2 % Fake italic if no italic font
]
\end{document}
```
--------------------------------
### Add `ontspec-set-variant` and `ontspec-get-variant` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces macros for managing font variants, allowing users to select and query specific font variants like stylistic sets or swashes.
```LaTeX
\fontspec-set-variant:n
\fontspec-get-variant:n
```
--------------------------------
### Add `ontspec-get-fontsampletextfontlanguages` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve all supported language tags for the font used in the sample text.
```LaTeX
\fontspec-get-fontsampletextfontlanguages:n
```
--------------------------------
### Select OpenType Script and Language
Source: https://context7.com/latex3/fontspec/llms.txt
Configures specific script and language settings for OpenType fonts to ensure correct glyph shaping and localized character forms.
```latex
\documentclass{article}
\usepackage{fontspec}
% Load a font with specific script support
\newfontfamily\arabicfont{Amiri}[Script=Arabic]
\newfontfamily\devanagarifont{Noto Sans Devanagari}[Script=Devanagari]
% Language-specific features
\setmainfont{Linux Libertine O}[
Script=Latin,
Language=Turkish
]
\begin{document}
% Script selection affects glyph shaping
{\arabicfont العربية}
{\devanagarifont हिन्दी}
% Language affects localized forms
Default: ffi ligature\\
{\addfontfeature{Language=German}
German: ffi may differ}
% Multiple scripts in one document
Latin text with {\arabicfont بعض العربية} inline.
\end{document}
```
--------------------------------
### Add OldStyle and Lining Numbers Commands
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces `\oldstylenums` and `\liningnums` commands that are compatible with the fontspec package. These commands allow explicit control over the selection of old-style or lining numerals in fonts that support them.
```LaTeX
\oldstylenums
\liningnums
```
--------------------------------
### Enable HarfBuzz Rendering Engine in LuaTeX (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces new Renderer options for LuaTeX to enable the HarfBuzz engine. These options are experimental and require the `luahbtex` engine. They allow for advanced text shaping capabilities provided by HarfBuzz.
```LaTeX
% Experimental Renderer options for LuaTeX with HarfBuzz
% Requires luahbtex engine
% Options: Harfbuzz, OpenType, AAT, Graphite
```
--------------------------------
### Local and Global Font Setting Macros (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Adds local and global variants for macros that set font families and faces. This allows for more precise control over the scope of font settings, differentiating between temporary changes and document-wide configurations.
```LaTeX
\fontspec_(g)set_family:Nnn
\fontspec_(g)set_fontface:NNnn
```
--------------------------------
### Automate Package Release with Lua Script
Source: https://github.com/latex3/fontspec/blob/develop/doc/dev.md
Command to initiate the automated release procedure for the fontspec package using a Lua script. This script handles versioning, branch synchronization, tagging, and uploading to CTAN.
```bash
lua autorelease.lua
```
--------------------------------
### Add `ontspec-get-fontsampletextfontscripts` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve all supported script tags for the font used in the sample text.
```LaTeX
\fontspec-get-fontsampletextfontscripts:n
```
--------------------------------
### Compound Scaling Factors (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces the `ScaleAgain` feature for compounding scale factors. This is particularly useful for packages like `unicode-math` that require multiple scaling adjustments, allowing for more complex scaling scenarios.
```LaTeX
ScaleAgain
```
--------------------------------
### Add `ontspec-get-family` and `ontspec-get-fontface` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Adds macros `\fontspec-get-family` and `\fontspec-get-fontface` for retrieving information about the currently set font family and face.
```LaTeX
\fontspec-get-family:c
\fontspec-get-fontface:N
```
--------------------------------
### Add `ontspec-get-fontsampletextraw` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve the raw OpenType features string for the font's sample text.
```LaTeX
\fontspec-get-fontsampletextraw:n
```
--------------------------------
### Add `ontspec-set-language` and `ontspec-get-language` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides macros for setting and retrieving the language tag, essential for language-specific typographic features.
```LaTeX
\fontspec-set-language:n
\fontspec-get-language:n
```
--------------------------------
### Add `ontspec-get-fontsampletextfonttables` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve information about the tables within the font used in the sample text.
```LaTeX
\fontspec-get-
```
--------------------------------
### Add `ontspec-get-fontsampletextfontmetrics` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve font metrics information for the font used in the sample text.
```LaTeX
\fontspec-get-fontsampletextfontmetrics:n
```
--------------------------------
### Add `ontspec-get-fontcopyright` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve the copyright information for a font.
```LaTeX
\fontspec-get-fontcopyright:n
```
--------------------------------
### Define Multiple Language Tags for Font Selection (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Allows defining a font language with multiple OpenType tags. The package attempts to use the first available tag in the specified order, providing flexibility for fonts with different language tag implementations. This is useful for languages with regional variations or multiple standard tags.
```LaTeX
\newfontlanguage{Turkish}{TRK,TUR}
```
--------------------------------
### Handle Missing Script Fonts Gracefully (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Fixes a crash that occurred when loading fonts missing a requested script. The package now handles such cases more robustly, preventing document compilation failures due to missing script support in the selected font.
```LaTeX
% Fix crash when loading fonts missing a requested script
```
--------------------------------
### Add `ontspec-get-fontlocales` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve all supported locale tags for a given font.
```LaTeX
\fontspec-get-fontlocales:n
```
--------------------------------
### Add `ontspec-get-fontfeatures` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve all available font features for a given font.
```LaTeX
\fontspec-get-fontfeatures:n
```
--------------------------------
### Add `ontspec-get-fontlanguages` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve all supported language tags for a given font.
```LaTeX
\fontspec-get-fontlanguages:n
```
--------------------------------
### Configure Global and Local Font Features
Source: https://github.com/latex3/fontspec/blob/develop/doc/user.md
Manage font features globally using defaultfontfeatures or apply them to specific font instances. The addfontfeatures command allows modifying the currently active font family.
```latex
\defaultfontfeatures{Ligatures=TeX}
\defaultfontfeatures+[\myfont]{Numbers=OldStyle}
\addfontfeatures{LetterSpace=5}
```
--------------------------------
### Clone Fontspec Test Fonts Repository
Source: https://github.com/latex3/fontspec/blob/develop/doc/dev.md
Commands to clone the external repository containing freely available fonts used for the fontspec test suite and documentation build. This is useful for manual compilation.
```bash
git clone https://github.com/wspr/fontspec-test-fonts.git
cd fontspec-test-fonts
sh install.sh
```
--------------------------------
### Define Custom Font Features and Aliases
Source: https://context7.com/latex3/fontspec/llms.txt
This snippet shows how to define custom OpenType feature names and arbitrary font feature strings using `\newopentypefeature` and `\newfontfeature`. It also demonstrates aliasing existing features for brevity with `\aliasfontfeature`. This allows for more convenient and readable application of complex font features.
```latex
\documentclass{article}
\usepackage{fontspec}
% Define new OpenType feature option
\newopentypefeature{Style}{Historic}{hist}
\newopentypefeature{Ligatures}{Required}{rlig}
% Define arbitrary font feature string
\newfontfeature{ColorRed}{color=FF0000}
\newfontfeature{ColorBlue}{color=0000FF}
% Alias existing features to shorter names
\aliasfontfeature{Numbers}{Nums}
\aliasfontfeatureoption{Numbers}{OldStyle}{OS}
\setmainfont{EB Garamond}
\begin{document}
{\addfontfeature{Style=Historic}
Historic style text}
{\addfontfeature{ColorRed}
Red colored text}
% Using aliased names
{\addfontfeature{Nums=OS}
Old-style numbers: 1234567890}
\end{document}
```
--------------------------------
### Set Default Document Fonts
Source: https://github.com/latex3/fontspec/blob/develop/doc/user.md
These commands configure the primary document fonts for main text, sans-serif, and monospaced styles. They are typically used in the document preamble.
```latex
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}
```
--------------------------------
### Maintain `\oldstylenums` with `textcomp` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Fixes a regression where `\oldstylenums` could be overwritten if the `textcomp` package was loaded after `fontspec`. This ensures that old-style figures remain correctly set regardless of the loading order of these packages.
```LaTeX
% Fix for \oldstylenums overwritten by textcomp
```
--------------------------------
### Add `ontspec-get-fontsampletextvariant` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve the variant used for the font's sample text.
```LaTeX
\fontspec-get-fontsampletextvariant:n
```
--------------------------------
### Add `ontspec-set-family` and `ontspec-set-fontface` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Adds macros `\fontspec-set-family` and `\fontspec-set-fontface` for setting font families and faces, likely as lower-level primitives for `\setfontfamily` and `\setfontface`.
```LaTeX
\fontspec-set-family:Nnn
\fontspec-set-fontface:NNnn
```
--------------------------------
### Font Selection Commands
Source: https://github.com/latex3/fontspec/blob/develop/README.md
Commands for defining and selecting fonts and their features within a LaTeX document.
```APIDOC
## Font Selection Commands
### Description
Commands for defining and selecting fonts and their features within a LaTeX document.
### Commands
- `\newfontfamily{}{}[]`: Define a new font family for efficient selection.
- `\newfontface{}{}[]`: Alias for `\newfontfamily`.
- `\setmainfont{}[]`: Set the default main document font.
- `\setsansfont{}[]`: Set the default sans-serif document font.
- `\setmonofont{}[]`: Set the default monospaced document font.
- `\fontspec{}[]`: Define an ad hoc font family individually.
- `\defaultfontfeatures{}`: Specify default features for all subsequently defined fonts.
- `\defaultfontfeatures+{}`: Add features to the global default font features.
- `\defaultfontfeatures[]{}`: Specify default features for a specific font or font switch.
- `\defaultfontfeatures+[]{}`: Add features to the defaults for a specific font or font switch.
- `\addfontfeatures{}`: Add features to the currently active font family.
```
--------------------------------
### Add `ontspec-get-fontsampletextfontfeatures` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Introduces a macro to retrieve all available font features for the font used in the sample text.
```LaTeX
\fontspec-get-fontsampletextfontfeatures:n
```
--------------------------------
### Font Definition Commands
Source: https://github.com/latex3/fontspec/blob/develop/doc/user.md
Commands for defining new font families and faces for use within a document.
```APIDOC
## COMMAND \newfontfamily
### Description
Defines a new font family command for selecting fonts.
### Parameters
- **font switch** (command) - Required - The command name to define.
- **font name** (string) - Required - The name of the font to load.
- **font options** (key-value) - Optional - Configuration options for the font.
### Request Example
\newfontfamily\myfont{Arial}[Scale=1.2]
```
--------------------------------
### Add `ontspec-get-fontsampletextlocale` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve the locale associated with the font's sample text.
```LaTeX
\fontspec-get-fontsampletextlocale:n
```
--------------------------------
### Add `ontspec-get-fontdesigner` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve the name of the font designer.
```LaTeX
\fontspec-get-fontdesigner:n
```
--------------------------------
### Fontspec Internal Option Processing with l3keys
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
The fontspec package has transitioned from using the `xkeyval` package to `expl3`'s `l3keys` for option processing. This change improves compatibility, allowing fontspec to be loaded before `\documentclass` and resolving conflicts with packages like `preview`.
```LaTeX
% Previously used xkeyval
% Now uses expl3's l3keys
```
--------------------------------
### Accumulate `UprightFeatures` in `\addfontfeatures` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Fixes a bug where successive `\addfontfeatures` commands using `UprightFeatures` or similar would overwrite previous settings. Now, these features are accumulated, allowing for more complex feature stacking.
```LaTeX
% Successive \addfontfeatures with UprightFeatures={...} now accumulate
```
--------------------------------
### Control Ligatures in Fonts
Source: https://context7.com/latex3/fontspec/llms.txt
Shows how to manage OpenType ligatures including TeX-style input, common ligatures, and rare or historic variants. These settings allow fine-grained control over character combinations.
```latex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\begin{document}
Text with -- en-dash and --- em-dash.
``Quoted text'' works automatically.
The fine officeффice has many files.
{\addfontfeature{Ligatures=CommonOff}
The fine office has many files.}
{\addfontfeature{Ligatures=Rare}
Rare ligatures like ct and st.}
{\addfontfeature{Ligatures=Historic}
Historic ligatures for medieval texts.}
\end{document}
```
--------------------------------
### Add `ontspec-get-fontsampletextfeatures` (LaTeX)
Source: https://github.com/latex3/fontspec/blob/develop/doc/CHANGES.md
Provides a macro to retrieve the OpenType features applied to the font's sample text.
```LaTeX
\fontspec-get-fontsampletextfeatures:n
```