Skip to content

如何修改公式里的中文字体?

如何修改公式里的中文字体?

若不专门设置,公式中的中文通常是楷体:

typst
$ hat(alpha)(f) = f(alpha) "(同上,α–map的“定义”)"$
$ f(alpha) #[或者*任意*内容 _α–map_ $alpha$–map] $
$ "Math" 1 I l "vs. 正文 1Il" $
Typst compiled image

✅ Typst 0.13 已改进

#5305 目前可以对不同字符分别设置不同的字体。

配置正文字体后,请继续设置数学公式的字体:

typst
#show math.equation: set text(font: (
  (name: "Libertinus Serif", covers: "latin-in-cjk"), // 西文
  "Source Han Serif SC", // 中文
  "New Computer Modern Math", // 数学
))
Typst compiled image
  1. 西文字体,负责 123abc,"!、{}()

    Libertinus Serif 是 typst 内置的字体,可换为其它西文字体。

  2. 中文字体,负责汉字和,“”!

    Source Han Serif SC 可换为其它中文字体。

  3. 数学字体,负责公式中的复杂排版

    New Computer Modern Math 是 typst 内置的字体,可换为其它支持 OpenType 数学特性的字体。

若计划中西共用同一字体

可合并前两项,例如:

typst
#show math.equation: set text(font: (
  "Source Han Serif SC",
  "New Computer Modern Math",
))
Typst compiled image

注意这里第一处_α–map_没有倾斜,因为 Source Han Serif SC 缺少相应字形。

此外,不建议设置 #show math.equation: set text(fallback: false)

如果你使用旧版本,请使用以下旧方案。

使用 regex("\p{script=Han}") 匹配中文。

typst
#show math.equation: it => {
  show regex("\p{script=Han}"): set text(font: "Source Han Serif SC")
  it
}
Typst compiled image
What do you think?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v3.5.1

基于 MIT 许可发布