Skip to content
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

Automatic adjustment of font-size on math tag? #41

Open
fred-wang opened this issue Jul 3, 2020 · 7 comments
Open

Automatic adjustment of font-size on math tag? #41

fred-wang opened this issue Jul 3, 2020 · 7 comments
Labels

Comments

@fred-wang
Copy link
Contributor

This is a follow-up of w3c/mathml#37

With the rule math { font-family: math; }, the default behavior is to use a math font instead of inheriting the font from the parent that (likely) is not designed for math layout and would result in poor rendering.

The font-size is inherited, but since the surrounded text and the math formula uses two different font families, the actual size of glyphs is different.

MathJax has a configuration option to try and workaround this:
https://docs.mathjax.org/en/latest/options/output/index.html#output-matchfontheight

Do we want to enhance font-size with a property value that automatically perform this kind of font-size adjustment when changing the font-family?

Or do we want to add some special adjustment for "font-family: math" (when I checked WebKit and Chromium code, it seems they do something for font-family: monospace but not sure whether that's specified by CSS).

Or is it something that should be performed by a polyfill?

Or do we just don't care, and we should let people setup their CSS themselves?

(Note: of course, the ideal situation is when one uses a text font with its math companion, like STIX Two for the text and STIX Two Math for the math, see https://fred-wang.github.io/MathFonts/ ; this issue is about what we should do for the default)

@faceless2
Copy link

faceless2 commented Jul 3, 2020

The procedure described for the MathJax feature is almost identical to the existing font-size-adjust CSS property already defined in css-text-4, except that - instead of adjusting all fonts in the font-family list to have the same x-height, you're adjusting all fonts in the font-family list to have the same x-height as the parent element's font.

The sizing changes for font-family: monospace are an awful legacy bodge. They also only apply for named font sizes. font: medium monospace is 13px, but font: medium monospace, serif is 16px. It's not a model to emulate.

However, I think you could probably make a reasonable case for something like font-size-adjust: parent, which would adjust the x-height for the fonts used in an element, to match the x-height of the first-available-font of the parent element. I'm sure this could be applied beyond MathML as well.

@fred-wang
Copy link
Contributor Author

However, I think you could probably make a reasonable case for something like font-size-adjust: parent, which would adjust the x-height for the fonts used in an element, to match the x-height of the first-available-font of the parent element. I'm sure this could be applied beyond MathML as well.

That sounds a good idea. Probably something for @bkardell to check with the CSS people.

@litherum
Copy link

litherum commented Sep 23, 2020

Or do we want to add some special adjustment for "font-family: math"

Nope. Font families should not affect font sizes. You found the case where they do, but @faceless2 is right that it's terrible and we shouldn't replicate it.

@litherum
Copy link

font-size-adjust: parent

There's one tricky piece here which is: Which of the used fonts in the parent should be matched? The primary font's metrics? But what if none of the primary font's glyphs are actually used anywhere in the document? That seems like it would be wrong.

Another option that could work is to recommend that content which use math set font-size-adjust on the containing paragraph. It's inherited, which means the math and its surrounding text will all use the same apparent x-height.

@faceless2
Copy link

There's one tricky piece here which is: Which of the used fonts in the parent should be matched?

I think it has to be the "first available font" - we're already using this for metrics for ex/capheight etc., even if the font isn't actually used. So it would be entirely consistent to use the first-avilable font here (for anyone coming to this cold, it's defined as the the first font-face that includes U+0020 in the unicode-range).

Setting it on the parent and relying on inheritance is a bit weird. In parficular, if you just want the x-height to be whatever the normal x-height for that font is, you'd have to do font-size-adjust: calc(1ex / 1em). FIrst, that's awful, second it's taking the metric from the first-available-font again, so we're back where we started.

@NSoiffer NSoiffer transferred this issue from w3c/mathml Jun 28, 2021
@NSoiffer NSoiffer added the TPAC label Jul 26, 2021
@fred-wang
Copy link
Contributor Author

Just something to remember: we now have a font-size: math; on all MathML elements to say "take into account script level change". So that may conflict or not with the solutions proposed here.

@fred-wang
Copy link
Contributor Author

I'm not sure what's the status of this. For the record, this is on "Other tasks" of https://mathml.igalia.com/project/ but it's not clear whether this will be in the initial implementation.

@faceless2 what's the status of the discussion on the CSS WG side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants