> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/in-depth-articles/39-step-3-replacing-latex-s-default-fonts-with-variable-fonts.md).

# Step 3: Replacing LaTeX’s default fonts with variable fonts

[Introduction](https://www.overleaf.com/learn/latex/Articles/How_to_use_OpenType_variable_fonts_with_LaTeX?preview=true) [Step 1](https://www.overleaf.com/learn/latex/Articles/Step_1:_Setting_up_an_Overleaf_project_to_use_variable_fonts?preview=true) [Step 2](https://www.overleaf.com/learn/latex/Articles/Step_2:_An_introduction_to_LaTeX_fonts?preview=true) [Step 3](https://www.overleaf.com/learn/latex/Articles/Step_3:_Replacing_LaTeX’s_default_fonts_with_variable_fonts?preview=true) [Step 4](https://www.overleaf.com/learn/latex/Articles/Step_4:_How_to_configure_an_italic_variable_font_using_fontspec?preview=true) [Step 5](https://www.overleaf.com/learn/latex/Articles/Step_5:_LaTeX_font_weights_and_named_instances_of_variable_fonts?preview=true) [Step 6](https://www.overleaf.com/learn/latex/Articles/Step_6:_Using_variable_fonts_to_add_bold_fonts_to_an_Overleaf_project?preview=true) [Step 7](https://www.overleaf.com/learn/latex/Articles/Step_7:_Using_Noto_Sans_and_Roboto_Mono_variable_fonts_with_LaTeX?preview=true) [Step 8](https://www.overleaf.com/learn/latex/Articles/Step_8:_How_to_create_a_simple_LaTeX_package_to_configure_your_variable_fonts?preview=true) [Examples and projects](https://www.overleaf.com/learn/latex/Articles/Overleaf_projects_showing_how_to_use_variable_fonts_with_LaTeX?preview=true)

In this step, we introduce three commands from the fontspec package that will be used to replace LaTeX’s default fonts with variable fonts.

## Using fontspec to change LaTeX’s default fonts

We'll use the following fontspec package commands to replace LaTeX's default fonts with variable fonts of our choice:

* `\setmainfont{⟨font⟩}[⟨font features⟩]` sets the font used for the main document text.
* `\setsansfont{⟨font⟩}[⟨font features⟩]` sets the sans serif font.
* `\setmonofont{⟨font⟩}[⟨font features⟩]` set the monospaced font.

Each of these commands has two components:

* `⟨font⟩`: a required argument, contained in braces `{...}`, which specifies the font we want to use, given as a font name of the name of a font file.
* `⟨font features⟩`: an optional argument, contained in square brackets `[...]`, used to enable font-specific features, including configuring variable fonts.

These commands will be explained in more detail later in the tutorial.

## How to activate the tutorial project’s variable fonts

Follow these steps to activate and use the project’s variable fonts.

1. Open the initial tutorial project and update it by pasting the following code into the document preamble—paste it after the line `\usepackage{fontspec}`.

```latex
% Document family main text font
\setmainfont{NotoSerif-VariableFont-wdth-wght.ttf}
% Document family sans serif font
\setsansfont{NotoSans-VariableFont-wdth-wght.ttf}
% Document family monospaced font
\setmonofont{RobotoMono-VariableFont-wght.ttf}
```

![Image showing where to paste LaTeX code in the document preamble](/files/gHYDPeoliR7mtMFtC0ef)

4. Recompile the updated project to typeset it using variable fonts. You should notice the following issues:

* The typeset document no longer has any bold or italic text.
* There are three warnings of “undefined font shapes”:

![Image showing LaTeX missing font warnings.](/files/wcFlcJMSAJztTl0E3GDi)

## Why do I see “undefined shape” warnings?

Our initial setup for variable fonts is *very* basic, enabling upright, medium-weight fonts only. As a result, LaTeX issues “undefined shape” warnings, alerting you that it no longer has access to fonts for typesetting the bold, bold-italic, and regular-italic text used in our document.

## Understanding LaTeX’s “undefined shape” warnings

As explained in Step 2, LaTeX classifies each text font according to five attributes: encoding, family, series, shape, and size. If you try to use a font whose combination of attributes—encoding, family, series, and shape—don’t correspond to known “real” font, then LaTeX will issue an “missing shape” warning. These warnings can be prevented by configuring a font with the required attributes.

### The structure of these warnings

Each warning has the structure

``Font shape `*encoding/family name/series/shape*' undefined``

as shown in this graphic:

![Image showing structure of LaTeX missing shappe warnings](/files/GRY5TVENv0QnlryvGyp9)

### What are these warnings telling us?

Each of the following warnings is explained below.

![Image showing LaTeX missing font warnings.](/files/wcFlcJMSAJztTl0E3GDi)

1. **``Font shape `TU/NotoSerif-VariableFont-wdth-wght.ttf(0)/b/n' undefined``**

LaTeX does not have access to a font with the following combination of attributes:

* *encoding*: **`TU`** (Unicode).
* *family*: `**NotoSerif-VariableFont-wdth-wght.ttf(0)**`—a lengthy family name created by the fontspec package when we used the \setmainfont command. We explore family names later in the series.
* *series*: **`b`** → **b**old *weight*, **m**edium *width* (the **m** is dropped).
* shape: **`n`** → **n**ormal (upright) *shape.*

LaTeX lacks a **b**old weight, **m**edium width (series), and **n**ormal (upright) shape font in the `NotoSerif-VariableFont-wdth-wght.ttf(0)` family.

4. **``Font shape `TU/NotoSerif-VariableFont-wdth-wght.ttf(0)/b/it' undefined``**

LaTeX does not have access to a font with the following combination of attributes:

* *encoding*: **`TU`** (Unicode).
* *family*: `**NotoSerif-VariableFont-wdth-wght.ttf(0)**`*.*
* *series*: `**b**` → **b**old weight, **m**edium width (the **m** is dropped).
* *shape*: it → italic shape.

LaTeX lacks a **b**old weight, **m**edium width (series) **it**alic (shape) font in the `NotoSerif-VariableFont-wdth-wght.ttf(0)` family.

8. ``**Font shape `TU/NotoSerif-VariableFont-wdth-wght.ttf(0)/m/it' undefined**``

LaTeX does not have access to a font with the following combination of parameters:

* encoding: TU (Unicode)
* family: NotoSerif-VariableFont-wdth-wght.ttf(0)
* series: m → medium weight, medium width (note use of a single m)
* shape: it → italic shape

LaTeX lacks a medium-weight, medium-width (series) italic (shape) font in the NotoSerif-VariableFont-wdth-wght.ttf(0) family.

## In the next Step

In Steps 4 to 6 we’ll fix these warnings by configuring our variable fonts to provide the missing font shapes.

[Introduction](https://www.overleaf.com/learn/latex/Articles/How_to_use_OpenType_variable_fonts_with_LaTeX?preview=true) [Step 1](https://www.overleaf.com/learn/latex/Articles/Step_1:_Setting_up_an_Overleaf_project_to_use_variable_fonts?preview=true) [Step 2](https://www.overleaf.com/learn/latex/Articles/Step_2:_An_introduction_to_LaTeX_fonts?preview=true) [Step 3](https://www.overleaf.com/learn/latex/Articles/Step_3:_Replacing_LaTeX’s_default_fonts_with_variable_fonts?preview=true) [Step 4](https://www.overleaf.com/learn/latex/Articles/Step_4:_How_to_configure_an_italic_variable_font_using_fontspec?preview=true) [Step 5](https://www.overleaf.com/learn/latex/Articles/Step_5:_LaTeX_font_weights_and_named_instances_of_variable_fonts?preview=true) [Step 6](https://www.overleaf.com/learn/latex/Articles/Step_6:_Using_variable_fonts_to_add_bold_fonts_to_an_Overleaf_project?preview=true) [Step 7](https://www.overleaf.com/learn/latex/Articles/Step_7:_Using_Noto_Sans_and_Roboto_Mono_variable_fonts_with_LaTeX?preview=true) [Step 8](https://www.overleaf.com/learn/latex/Articles/Step_8:_How_to_create_a_simple_LaTeX_package_to_configure_your_variable_fonts?preview=true) [Examples and projects](https://www.overleaf.com/learn/latex/Articles/Overleaf_projects_showing_how_to_use_variable_fonts_with_LaTeX?preview=true)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/in-depth-articles/39-step-3-replacing-latex-s-default-fonts-with-variable-fonts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
