What is the designed behaviour of font `covers` in math equations?

What is the designed behaviour of the following? Does the font A only covers 0 in texts in math, or all 0 in math, or anything?

#show math.equation: set text(font: (
  (name: "A", covers: regex("0")),
  "Some math font",
))

Full code
#set page(width: auto, height: auto, margin: 2em)

#set text(fallback: false)
#set raw(lang: "typc")
#show raw: set text(font: ("DejaVu Sans Mono", "Noto Serif CJK SC"))

#align(center, `$ a 0 9 "a09" $`)

= Example A

+ New Computer Modern Math
$ a 0 9 "a09" $

= Example B

+ Fira Math
#show math.equation: set text(font: "Fira Math")
$ a 0 9 "a09" $

= Example C1

+ Fira _Math_, covers `regex("0")`
+ New Computer Modern Math
#show math.equation: set text(font: (
  (name: "Fira Math", covers: regex("0")),
  "New Computer Modern Math",
))
$ a 0 9 "a09" $

= Example C2

+ Fira _Sans_, covers `regex("0")`
+ New Computer Modern Math
#show math.equation: set text(font: (
  (name: "Fira Sans", covers: regex("0")),
  "New Computer Modern Math",
))
$ a 0 9 "a09" $

My guess

  • For texts in math.equation, render the character using the first font that covers and contains it.
  • For real math in math.equation, render the chracter using the first font that support OpenType math features, ignoring covers configurations.

Background

I am trying to debug Setting fonts repeatedly with different `covers` is not effective · Issue #6566 · typst/typst · GitHub.

It looks like there was no math-specific code in Support for defining which charset should be covered by a font by peng1999 · Pull Request #5305 · typst/typst · GitHub?

And the only two references of family.covers() are both in crates/typst-layout/src/inline/shaping.rs: one in insert_hyphen, another in shape_segment.

DeepWiki:

Conclusions

So my guess is right: find_math_font only concerns about family.as_str() and ignores covers.

The font handling in math currently is very rudimentary, and doesn’t do any fallback nor supports covers. If/when Support multiple fonts in math by mkorje · Pull Request #6365 · typst/typst · GitHub gets merged, the situation in math will match normal text.

2 Likes

Thanks! I am trying to document the behaviour in TextElem, and GitHub also reminds me the existence of #6365.

Update: Wow, You are the author of #6365!

1 Like