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

Mechanism to determine the default font-family / font-size on the <math> tag #37

Closed
fred-wang opened this issue Feb 22, 2019 · 9 comments
Labels
css / html5 Issues related to CSS or HTML5 interoperability MathML Core Issues affecting the MathML Core specification

Comments

@fred-wang
Copy link

Currently WebKit has some default list of math font-family to try on the math root in the user agent stylesheet. Gecko has "font-family: sans-serif;" but also some preferences for math font that can be configured using the standard font menu of Firefox (it relies on a "math" lang).

https://trac.webkit.org/browser/trunk/Source/WebCore/css/mathml.css
https://dxr.mozilla.org/mozilla-central/source/layout/mathml/mathml.css

"Finally, one of the most important issue is the choice of the math font.
Note that most stylistic math properties are actually included in the
font itself so it's great that authors can just use the CSS font-family
to select their preferred fonts (possibly provided as Web fonts), and
make it consistent with the rest of the page. However, to determine the
default math fonts, some mechanisms should probably be formalized and
implemented in web engines:

  1. Text fonts are not appropriate for math layout. Hence making the
    element inherit the text font is a very bad idea. Ideally, web
    engines should have a mechanism to try and find math fonts in the
    specified CSS font-family lists and to fallback to known math fonts on
    the system.

  2. One consequence is that we are likely to get different text and math
    fonts and so inconsistent font-size. Instead of making the
    element inherit the font-size, Web engines should probably have a
    mechanism to automatically adjust the font-size.

  3. Even with this adjustment, the style of the font faces of the text
    and math fonts may be inconsistent. Many text fonts have a math
    companion e.g. STIX / STIX Math, Latin Modern Roman / Latin Modern Math,
    DejaVu Serif / DejaVu Math TeX Gyre etc It would be good to have a
    mechanism to map a font to its math companion (probably this should be
    discussed on the Open Font Format mailing list). Then the font-family
    can be determined using this mapping and this solves all the issues of
    inconsistent style and font-size.

So to summarize, the idea to determine the default font-family /
font-size on the element would be: a) find a math font that fits
best (font-size and fontface style) with the inherited font-family and
b) adjust the font-size if necessary to match the parent font-size."
Original report: https://lists.w3.org/Archives/Public/www-math/2016Jul/0025.

@fred-wang fred-wang added MathML Core Issues affecting the MathML Core specification css / html5 Issues related to CSS or HTML5 interoperability labels Feb 22, 2019
@fred-wang
Copy link
Author

This was also reported in the MathMLinHTML5 implementation note ( https://gitlab.com/mathml/MathMLinHTML5/issues/26 ):

'From http://www.mathml-association.org/MathMLinHTML5/output/S2.html#SS3.SSS2:
"Because mathematical formulas are generally written with special fonts, the default user agent stylesheet must reset the CSS font-family on the math element to serif. User agents should then use their own mechanism to try and interpret this serif value on the math element as a font with an OpenType MATH table."

This is maybe too specific to Gecko's implementation. The note should probably just suggest to make the user agent stylesheet change the font-family in order to force the selection of a math font.

To solve size inconsistency between the text font and math font, maybe introduce a new CSS keyword for font-size ("auto-adjust", "match-parent" or something like that) that would tell the CSS engines to automatically adjust the font-size of an element to take into account font-family change, so that the text height remains the same. See https://phabricator.wikimedia.org/T132607'

@dani31415
Copy link

The above URL changed: https://mathml-refresh.github.io/mathml-core/#cssuseragent

@fred-wang
Copy link
Author

One thing I was thinking about would be to define a "font-family: math" to have the browsers search for a math font and give the possibility to make the list of math fonts configurable. Firefox currently relies on an internal "math" lang instead but that's not the mechanism we have in WebKit/Chromium

@fred-wang fred-wang added the need resolution Issues needing resolution at MathML Refresh CG meeting label May 16, 2019
@fred-wang fred-wang added the need tests Issues related to writing WPT tests label Sep 16, 2019
@faceless2
Copy link

font-family: math is already defined in https://www.w3.org/TR/css-fonts-4/#generic-font-families, although I don't know how widely implemented it is yet.

@fred-wang
Copy link
Author

@faceless2 Thanks for the information, that's great. Then if the CSS WG already agreed about it we could just implement it in browsers.

@NSoiffer
Copy link
Contributor

@fred-wang: At the meeting today, we discussed math fonts and specifying the font to use via CSS. I asked about having to use a Web font because most users don't have math fonts on their machines. That could be remedied if every browser included at least one math font when they did the install. Any idea of whether there are plans to include one in the Chrome download? Does Firefox include any (STIX?) when it is downloaded?

@fred-wang
Copy link
Author

Any idea of whether there are plans to include one in the Chrome download? Does Firefox include any (STIX?) when it is downloaded?

This has been discussed for years. I don't think this is something likely to happen (especially on mobile browser, as long as we don't do w3c/mathml-core#122 to reduce font-size). There is already Cambria on Windows and as I said I pinged Apple regarding upgrading the pre-installed STIX font on mac. We could talk about #330 again with Google. There is a bug to bundle font in Firefox, but again I don't think that will happen anytime soon. For now the best we can have is https://addons.mozilla.org/en-US/firefox/addon/mathml-fonts (which should work in any browser).

Anyway, I think this is orthogonal to this issue, which is just about trying to pick available math fonts when possible instead of just using text ones. Pre-installed fonts is out of the decision of this CG. I suspect having more native mathml users would help to convince maintainers about the importance of math fonts.

fred-wang added a commit to w3c/mathml-core that referenced this issue Mar 24, 2020
@fred-wang
Copy link
Author

Consensus from 2020/03/23: use font-family: math

spec updated

@NSoiffer NSoiffer removed the need resolution Issues needing resolution at MathML Refresh CG meeting label Mar 24, 2020
fred-wang added a commit to web-platform-tests/wpt that referenced this issue May 27, 2020
fred-wang added a commit to web-platform-tests/wpt that referenced this issue May 27, 2020
…23786)

* Add MathML test to check the default font-family on the <math> root.

w3c/mathml#37

* Check that non-inherited is math
@fred-wang fred-wang removed the need tests Issues related to writing WPT tests label May 27, 2020
@fred-wang
Copy link
Author

test added so closing

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jun 1, 2020
…t-family on the <math> root., a=testonly

Automatic update from web-platform-tests
Add MathML test to check the default font-family on the <math> root. (#23786)

* Add MathML test to check the default font-family on the <math> root.

w3c/mathml#37

* Check that non-inherited is math
--

wpt-commits: 4d53adfdfb1d6298ac51c6db31256c0c3562659e
wpt-pr: 23786
xeonchen pushed a commit to xeonchen/gecko that referenced this issue Jun 2, 2020
…t-family on the <math> root., a=testonly

Automatic update from web-platform-tests
Add MathML test to check the default font-family on the <math> root. (#23786)

* Add MathML test to check the default font-family on the <math> root.

w3c/mathml#37

* Check that non-inherited is math
--

wpt-commits: 4d53adfdfb1d6298ac51c6db31256c0c3562659e
wpt-pr: 23786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css / html5 Issues related to CSS or HTML5 interoperability MathML Core Issues affecting the MathML Core specification
Projects
None yet
Development

No branches or pull requests

4 participants