Skip to content

In math and raw, fallback to the main-text font first #8732

Open

Description

@YDX-2147483647

Description

At present, text.font for main text, raw, and math.equation are controlled separately.
And none of the default fonts1 provides glyphs for CJK / Han / East Asian characters.
As a result, to those who use such characters, sometimes it's necessary to specify the fallback font (e.g., Noto Serif CJK SC) for three times:

#set text(font: (
  (name: "Libertinus Serif", covers: "latin-in-cjk"),
  "Noto Serif CJK SC",
))
#show math.equation: set text(font: (
  "New Computer Modern Math",
  "Noto Serif CJK SC",
))
#show raw: set text(font: (
  "DejaVu Sans Mono",
  "Noto Serif CJK SC",
))

I suggest Typst changes the fallback rule in math and raw to the following.

  1. Try the text.font for math/raw as usual.
  2. If missing glyph, try the text.font for main text.
  3. If still missing, try other available fonts as usual.

Following this rule, the above configuration can be simplified as:

#set text(font: (
  (name: "Libertinus Serif", covers: "latin-in-cjk"),
  "Noto Serif CJK SC",
))

I guess this shouldn't be hard to implement. A special Fold is likely to work.

Use Case

This will make it easier to configure the font.

That really matters, because writing CJK without configuring font leads to unpredictable font fallback. (main text: #5040, #5900, #590; raw: #3385, #5748; math: #6737)

How to typeset two‑line text in a mathematical formula? - Questions - Typst Forum gives a realistic example for math:

Image Image Image

Additional considerations

  • This proposal is kind of an alternative to Text in math mode should use text font #366. The different is that Text in math mode should use text font #366 does not cover missing math symbols and raw, but this proposal does.

  • The current fallback rule for raw is different from that for main text and math.
    In raw, monospace fonts take precedence; but in main text and math, proportional fonts take precedence.

    All Han characters are squares, so most CJK fonts are monospace, but the font files may or may not claim to be monospace (isFixedPitch in the OpenType post table).

    Further consideration may be necessary here.

Footnotes

  1. Default fonts: Libertinus Serif for main text, DejaVu Sans Mono for raw, New Computer Modern Math for math.equation. ↩

Activity

  1. added
    feature request
    on Aug 9, 2026
  2. added
    text
    on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requesttext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions