Page MenuHomePhabricator

Italic for math formulas not working if anchor tag is in MathML
Closed, ResolvedPublic

Description

There is a rendering issue in Firefox when a MathML, ex,<mi> element contains an <a> tag around plain text. In this case, the italic style applied to <mi> is lost.

Steps to reproduce:

  1. Add a formula using MathML with an <a> tag inside the <mi> element (add qid to formula). Example from https://w.wiki/d7M:
<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><a href="https://en.wikipedia.org/wiki/Energy" title="energy">E</a></mi>
      <mo stretchy="false">=</mo>
      <mi><a href="https://en.wikipedia.org/wiki/Mass" title="mass">m</a></mi>
      <msup>
        <mi><a href="https://en.wikipedia.org/wiki/Speed_of_light" title="speed of light in vacuum">c</a></mi>
        <mrow data-mjx-texclass="ORD"><mn>2</mn></mrow>
      </msup>
    </mstyle>
  </mrow>
</math>
  1. View page in Firefox.

Expected behavior:
Variables (E, m, c) are italicized as per mathematical convention.

Screenshot From 2025-08-20 02-38-20.png (51×127 px, 2 KB)

Actual behavior:
When <a> is inside <mi>, Firefox displays the characters in upright font instead of italic.

Screenshot From 2025-08-20 02-38-52.png (47×131 px, 2 KB)

Proposed fix:
Instead of putting <a> inside <mi>, wrap <a> around <mi> so that the MathML element styling is preserved.
Desired output example:

<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">
      <a href="https://en.wikipedia.org/wiki/Energy" title="energy"><mi>E</mi></a>
      <mo stretchy="false">=</mo>
      <a href="https://en.wikipedia.org/wiki/Mass" title="mass"><mi>m</mi></a>
      <msup>
        <a href="https://en.wikipedia.org/wiki/Speed_of_light" title="speed of light in vacuum"><mi>c</mi></a>
        <mrow data-mjx-texclass="ORD"><mn>2</mn></mrow>
      </msup>
    </mstyle>
  </mrow>
</math>

Environment:

  • Browser: Firefox (all recent versions)
  • This works correctly in Chrome (italics preserved), so this is Firefox-specific behavior.

Notes:

  • MathJax will need a small modification in its link-generation step.