> 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/zh-cn/shen-ru-wen-zhang/35-overleaf-projects-showing-how-to-use-variable-fonts-with-latex.md).

# 展示如何在 LaTeX 中使用可变字体的 Overleaf 项目

[引言](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)

本系列教程的最后一部分列出了由 Overleaf 创建的五个项目，旨在展示 OpenType 可变字体的使用。所有项目都包含必要的可变字体文件，以及一个 `latexmkrc` 用于将这些字体文件提供给 LaTeX 的文件。

我们建议使用免费方案的用户注意，其中一些项目的初始编译时间较长，这反映了它们对 LuaLaTeX 和 OpenType 可变字体的使用。

## 项目 1：一个已配置好 OpenType 可变字体、可直接使用的项目

* 打开 Overleaf 项目 <https://www.overleaf.com/1311295292wvdkgcbnfxsw#94292d>

此项目配置为使用 Noto Serif、Noto Sans 和 Roboto Mono。章节标题、图注和表注，甚至脚注，都被配置为使用特定的可变字体设置——请参见项目文件 `myvariablefonts.sty` 了解更多细节。

## 项目 2：使用可变字体演示 LaTeX 的字体选择命令

* 打开 Overleaf 项目： <https://www.overleaf.com/1941895198cqjzyhzvxhwz#794ae2>

此项目为 Noto Serif、Noto Sans 和 Roboto Mono 配置了许多 LaTeX 字体宽度、字重和字形的组合。它向您展示如何将这些字体与 LaTeX 的字体选择命令一起使用 `\fontseries`, `\fontshape` 和 `\fontfamily`.

![图像显示 LaTeX 的 \fontseries 命令用于排版可变字体](/files/0e9cd996f832c4396107f4634b7a7056d75b04c9)

## 项目 3：使用 babel 宏包借助可变字体排版阿拉伯语和英语

* 打开 Overleaf 项目 <https://www.overleaf.com/3933144323kswvxhnqkbcw#097c77>

