mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.18k stars 1.16k forks source link

Psuedoscript and degree #2791

Open NSoiffer opened 3 years ago

NSoiffer commented 3 years ago

Issue Summary

The MathML spec lists a number of pseudoscript chars. Among them is #B0 (degree sign). The spec says the proper markup is to put the degree sign in a superscript, but that looks poor in MathJax. See screenshot below.

This looks related to #2716, but I didn't see this particular example.

This seems basic enough that it would have been reported earlier; apologies if I am missing something obvious. If I use prime (2032) instead, it behaves as expected.

Steps to Reproduce:

  1. https://mathjax.github.io/MathJax-demos-web/input-mml2chtml.html
  2. Input:
    <math>
    <mi>cos</mi><msup><mn>30</mn><mo>&#xB0;</mo></msup>
    <mi>cos</mi><mn>30</mn><mo>&#xB0;</mo>
    </math>
  3. Output: image

It's nice that the second form looks good, but the first form (which is recommended in the spec) should look good also.

Note:

<math>
<mi>cos</mi><msup><mn>30</mn><mo>&#x2032;</mo></msup>
<mi>cos</mi><mn>30</mn><mo>&#x2032;</mo>
</math>

displays as image which is what I expect.

Version Info

dpvc commented 3 years ago

MathJax's fonts don't include a large, un-raised version of U+00B0, which is what would be needed to render that character as a proper superscript (just as it doesn't have the smaller raised prime needed to render it in the un-superscripted position). In fact, the MathJax fonts tend not to have the needed characters for many of the pseudo-scripts listed in the MathML spec. The infrastructure is in place to allow rendering of both msup-based and non-msup versions, but the proper characters currently aren't available. They are available in some other fonts, like STIX2, and so when the next release comes out that will include those fonts, that can be addressed. (The font release has been delayed due to both lack of funds, and personal circumstances on my part, but work is nearly complete on SVG versions of the fonts.)

NSoiffer commented 3 years ago

One of the points for that section the MathML spec was to standardize the display of the characters so that changing fonts doesn't end up with wildly different display behavior. I looked at Asana, Cambria, and STIX2 and they all have the degree symbol the same size but differ on the prime. I think that @davidcarlisle was involved in the writing of that section, so I'm referencing him in case he wants to chime in.

One of the points of the section is that you want to use one of those characters in an msubsup, they need to display properly in msup. Take a look at

<math>
<msubsup><mi>x</mi><mn>1</mn><mo>′</mo></msubsup>
<msubsup><mi>x</mi><mn>1</mn><mo>&#xB0;</mo></msubsup>
<msubsup><mi>x</mi><mn>1</mn><mo scriptlevel="0">&#xB0;</mo></msubsup>
</math>

which displays as image

I added the scriptlevel="0" example to show that trying to do that does not solve the problem. There may be some hack besides mpadded to make it look right, but that eludes me at the moment. In any case, it shouldn't requiring hacks to get

I suspect it may be hard, but I think the ideal thing would be for MathJax to look at the pseudo-script to display and see whether it is already shrunk and adjust the display appropriately.

NSoiffer commented 3 years ago

David Carlisle pointed out that the MathML spec does say these chars need special handling:

Note this means that a renderer of MathML will have to treat pseudo-scripts differently from most other character codes it finds in a superscript position; in most fonts, the glyphs for pseudo-scripts are already shrunk and raised from the baseline.

If you feel the spec should be changed, please comment on: https://github.com/w3c/mathml/issues/251

dpvc commented 2 years ago

One of the points of the section is that you want to use one of those characters in an msubsup, they need to display properly in msup

Oh, I understand the point of the section, and as I've already mentioned, the infrastructure is in place to do that. The problem isn't in the understanding of how it is supposed to work, it is in not having the needed glyphs in the fonts that MathJax is using. That should be addressed when I get the font update finished (I had hoped to have it before the fall classes started, but didn't make it). MathJax needs to have the glyph in both its smaller-and-raised position (for use outside of msubsup and msup) and in a larger-unraised position (for use in msubsup and msup). One or the other is missing from the MathJax fonts for most pseudo-scripts. The fact that these characters are in other fonts that MathJax isn't currently using doesn't really matter.

I think the ideal thing would be for MathJax to look at the pseudo-script to display and see whether it is already shrunk and adjust the display appropriately.

I don't think that is going to be a viable strategy, and is likely to be pretty fragile.

David Carlisle pointed out that the MathML spec does say these chars need special handling

Indeed, that was clear from the beginning, and what I said we are already prepared for, once the fonts are updated. MathJax will pick which variant to use (large or small) for the situation where it is used.

jmitsdarfer commented 2 years ago

@dpvc I recently happened to come across this discussion. I'm just wondering if, once the fonts are updated, would that be available in v2 and v3 or only v3? Thank you.

dpvc commented 2 years ago

This will likely be v3 only. While v2 is continuing to be maintained in terms of bug fixes, it is not likely to be getting new features at this point.