Page MenuHomePhabricator

Native MathMl: Space before and after the | character is too big
Open, Needs TriagePublic

Assigned To
None
Authored By
Christian1985
May 29 2025, 4:23 PM
Referenced Files
F65742042: Screenshot 2025-08-12 at 17.20.05.png
Aug 12 2025, 3:21 PM
F65741881: Screenshot 2025-08-12 at 16.31.36.png
Aug 12 2025, 2:42 PM
F65741872: Screenshot 2025-08-12 at 16.40.49.png
Aug 12 2025, 2:41 PM
F65741809: Screenshot 2025-08-12 at 16.26.47.png
Aug 12 2025, 2:41 PM
F65741783: Screenshot 2025-08-12 at 16.22.58.png
Aug 12 2025, 2:41 PM
F60811035: image.png
May 29 2025, 4:23 PM

Description

I use Ubuntu 24.04 and Chrome.

In the formula
:<math forcemathmode="native">\max_{|z| \le 1}( |P'(z)| ) \le n\cdot\max_{|z| \le 1}( |P(z)| )</math>
rendert with MathMl, the spacing before and after the | character is much too large.

image.png (269×744 px, 39 KB)

Event Timeline

A minimal example is <math>n=|C|</math>. There is too much space in the Firefox rendering after the first vertical bar. This can be fixed by wrapping the expression |C| inside a mrow element like https://temml.org/ does.

@Dexxor

Thanks for the minimal example. That helps a lot.

I tried that on temml.org. I see the following MathML output

<math display="block" class="tml-display"><mrow><mi>n</mi><mo>=</mo><mi>|</mi><mi>C</mi><mi>|</mi></mrow></math>

Screenshot 2025-08-12 at 16.22.58.png (394×833 px, 28 KB)

In production I see

<math xmlns="http://www.w3.org/1998/Math/MathML" class="mwe-math-element mwe-math-element-inline"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mi>n</mi><mo stretchy="false">=</mo><mo stretchy="false">|</mo><mi>C</mi><mo stretchy="false">|</mo></mstyle></mrow></math>

looking like

Screenshot 2025-08-12 at 16.26.47.png (394×833 px, 80 KB)

So I think it is either the stretchyness or the mi vs mo question. I would guess it should be mo.

For the reference LaTeXML generates mo

<math id="p1.1.m1.1" class="ltx_Math" alttext="n=|C|\@add@PDF@RDFa@triples\par" display="inline"><semantics id="p1.1.m1.1a"><mrow id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml"><mi id="p1.1.m1.1.2.2" xref="p1.1.m1.1.2.2.cmml">n</mi><mo id="p1.1.m1.1.2.1" xref="p1.1.m1.1.2.1.cmml">=</mo><mrow id="p1.1.m1.1.2.3.2" xref="p1.1.m1.1.2.3.1.cmml"><mo stretchy="false" id="p1.1.m1.1.2.3.2.1" xref="p1.1.m1.1.2.3.1.1.cmml">|</mo><mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">C</mi><mo stretchy="false" id="p1.1.m1.1.2.3.2.2" xref="p1.1.m1.1.2.3.1.1.cmml">|</mo></mrow></mrow><annotation-xml encoding="MathML-Content" id="p1.1.m1.1b"><apply id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"><eq id="p1.1.m1.1.2.1.cmml" xref="p1.1.m1.1.2.1"></eq><ci id="p1.1.m1.1.2.2.cmml" xref="p1.1.m1.1.2.2">𝑛</ci><apply id="p1.1.m1.1.2.3.1.cmml" xref="p1.1.m1.1.2.3.2"><abs id="p1.1.m1.1.2.3.1.1.cmml" xref="p1.1.m1.1.2.3.2.1"></abs><ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">𝐶</ci></apply></apply></annotation-xml><annotation encoding="application/x-tex" id="p1.1.m1.1c">n=|C|\@add@PDF@RDFa@triples\par</annotation><annotation encoding="application/x-llamapun" id="p1.1.m1.1d">italic_n = | italic_C |</annotation></semantics></math>

Screenshot 2025-08-12 at 16.31.36.png (394×833 px, 54 KB)

and so does mathoid

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block" alttext="n=|C|">
  <semantics>
    <mrow>
      <mi>n</mi>
      <mo>=</mo>
      <mrow class="MJX-TeXAtom-ORD">
        <mo stretchy="false">|</mo>
      </mrow>
      <mi>C</mi>
      <mrow class="MJX-TeXAtom-ORD">
        <mo stretchy="false">|</mo>
      </mrow>
    </mrow>
    <annotation encoding="application/x-tex">n=|C|</annotation>
  </semantics>
</math>

Screenshot 2025-08-12 at 16.40.49.png (641×458 px, 46 KB)

It seems adding the mrow (which temml does not do) solves the problem. See https://codepen.io/physikerwelt/pen/azvLemO

<math>
  <mi>n</mi>
  <mo>=</mo>
  <mrow>
    <mo>|</mo>
    <mi>C</mi>
    <mo>|</mo>
  </mrow>
</math>

The question is, how to infer from the grammar that an mrow should be used here. The parse tree of n=|C| is just a sequence of flat literals

./bin/texvcjs 'n=|C|' -c --info
[[1,"n"],[1,"="],[1,"|"],[1,"C"],[1,"|"]]

The goal is to render $n=|C|$ exactly as $n={|C|}$ (second example in the screenshot below)

Screenshot 2025-08-12 at 17.20.05.png (347×695 px, 71 KB)

./bin/texvcjs 'n={|C|}'  --info -o tree -c
[[1,["n"]],[1,["="]],[13,[[1,["|"]],[1,["C"]],[1,["|"]]]]]