> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-wen-zhang/29-how-to-use-opentype-variable-fonts-with-latex.md).

# 如何在 LaTeX 中使用 OpenType 可变字体

[引言](https://www.overleaf.com/learn/latex/Articles/How_to_use_OpenType_variable_fonts_with_LaTeX?preview=true) [第1步](https://www.overleaf.com/learn/latex/Articles/Step_1:_Setting_up_an_Overleaf_project_to_use_variable_fonts?preview=true) [第2步](https://www.overleaf.com/learn/latex/Articles/Step_2:_An_introduction_to_LaTeX_fonts?preview=true) [第3步](https://www.overleaf.com/learn/latex/Articles/Step_3:_Replacing_LaTeX’s_default_fonts_with_variable_fonts?preview=true) [第4步](https://www.overleaf.com/learn/latex/Articles/Step_4:_How_to_configure_an_italic_variable_font_using_fontspec?preview=true) [第5步](https://www.overleaf.com/learn/latex/Articles/Step_5:_LaTeX_font_weights_and_named_instances_of_variable_fonts?preview=true) [第6步](https://www.overleaf.com/learn/latex/Articles/Step_6:_Using_variable_fonts_to_add_bold_fonts_to_an_Overleaf_project?preview=true) [第7步](https://www.overleaf.com/learn/latex/Articles/Step_7:_Using_Noto_Sans_and_Roboto_Mono_variable_fonts_with_LaTeX?preview=true) [第8步](https://www.overleaf.com/learn/latex/Articles/Step_8:_How_to_create_a_simple_LaTeX_package_to_configure_your_variable_fonts?preview=true) [示例和项目](https://www.overleaf.com/learn/latex/Articles/Overleaf_projects_showing_how_to_use_variable_fonts_with_LaTeX?preview=true)

在本教程系列中，你将学习如何在 LaTeX 中安装、配置和使用 OpenType 可变字体，重点介绍 LuaLaTeX 和 [fontspec 宏包](https://ctan.org/pkg/fontspec?lang=en)。通过一个引导式 [Overleaf 项目](https://www.overleaf.com/8438931911svtqtnmfvsrp#28008d)，你将逐步学习涵盖实用技巧和必要背景知识的说明，从而能够自信地在 LaTeX 文档中使用可变字体。在此过程中，你还将更广泛地了解 LaTeX 字体，包括如何通过配置合适的可变字体来解决“未定义字体字形”警告。

可变字体为 LaTeX 文档设计提供了无与伦比的灵活性，可通过自定义字重和字宽等字体属性来提升文本呈现效果和可读性。它们还有助于解决排版问题，例如在给定空间中容纳更多文本。请注意，本系列仅专注于文本字体，因为用于数学排版的可变字体尚不可用。

### 教程内容

* 可变字体简介（本文）
* [第 1 步：设置一个用于使用可变字体的 Overleaf 项目](/latex/zh-cn/shen-du-wen-zhang/37-step-1-setting-up-an-overleaf-project-to-use-variable-fonts.md)
* [第 2 步：LaTeX 字体简介](/latex/zh-cn/shen-du-wen-zhang/38-step-2-an-introduction-to-latex-fonts.md)
* [第 3 步：用可变字体替换 LaTeX 的默认字体](/latex/zh-cn/shen-du-wen-zhang/39-step-3-replacing-latex-s-default-fonts-with-variable-fonts.md)
* [第 4 步：如何使用 fontspec 配置斜体可变字体](/latex/zh-cn/shen-du-wen-zhang/40-step-4-how-to-configure-an-italic-variable-font-using-fontspec.md)
* [第 5 步：LaTeX 字体字重和可变字体的命名实例](/latex/zh-cn/shen-du-wen-zhang/41-step-5-latex-font-weights-and-named-instances-of-variable-fonts.md)
* [第 6 步：使用可变字体为 Overleaf 项目添加粗体字体](/latex/zh-cn/shen-du-wen-zhang/42-step-6-using-variable-fonts-to-add-bold-fonts-to-an-overleaf-project.md)
* [第 7 步：在 LaTeX 中使用 Noto Sans 和 Roboto Mono 可变字体](/latex/zh-cn/shen-du-wen-zhang/43-step-7-using-noto-sans-and-roboto-mono-variable-fonts-with-latex.md)
* [第 8 步：如何创建一个简单的 LaTeX 宏包来配置你的可变字体](/latex/zh-cn/shen-du-wen-zhang/44-step-8-how-to-create-a-simple-latex-package-to-configure-your-variable-fonts.md)
* [5 个展示如何在 LaTeX 中使用可变字体的 Overleaf 项目](/latex/zh-cn/shen-du-wen-zhang/35-overleaf-projects-showing-how-to-use-variable-fonts-with-latex.md)

### 可变字体简介

对于排印师、设计师和字体爱好者来说，2016 年 9 月 14 日是一个值得铭记的日子。就在那一天，Microsoft、 [Google](https://opensource.googleblog.com/2016/09/introducing-opentype-font-variations.html), [Adobe](https://blog.typekit.com/2016/09/14/variable-fonts-a-new-kind-of-font-for-flexible-design/)以及 Apple [公开宣布](https://youtu.be/6kizDePhcFU?feature=shared\&t=250) 了一种名为 [OpenType 字体变体](https://medium.com/variable-fonts/https-medium-com-tiro-introducing-opentype-variable-fonts-12ba6cd2369)的新字体格式，通常更常被称为 *OpenType 可变字体* 或简称 *可变字体*.

传统上，常规、粗体、半粗体、特粗、压缩、粗压缩等每种字体样式都需要单独的字体文件，但这一点已不再必要。OpenType 可变字体是一项令人印象深刻的技术，它允许单个字体文件通过调整称为 *设计轴*的内置参数值来生成多种字体样式。这一点在下面的视频中通过 Google 的 [Noto Serif 可变字体](https://fonts.google.com/noto/specimen/Noto+Serif/tester).

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/3OhDBHA95DciCRVRgrF4wp/18f8c3f6d15109bf307c48bde9d7c879/VariableFonts.mp4>" %}

进行了演示。Google 的 Noto Serif 有两个设计轴：宽度和字重，但其他字体可能只有一个轴或多个轴——例如，一种名为 [Recursive](https://fonts.google.com/specimen/Recursive/tester) 的可变字体有五个轴， [有些甚至更多](https://www.axis-praxis.org/specimens/decovar)。字体的开发者决定轴的数量及其设计效果。

### 关于设计轴的一些说明

要在 LaTeX 中使用可变字体（具体来说是 fontspec 和 LuaLaTeX），你需要了解以下内容。

* 每个设计轴都由一个简短的四字符“标签”和一个更长、更具描述性的名称来标识。
* OpenType 可变字体规范规定了 [五个已注册的（“标准”）轴](https://learn.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg#registered-axis-tags):

|      |      |
| ---- | ---- |
| 标签   | 名称   |
| ital | 斜体   |
| opsz | 光学尺寸 |
| slnt | 倾斜   |
| wdth | 宽度   |
| wght | 字重   |

* 从 [2.9a 版本](https://github.com/latex3/fontspec/releases/tag/v2.9a)， [fontspec 宏包](https://ctan.org/pkg/fontspec?lang=en) 开始，你可以使用其名称来设置标准轴的值，例如 `Weight=400`.
* 字体创建者可以自由创建并命名其他设计轴。fontspec 提供了使用四字符标签设置任何设计轴值的功能。
* 设计轴的取值范围从最小值到最大值，步长由字体创建者确定。要在 LaTeX（LuaLaTeX）中使用可变字体，你需要了解它的各个轴，以及每个轴的最小值、最大值和增量（步长）值。
* 目前，可变字体只能用于文档正文文本——还没有可变数学字体。
* Google 维护着一个 [设计轴列表](https://fonts.google.com/variablefonts#axis-definitions) ，列出了他们提供的字体当前使用的设计轴，包括四字母设计标签、完整名称以及该轴作用的定义。

### 可变字体需要 LuaLaTeX 和 fontspec 宏包

截至 2024 年 8 月，只有 LuaLaTeX [编译器](/latex/zh-cn/zhi-shi-ku/026-changing-compiler.md) 支持 OpenType 可变字体——pdfLaTeX 和 XeLaTeX 不支持。

在 LuaLaTeX 中使用 OpenType 字体需要 fontspec 宏包，它提供用户级命令，以访问一个更低层级、更技术化的字体加载系统，称为 [luaotfload](https://ctan.org/pkg/luaotfload?lang=en)。虽然直接使用 luaotfload 的功能完全可行，但大多数人更喜欢 fontspec 的简洁与方便。

[TeX Live 2024](https://www.overleaf.com/blog/tex-live-2024-is-now-available) 包含于 2024 年 2 月 13 日发布的 fontspec 2.9a 版本，该版本增加了额外功能，使可变字体的使用更加容易。

### 我可以在哪里找到并探索一些可变字体？

访问 Google Fonts 是一个很好的起点——尤其是 [列出字体家族及其设计轴的页面](https://fonts.google.com/variablefonts)。一旦你找到感兴趣的字体，就进入它的 *类型测试器* 页面，并使用提供的控件调整其设计轴。

该 [Axis-Praxis 网站](https://www.axis-praxis.org) 可让你尝试众多可变字体，其中一些展示了引人入胜的设计可能性——包括 [Decovar](https://www.axis-praxis.org/specimens/decovar)，这是一种具有 12 个设计轴的实验性字体。你还可以将可变字体上传到 Axis-Praxis，并使用该平台自动生成的控件测试它们，以改变设计轴的值。

另一个有用的网站是 <https://v-fonts.com/>，其用途描述为“一个用于查找和试用可变字体的简单资源”。

[引言](https://www.overleaf.com/learn/latex/Articles/How_to_use_OpenType_variable_fonts_with_LaTeX?preview=true) [第1步](https://www.overleaf.com/learn/latex/Articles/Step_1:_Setting_up_an_Overleaf_project_to_use_variable_fonts?preview=true) [第2步](https://www.overleaf.com/learn/latex/Articles/Step_2:_An_introduction_to_LaTeX_fonts?preview=true) [第3步](https://www.overleaf.com/learn/latex/Articles/Step_3:_Replacing_LaTeX’s_default_fonts_with_variable_fonts?preview=true) [第4步](https://www.overleaf.com/learn/latex/Articles/Step_4:_How_to_configure_an_italic_variable_font_using_fontspec?preview=true) [第5步](https://www.overleaf.com/learn/latex/Articles/Step_5:_LaTeX_font_weights_and_named_instances_of_variable_fonts?preview=true) [第6步](https://www.overleaf.com/learn/latex/Articles/Step_6:_Using_variable_fonts_to_add_bold_fonts_to_an_Overleaf_project?preview=true) [第7步](https://www.overleaf.com/learn/latex/Articles/Step_7:_Using_Noto_Sans_and_Roboto_Mono_variable_fonts_with_LaTeX?preview=true) [第8步](https://www.overleaf.com/learn/latex/Articles/Step_8:_How_to_create_a_simple_LaTeX_package_to_configure_your_variable_fonts?preview=true) [示例和项目](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://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-wen-zhang/29-how-to-use-opentype-variable-fonts-with-latex.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.
