Skip to content

Problems on setting CJK/Han font in math equations #6737

@YDX-2147483647

Description

@YDX-2147483647

Previous title: Some math features collapse when show math.equation: set text(font: (NCM, NCM Math))

Description

Some math features are not behave normally when setting math font to ("New Computer Modern", "New Computer Modern Math").
Specifically, in the following example, the spacing between the two sides of := is lost, and { does not automatically stretch its height either.

#show math.equation: set text(font: (
  "New Computer Modern",
  "New Computer Modern Math",
))
$ f := cases(x, y) $
Image

This issue occurs only if the first font is NCM (New Computer Modern):

  • show math.equation: set text(font: (any font for regular text other than NCM, any math fonts)) ⇒ ✅
  • show math.equation: set text(font: (NCM, any math fonts)) ⇒ 😓

Futher examples

Image Image
Full code
#set page(height: auto, width: auto)

#let example = $
  f := cases(
    1 "if" (x dot y)/2 <= 0,
    2 "if" x "is even",
    3 "if" x in NN,
    4 "else",
  )
$

#let good = emoji.checkmark.box
#let bad = emoji.face.sweat

= Default #good
#example

= NCM Math #good
(NCM = New Computer Modern)
#show math.equation: set text(font: "New Computer Modern Math")
#example

= Libertinus Serif, NCM Math #good
#show math.equation: set text(font: (
  "Libertinus Serif",
  "New Computer Modern Math",
))
#example

= NCM, NCM Math #bad
#show math.equation: set text(font: (
  "New Computer Modern",
  "New Computer Modern Math",
))
#example

#pagebreak()

= Fira Math #good
#show math.equation: set text(font: (
  "Fira Sans",
  "New Computer Modern Math",
))
#example

= Fira Sans, NCM Math #good
#show math.equation: set text(font: (
  "Fira Sans",
  "New Computer Modern Math",
))
#example

= NCM, Fira Math #bad
#show math.equation: set text(font: (
  "New Computer Modern",
  "Fira Math",
))
#example

= Fira Sans, Fira Math #good
#show math.equation: set text(font: (
  "Fira Sans",
  "New Computer Modern Math",
))
#example

Why do you want (NCM, NCM Math)?

What I actually need is:

  • use Noto CJK for Han/CJK characters and punctuations, e.g., (所谓“定义”), and
  • leave other characters remain as default.

This leads to font: (NCM, Noto CJK, NCM Math).

Image
#set text(fallback: false) // For debugging

= Default
$ x = 1 "(所谓“定义”)" $

= NCM, Noto CJK, NCM Math
#show math.equation: set text(font: (
  (name: "New Computer Modern", covers: "latin-in-cjk"),
  "Noto Serif CJK SC",
  "New Computer Modern Math",
))
$ x = 1 "(所谓“定义”)" $

Ref: 如何修改公式里的中文字体? How change Chinese font in equations? | Typst 中文社区导航 typst-doc-cn guide

Env info

Reproduction URL

No response

Operating system

Web app, Linux, Windows

Typst version

  • I am using the latest version of Typst

Additionally, I've tested the basic example in main (bcc71dd).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmathRelated to math syntax, layout, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions