gpt4 book ai didi

latex - 数学中的字母和数字不使用 "mainfont"也不使用 "mathfont"

转载 作者:行者123 更新时间:2023-12-03 07:58:27 24 4
gpt4 key购买 nike

我注意到,在数学模式下(即四开本、$$...$$$...),正在设置字母和数字使用默认字体,无论 mainfontmathfont。因此,变量名称和数字以不同的字体排版。

mathfont 确实对数学运算符有影响,例如\log 使用mathfont进行排版。然而,字母和数字则不然。这是预期的行为吗?

我知道一个解决方法。即对整个方程使用\mathit{},然后对需要直立的数字使用\mathrm{}。然后它看起来是正确的,但它使编码变得更加繁重(比它已经可能的)。

编译以下文档来查看问题:

---
documentclass: article
mainfont: Lato
mathfont: Lato
---
$$ y = 123\cdot\log{x} $$
$$ \mathit{y = \mathrm{123}\cdot\log{x}} $$

(最终替换为您自己的字体)。第二个方程看起来应该是这样的。在第一个方程中,只有运算符 (log) 使用 mathfont。其他项目使用默认的“latex”字体(与未指定 mainfont 时的字体相同)。

最佳答案

并非每种字体都包含必要的数学符号,Lato 不包含它们。您将在 .log 文件中看到如下警告:

Package fontspec Warning: Font "Lato" does not contain requested Script
(fontspec) "Math".

特别是对于无衬线字体,没有太多可供选择的字体,而且现有的少数字体通常不完整。

Fira Math 是一种提供相当好的覆盖范围的无衬线字体(...但它的设计可能有点两极分化)

---
documentclass: article
mainfont: Lato
mathfont: Fira Math
format:
pdf
---
$$ y = 123\cdot\log{x} $$
$$ \mathit{y = \mathrm{123}\cdot\log{x}} $$

enter image description here


如果您想在数学模式下使用文本字体中的字母和数字,您可以使用 mathastext 包:

% !TeX TS-program = lualatex
\documentclass{article}

\usepackage[no-math]{fontspec}
\setmainfont{Lato}
\usepackage{mathastext}

\begin{document}

\[ y = 123\cdot\log{x} \]

\end{document}

enter image description here

关于latex - 数学中的字母和数字不使用 "mainfont"也不使用 "mathfont",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75288350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com