w3c / mathml-core

MathML Core draft
https://w3c.github.io/mathml-core
36 stars 14 forks source link

Misaligned brackets #215

Open fkuehnel opened 8 months ago

fkuehnel commented 8 months ago

Still, there are some misalignments in rendering matrices and brackets, i.e.

https://www.wikiwand.com/en/Moore%E2%80%93Penrose_inverse

Screenshot 2024-01-21 at 10 09 23 PM
dginev commented 8 months ago

A quick diagnostic suggests this is (at least partially) connected to #103

  1. snippet reproducing the problem (in Chrome): https://codepen.io/dginev/pen/xxBreNE

  2. hand-typed snippet avoiding the problem: https://codepen.io/dginev/pen/qBvjwYN

The markup encountering the issue leverages the "sizing trick" of setting the same minsize and maxsize, with em units:

<mrow class="MJX-TeXAtom-ORD">
  <mrow class="MJX-TeXAtom-OPEN">
    <mo maxsize="2.470em" minsize="2.470em">(</mo>
  </mrow>
</mrow>
<!-- ... -->
<msup>
  <mrow class="MJX-TeXAtom-ORD">
    <mrow class="MJX-TeXAtom-CLOSE">
      <mo maxsize="2.470em" minsize="2.470em">)</mo>
    </mrow>
  </mrow>
  <mrow class="MJX-TeXAtom-ORD">
    <mo>+</mo>
  </mrow>
</msup>

The second potential problem is the parsing avenue which attaches the superscript of the entire expression only on the closing paren. Which I assume may be more fragile, compared to a wrapping mrow that contains the () delimiters as the first and last child.

But yes, I think this connects to the broader discussion of #103

dginev commented 4 months ago

The reported snippet appears to now work well with the latest Chrome. I checked with version 125.0.6422.76, with the previously mentioned codepen.

Is this good enough to close @fkuehnel ?

NSoiffer commented 4 months ago

Just confirming what @dginev wrote: I updated from 124.0.6367.208 to 125.0.6422.77 and the codepen display now looks good, whereas in the previous version it did not.

davidcarlisle commented 4 months ago

adding sub/super scripts to delimiters still mis-aligns though see for example

https://w3c.github.io/mathml-docs/intent-examples/#id-1-afbf0c9d54fa697fee15f8c64feda4b2

image

in chrome 125.0.6422.77 and

image

in firefox

dginev commented 4 months ago

adding sub/super scripts to delimiters still mis-aligns though see for example

https://w3c.github.io/mathml-docs/intent-examples/#id-1-afbf0c9d54fa697fee15f8c64feda4b2

image

I wonder if it would be better to open separate issues for each kind of technical misalignment.

I made 3 variations of this example in a new codepen here (tested with Chrome 125): https://codepen.io/dginev/pen/VwOjPzW

It looks like this is an issue encountered due to <mo> and <msubsup> being the paired fences, where only one of the two is handled with 3.4.1.4 Base with subscript and superscript.

If we instead lift the <msubsup> to wrap both fences (2nd example in codepen) or use <msubsup> for both left and right fence (3rd example in codepen), the alignment appears correct.

Edit: Added a 4th example to the codepen, with both <mo> elements set to stretchy="false". That also aligns correctly, (and leads to a slight variation in horizontal spacing between the fences).

NSoiffer commented 4 months ago

@davidcarlisle 's example is also bad in Chrome Canary 127.0.6494.0 (22/05/2024), so it does seem to be separate and not fixed.

fred-wang commented 4 months ago

adding sub/super scripts to delimiters still mis-aligns though see for example

https://github.com/w3c/mathml-core/issues/205#issuecomment-2039337765