-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support multiple fonts in math #6365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Why is raw emoji showing but |
I don't know exactly what you're referring to, but it probably has to do with math fonts not having emojis in them. |
When written as |
Yes, that's why.
I can't reproduce this, they both render as tofus on this branch. |
abe5a38
to
c516a65
Compare
I've opened typst/typst-dev-assets#7 to add another math font to the test suite. |
2587d3b
to
fe4a4cc
Compare
da12225
to
e84434a
Compare
27ebd1d
to
2baaf22
Compare
69cca4f
to
e06ebac
Compare
crates/typst-layout/src/math/mod.rs
Outdated
.and_then(|id| world.font(id)) | ||
.filter(|_| family.covers().is_none()) | ||
}) | ||
.ok_or(::ecow::eco_vec![error!(span, "no font could be found")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is new, right? I guess relying purely on fallback does not work with the font stack thing, but also generally fails because we need all those metrics?
This seem a bit inconsistent with how font fallback otherwise works in Typst, but I guess it is not more restrictive than before with "current font is not suitable for math".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically replaced the old "current font doesn't support math" error thing. Yeah, we just need to grab whatever the current font is for the metrics.
Surely though this error will basically never occur, right? (Unless the font specified doesn't exist and fallback is disabled, I guess)
366add8
to
d7a83b7
Compare
5715c49
to
b58935a
Compare
172274f
to
8e671b4
Compare
Thank you. This is excellent work! |
Font handling
The default math font (new computer modern math) has been added to the text font fallback list. This means that math will always be able to render, as long as the user doesn't#set text(fallback: false)
.The way in which font fallback in math works is nearly identical to normal text layout. The key difference is that we only use fonts that have a MATH table present, skipping ones that don't. Note that while strings in math don't use the text font, they do go through normal text layout. So$🍏$
will render as a tofu, whereas$"🍏"$
will not.Math layout will fallback through all available fonts, and has its own set of fallback fonts distinct from normal text.
Test changes caused by font handling
math-font-fallback: Font fall back in math only goes through fonts with a MATH table.
math-lr-scripts: The
zws
is now just ignored, so it no longer removes the spacing after thelr
. (i.e. the test now matches what it would look like if thezws
weren't there.)Repr in math
RawElem
in math is kinda weird. At the moment it basically ends up going throughlayout_external
since the font has changed:typst/crates/typst-layout/src/math/mod.rs
Lines 474 to 481 in 0a3c693
RawElem
off during realisation in math mode and add a check to not set the baseline for aRawElem
.Multiple fonts in math
As the name of the PR would suggest, multiple fonts now just work in math. No need for
box
hacks anymore.New tests as examples
math-font-features-switch: You can use glyphs from a font's stylistic sets now. Notice that the math kerning with the subscripts is still working!

math-font-covers: You can use covers with fonts in math now, so that specific glyphs are from a given font. Again, notice the kerning with the subscripts.

math-op-font: You can use any font you'd like operators and limits will work as specified.

math-op-set-font: Notice the improved kerning between the letters in each operator (less space between

c
andh
insech
, more space betweeno
andd
inmod
) as well as the ligature.More customisation and control
Whenever a glyph is laid out in math by Typst (e.g. the delims for matrices, the accent glyph for accents), it now goes through realisation. Essentially, this means you can now target them with show rules. Combine this with proper support for multiple fonts, and you can do all sorts of stuff (even very cursed things)!
New tests as examples
math-root-show-rule-1

math-root-show-rule-2

math-root-show-rule-3

math-root-show-rule-4

math-root-show-rule-5

math-delim-show-rule-1

math-delim-show-rule-2

math-delim-show-rule-3

math-delim-show-rule-4

math-delim-show-rule-5

math-primes-show-rule

math-glyph-show-rule

math-accent-show-rule-1

math-accent-show-rule-2

math-accent-show-rule-3

math-accent-show-rule-4

Issues