Page MenuHomePhabricator

Use mrow elements for linking instead of anchor tags
Open, Needs TriagePublic

Description

The current implementation uses anchor tags for linking in MathML. However, according to the W3C discussion, only mrow and anchor tags should use href attributes.
To address these issues, we need to make the following changes:

  1. Replace anchor tags with mrow elements.
  2. Modify the Popups integration to allow Popups on mrow elements with href attributes.
  3. Implement a polyfill to support href in MathML for Chrome, as it does not currently support this feature.
  4. Add MathJax support for Anchor Tags: MathJax by default pulls out href attributes of MathML elements and creates an anchor tag with that href, wrapping that mrow element. But it does not add the title attribute, and this breaks the Popups functionality.

Event Timeline

Change #1225176 had a related patch set uploaded (by FrederikHennecke1; author: FrederikHennecke1):

[mediawiki/extensions/Math@master] Use mrow elements for linking instead of anchor tags

https://gerrit.wikimedia.org/r/1225176

@FrederikHennecke1 do you think it is a bug in MathJax that the title is not used? If yes, we should file an issue here https://github.com/mathjax/mathjax/issues

@FrederikHennecke1 do you think it is a bug in MathJax that the title is not used? If yes, we should file an issue here https://github.com/mathjax/mathjax/issues

I do not think it is a bug. As far as I can see, they just move the href attribute out of the current element to an anchor tag and keep the rest of the element the same, like the texclass. We could also remove the mrow in case it only has the title attribute left, but I don't think the added code complexity is worth it.

@FrederikHennecke1 thank you! I just left a note to https://github.com/mathjax/MathJax/issues/3484#issuecomment-3740249528 as I wasn't expecting this and want to avoid surprises in the future.

Screenshot From 2026-01-17 02-15-54.png (54×79 px, 2 KB)

Top with anchor tags and bottom without:

<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>
<br>
<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>E</mi>
            <mo stretchy="false">=</mo>
                <mi>m</mi>
            <msup>
                    <mi>c</mi>
                <mrow data-mjx-texclass="ORD">
                    <mn>2</mn>
                </mrow>
            </msup>
        </mstyle>
    </mrow>
</math>

This is the rendering in Firefox. Chrome and Webkit look normal. But this issue is a bit wonky. I did screenshot it in my default Firefox browser(140.7.0esr ). This issue did not show up when I tried to compare it with BackstopJS so it may just be my local font.

In the MathWG we defined that it should be possible to replace all mrow with a and stop outputting mrow at all see
https://codepen.io/physikerwelt/pen/XJKMMyo

In the MathWG we defined that it should be possible to replace all mrow with a and stop outputting mrow at all see
https://codepen.io/physikerwelt/pen/XJKMMyo

This renders only correctly when using Chromium. I get the following with Firefox:

Screenshot From 2026-01-17 17-52-04.png (220×350 px, 15 KB)

Interesting, what Firefox version are you using?

Screenshot 2026-01-18 at 12.47.12.png (402×590 px, 30 KB)

(FF 147.0.1 (aarch64))

Firefox 140.7.0esr (64-bit) on Debian 13.

Firefox 140.7.0esr (64-bit) on Debian 13.

I just downloaded and tested the latest non-ESR version for Debian (147.0.1), and the rendering is fixed. Should we wait for the next big ESR release that fixes this problem before we finish this task?

Change #1225176 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Use mrow elements for linking instead of anchor tags

https://gerrit.wikimedia.org/r/1225176