本项目向您展示如何配置 OpenType 可变字体，以便与 [babel 宏包](https://ctan.org/pkg/babel?lang=en)。其中包括使用若干阿拉伯文字 OpenType 可变字体将英语和阿拉伯语混合排版的示例：

* [Noto Naskh Arabic](https://fonts.google.com/noto/specimen/Noto+Naskh+Arabic/tester)
* [Noto Nastaliq](https://fonts.google.com/noto/specimen/Noto+Nastaliq+Urdu/tester)
* [Noto Sans Arabic](https://fonts.google.com/noto/specimen/Noto+Sans+Arabic/tester)

本项目展示了 fontspec 的 `\addfontfeatures` 命令可用于对 OpenType 可变字体进行临时更改，包括本项目中使用的阿拉伯语可变字体。

![图像显示一段使用 LaTeX 和 OpenType 可变字体排版的阿拉伯语和英语段落](/files/ddfacdbd44a55b018613caaa700eb29fd65082ca)

**免责声明**：所有非英语文本及其对应翻译均由 ChatGPT 生成。

## 项目 4：展示可变字体的多种示例

* 打开 Overleaf 项目 <https://www.overleaf.com/2858462957mvthxfmtgxsc#11aac1>

本项目包含若干示例，展示如何使用 fontspec 的 `\addfontfeatures` 命令对可变字体进行临时调整；例如，临时更改字体的宽度或字重，以调整排版某些文本所需的空间。以下各节概述了这些示例，并提供背景信息，帮助您充分利用每一个示例。

### 示例：更改字体宽度以在给定空间内容纳更多文本

本示例使用 fontspec 的 `\addfontfeatures` 命令，演示对可变字体宽度做很小、几乎难以察觉的缩减，就能在给定空间内排入更多文本。两个包含相同文本的 minipage 并排排版，对比未压缩的 Noto Serif 与其宽度轴值减少 4% 的版本。

![图像显示减小可变字体宽度可以在给定空间内容纳更多文本](/files/61e537acf4c289b18d71d02ba3231e8c10e2e3db)

### 示例：在 fancyvrb 宏包中使用可变字体

使用 fontspec 的 `\newfontfamily` 命令，本示例演示如何使用您选择的可变字体在一个 `Verbatim` 环境中进行程序代码排版，该环境由 [`fancyvrb` 宏包](https://ctan.org/pkg/fancyvrb?lang=en)提供。它还展示了如何使用 LaTeX 的 `\fontseries` 命令。

![图像显示使用可变字体排版的逐字文本](/files/4818e2c418aa4a61d5529b7d1a2c718392579d3d)

#### 关于 Verbatim 环境的一些说明

该 `Verbatim` 环境的形式如下

```latex
\begin{Verbatim}[⟨settings⟩]
⟨input⟩
\end{Verbatim}
```

其中

* 该 `[⟨settings⟩]` 部分是可选的。 `⟨settings⟩` 可以包含参数（键值对），用于配置此特定 `Verbatim` 环境
* `⟨input⟩` 是您要排版的文本

一个 `Verbatim` 该环境会禁用 LaTeX 的默认文本处理，因此 `⟨input⟩` 文本可以原样排版——包括空格、LaTeX 命令、特殊字符和换行。

若要格式化 `⟨input⟩` 文本，例如应用粗体或斜体，请使用 `commandchars` ……中的键 `⟨settings⟩` 部分中的链接。 `commandchars` 指定三个“特殊”字符，这些字符可用于 `⟨input⟩` 用于调用 LaTeX 宏，而不是被直接排版。为避免错误和冲突，请选择三个不会出现在常规 `⟨input⟩` 文本。

例如，写出

```latex
\begin{Verbatim}[commandchars=|()]
⟨input⟩
\end{Verbatim}
```

会告诉该 `Verbatim` 环境将字符视为 `|`, `(`以及 `)` 作为命令字符。如果它们出现在 `⟨input⟩` LaTeX 将按如下方式处理它们：

* `|` 用于引入 LaTeX 命令——替代通常的 `\` 字符。
* `(` 和 `)` 用于分隔 LaTeX 命令参数——而不是通常的 `{` 和 `}`

例如，要将部分 `⟨input⟩` 文本排版为粗体，您可以写 `|textbf(some text)` 而不是写 `\textbf{some text}`.

### 示例：使用不同样式排版数字

本示例使用 fontspec 的 `\addfontfeatures` 命令来临时更改用于排版字符 0、1、2……9 的样式，这些字符通常被称为“digits”或“numbers”。排版师和设计师将这些字符称为“figures”，本示例中采用这一术语。

#### 关于排版和数字样式的一些说明

随着时间推移，针对不同文档元素（例如表格、正文或文档标题）的人们开发出了不同的数字排版样式。这些样式根据数字的三个属性来定义：宽度、高度，以及相对于基线的对齐方式。

有两种样式基于数字宽度：

* **比例式**：每个数字的宽度会根据其设计而变化。
* **tabular**：每个数字的宽度相同。

有两种样式基于数字高度和对齐方式：

* **齐线体**：数字位于基线之上，且其设计特征不会低于基线。所有数字高度相同。
* **旧式**：数字高度会变化，且数字设计的一部分可能出现在基线以下。

将这些组合起来，就得到下图所示的四种排版样式：

![](/files/8b0741cacb32d3021ccf45728ee48e7d33470e8f)

一个 [Monotype 发表的文章](https://www.monotype.com/resources/expertise/how-use-figure-styles-illustrator) 讨论了如何使用这些数字样式。

#### 如何获取这些数字样式

这些数字样式是否可用取决于用于排版文档的 OpenType 可变字体或非可变字体。幸运的是，Noto Serif 支持这四种数字样式，因此我们可以使用 `\addfontfeatures` 使用 fontspec 的 `Numbers` 键——请注意 `OldStyle`。下表是所提供的示例之一：

![显示用于排版数字的四种样式的表格：表格旧式、比例旧式、表格齐线和比例齐线。](/files/500a37fa150f2e0a0bf43912e97462c59ab2e932)

* 打开 Overleaf 项目 <https://www.overleaf.com/2858462957mvthxfmtgxsc#11aac1>

## 项目 5：使用可变字体演示 LaTeX 的“虚拟”字体字形

* 打开 Overleaf 项目 <https://www.overleaf.com/4719455662kydjkfvdwjpn#2ea0f1>

LaTeX 的“虚拟”字体字形并不代表物理字体；相反，它们旨在与 `\fontshape` 配合使用，以更改当前字形。项目示例展示了如何使用命令 `\fontshape`, `\textup`, `\textulc`, `\upshape`以及 `\ulcshape`.


---

# 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/zh-cn/shen-ru-wen-zhang/35-overleaf-projects-showing-how-to-use-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.
