MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Semantic enrichment adds unwanted `none` elements to `mmultiscript` containing `mtext`

Open dpvc opened this issue 3 months ago • 1 comments

The expression

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mmultiscripts>
    <mi>Cu</mi>
    <none></none>
    <mo>*</mo>
    <mprescripts></mprescripts>
    <none></none>
    <mrow>
      <mn>58</mn>
      <mtext>&#x2013;</mtext>
      <mn>61</mn>
    </mrow>
  </mmultiscripts>
</math>

gets turned into

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mmultiscripts>
    <mi>Cu</mi>
    <none></none>
    <mo>*</mo>
    <mprescripts></mprescripts>
    <none></none>
    <none></none>
    <none></none>
    <none></none>
    <mrow>
      <mn>58</mn>
      <mtext>&#x2013;</mtext>
      <mn>61</mn>
    </mrow>
    <none></none>
  </mmultiscripts>
</math>

(with the addition of four unneeded none elements, three before the mrow and one after it), turning the superscript into a subscript.

If the mtext element is changed to an mo, the problem doesn't occur.

This was reported in the MathJax User's Forum.

dpvc avatar Sep 08 '25 21:09 dpvc

The reason for the issue the treatment of multi-index elements with sequences of indices, e.g.,

<math>
<mmultiscripts><mi>A</mi><mn>11</mn><mn>2</mn><mn>3</mn><mn>44</mn><mprescripts/><mn>5</mn><mn>4</mn><mn>6</mn></mmultiscripts>
</math>

(note that github can't render that...)

In that case SRE works with an invisible separator element to separate indices. It also uses this separator to separate multiple text elements, that is where it got confused and started padding with none.

There is a two step solution to this:

  1. The initial solution is to disambiguate the separator element for multi-index structures to avoid confusion. That solves the bug.
  2. There is really no need to treat the dash here as text instead of punctuation. The complication is that punctuation is treated before text, relations and operators. But I am testing a possible solution.

zorkow avatar Sep 12 '25 10:09 zorkow