Skip to content

Center large math operators on axis#1735

Merged
laurmaedje merged 1 commit intotypst:mainfrom
damaxwell:centerlarge
Jul 20, 2023
Merged

Center large math operators on axis#1735
laurmaedje merged 1 commit intotypst:mainfrom
damaxwell:centerlarge

Conversation

@damaxwell
Copy link
Contributor

@damaxwell damaxwell commented Jul 16, 2023

Closes #1620

The large integral sign in Libertinus Math, glyph /integral.size1, has an abnormally low baseline.
image

If used as-is, this leads to the suboptimal layout reported in #1620. Nevertheless, LaTeX does a fine job typesetting with it. From the TeXbook, page 155 (see also Appendix G, rule 13, page 444):

"A character of class 1, i.e. a large operator like \sum, will be vertically centered with respect to the axis when it is typeset. <snip> This vertical adjustment is not made for any of the other classes."

That is, the glyph baseline is simply ignored if the character is a large operator (like \sum, \int, \prod, etc), and it is centered nicely instead. This PR implements this same policy for Typst. Only one test image needed updating after this change; there were minusucle pixel variations (<1%) associated with a single inline integral sign. This means that fonts used the test suite are already setting baselines to follow this policy.

#show math.equation: set text(font: "Libertinus Math", fallback: false)

$ sum_(k=0)^oo integral_0^oo e^(-k x^2) dif x $

Before

image

After

image

@Enivex
Copy link
Collaborator

Enivex commented Jul 17, 2023

I'm not sure ignoring the font properties like *TeX does is a good idea. My guess is that it's done primarily for historical reasons. This is really something that should be fixed in the font itself. There might be a good reason for why a font author would like an opinionated baseline for their symbols.

cc: @alerque

@damaxwell
Copy link
Contributor Author

MS Word also centers the integral sign on the axis; see its results below. Presumably it's doing so motivated by the TeX math layout algorithm.
image

@damaxwell
Copy link
Contributor Author

damaxwell commented Jul 20, 2023

Here's MathML rendered by Firefox (same expression, same Libertinus Math font):
image
Again, the integral sign is centered on the axis. I dug into the MathML standard to find out why.

Symbols in MathML are represented by the <mo> element, which has properties that include stretchy, symmetric and largeop which can be set explicitly. The largeop property controls whether the glyph gets bigger in display mode (corresponding to MathClass::Large, and the symmetric property controls whether the symbol is typeset centered on the axis.

For something like <mo>∫</mo> where these properties aren't explicitly set, they are inferred from the unicode character and some additional info about its placement relative to other elements (prefix/infix/postfix). Table 25 of the Math ML Core Spec "how to determine the category of an operator" shows how characters and positions map to classes A-M of Table 26. The large operators are listed in this table only in prefix position, and appear as either class H or class J. Class H has properties symmetric and largeop and class J has properties symmetric, largeop and moveablelimits. That is, H is for integrals, and J is for all the other large operators.

The upshot is that, by default, MathML makes every large operator symmetric about the axis. This can be overridden by the content author by setting the symmetric property.

In summary: TeX's layout algorithm bakes in centering large operators on the axis (and hence its offspring do as well), MS Word appears to do the same, and it's the default behaviour in MathML. A math font designer working in this environment would know all of this, and whatever might motivate the choice of baseline for a large operator, it wouldn't be to affect default math layout because the standard of the major engines is to center the glyph on the axis. Maybe in the future Typst will allow a symmetric toggle, but that seems pretty niche. Typst's default should be to follow the other standards and center the large operator glyphs.

@damaxwell
Copy link
Contributor Author

Oh, and this is a two-fer! Closes #1272

image

@laurmaedje laurmaedje merged commit 6a396ae into typst:main Jul 20, 2023
@laurmaedje
Copy link
Member

I'm convinced. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect baseline for integrals with Libertinus Math

3 participants