W3C home > Mailing lists > Public > public-css-archive@w3.org > September 2020

[csswg-drafts] [math] [css-fonts] Solution to mixing text and math fonts in a document (#5534)

From: Frédéric Wang via GitHub <sysbot+gh@w3.org>
Date: Sat, 19 Sep 2020 10:00:21 +0000
To: public-css-archive@w3.org
Message-ID: <issues.opened-704852714-1600509620-sysbot+gh@w3.org>
fred-wang has just created a new issue for https://github.com/w3c/csswg-drafts:

== [math] [css-fonts] Solution to mixing text and math fonts in a document ==
cc @litherum @jfkthame @drott @bkardell 

This is an item to discuss for the next CSSWG Math meeting.

Documents containing equations use fonts for the text (e.g. STIX Two Text, Cambria, Latin Modern...) and a companion font for the math (e.g. STIX Two Math, Cambria Math, Latin Modern Math...). Obviously, the former fonts have usual italic/bold variants, glyphs and font features to write "normal" text while the latter has all the specialized features for rendering formulas (math symbols, operator stretching, layout parameters, etc).

In the ideal situation where one has total control on the environment (e.g. TeX systems, Microsoft Word on Windows), it can be ensured that a pair of such fonts is available and used to get beautiful rendering. This is not necessarily the case on the Web : Even if [Web fonts can be used](https://github.com/fred-wang/MathFonts/blob/gh-pages/STIX/mathfonts.css), most authors either intentionally want to use non-matching fonts (like their favorite text font + their favorite math font), or even worse don't provide any math font at all.

This has two consequences:

1. If font-family on the `<math>` tags is not set to one installed on the user's computer/device or provided via a web font, then the mathematical formula will render with a text font, resulting in poor rendering.

2. Even if font-family on the `<math>` tags is set to an available math font, this one may be different from the inherited font-family of the surrounding text, resulting in inconsistent font-size between text and inline math.

In order to solve 1., Firefox implements a mechanism similar to how it selects fonts for different languages (lang attribute), essentially claiming that `<math>` tags have an 'x-math' language and picking known math fonts from the user preference. WebKit instead just hardcodes some known math fonts in its MathML UA stylesheet. Chromium does not have any mechanism implemented yet.

Browsers have not implemented anything in order to solve 2, although it seems WebKit & Chromium have a similar adjustment mechanism when moving to a "monospace" family for example. MathJax also has a [heuristic to perform adjustments via JavaScript measurements](https://docs.mathjax.org/en/latest/options/output/index.html#output-matchfontheight).

The MathML CG would like to find a cross-compatible CSS-based solutions to address these use cases:

For 1. it seems implementing `font-family: math` in browsers is the way to go, although there is some discussion about limiting generic families (see #4910). This would allow to make the default math font configurable by the users.

For 2. @faceless2 proposed extending `font-size-adjust` to compare the size against the font inherited from the parent could work?


Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5534 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Saturday, 19 September 2020 10:00:23 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 19 October 2021 01:31:33 UTC