ronkok / Temml

TeX-to-MathML conversion library in JavaScript
https://temml.org/
MIT License
162 stars 12 forks source link

`\bigcap` vertical misalign in display="block" in "STIX TWO" font in Chrome #66

Closed hbghlyj closed 2 months ago

hbghlyj commented 6 months ago

MathML generated by Temml:

<math display="block" class="tml-display" style="display:block math;">
  <mrow>
    <mi>x</mi>
    <mo>∈</mo>
    <mrow>
      <munderover>
        <mo movablelimits="false">⋂</mo>
        <mrow>
          <mi>m</mi>
          <mo>=</mo>
          <mn>1</mn>
        </mrow>
        <mi>∞</mi>
      </munderover>
    </mrow>
    <msub>
      <mi>K</mi>
      <mi>m</mi>
    </msub>
  </mrow>
</math>

in Latin Modern: image in STIX TWO: image

Tested in: Chrome Version 125.0.6422.77 (Official Build) (64-bit) and Chrome Version 125.0.6422.113 (Official Build) (64-bit)


in Firefox it is properly aligned

image

ronkok commented 5 months ago

Ignore this comment. It goes off on an irrelevant tangent. The true discussion starts in the next comment.

MathML-Core specifies CSS rules in several instances where MathML 3.0 specifies attributes. The browsers are currently in an incomplete state of transition from MathML 3.0 to MathML-Core. Temml tries to get good rendering in all three of the major browser engines, so sometimes Temml writes both the old attribute and the new CSS.

In this case, Chromium only renders display mode correctly if CSS contains style="display: block math;". Chromium should then ignore the attribute, but as you have pointed out, it does not. When the attribute is not written, Chromium renders this example correctly.

I'll do some testing and see if the other browsers will render display mode correctly without that attribute. If so, I'll omit it and this issue will go away. If one of the other browsers still requires that attribute in order to render display mode, then I may not be able to help you.

ronkok commented 5 months ago

It turns out that the problem occurs within the STIX TWO font. The image below shows screenshots from two fonts, Latin Modern and STIX TWO. Both screenshots show the glyphs for Unicode U+22C2 and U+22C3. For each code point, there is a standard glyph and an alternate glyph. MathML uses the alternate glyph for displaystyle.

STIX Issue

As you can see, Latin Modern has defined the alternate glyph with the proper vertical alignment. There is a substantial depth (descender) below the baseline. In STIX TWO, the alternate glyph is placed entirely above the baseline.

I don't think there is much that Temml can do to work around this issue. I've opened an issue in the stixfonts repository. Unfortunately, I don't expect quick action on their part. Their last release was three years ago.

Personally, I ship the Latin Modern font. It gives me better rendering.

ronkok commented 5 months ago

I suppose I could write a class when Temml writes a big operator, then do some browser sniffing in the CSS file for STIX. I dislike that sort of thing, but it may be possible. I'll give it some thought for a day.

ronkok commented 2 months ago

Fixed by the workaround in release 0.10.29.