Page MenuHomePhabricator

Extra space after equations in MathML mode.
Closed, ResolvedPublic

Description

The MathML rendering mode in firefox seems to add a bit of extra space after the equation. If you add an inline equation like "<math>x^2</math>, " with a comma immediately after it you find there is noticable whitespace just before the comma. This occurs even with simple variables "<math>y</math>, ".

Event Timeline

SalixAlba raised the priority of this task from to Needs Triage.
SalixAlba updated the task description. (Show Details)
SalixAlba added a project: Math.
SalixAlba subscribed.
fredw added a subscriber: Physikerwelt.
fredw subscribed.

Moritz: I think I already reported this bug in the past. IIRC, it was due to the fact that mathoid puts space in the source code around the math output...

DOM in Firefox:

The formula, <span><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML">
  <semantics>
    <mrow class="MJX-TeXAtom-ORD">
      <mstyle displaystyle="true" scriptlevel="0">
        <mi>E</mi>
        <mo>=</mo>
        <mi>m</mi>
        <msup>
          <mi>c</mi>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>2</mn>
          </mrow>
        </msup>
      </mstyle>
    </mrow>
    <annotation encoding="application/x-tex">{\displaystyle E=mc^{2}}</annotation>
  </semantics>
</math></span>
<meta class="mwe-math-fallback-image-inline" aria-hidden="true" style="background-image: url('https://www.mediawiki.org/api/rest_v1/media/math/render/svg/9f73dbd37a0cac34406ee89057fa1b36a1e6a18e'); background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.338ex;height: 2.676ex; width: 9.025ex;"></span>, is valid.

Somehow, the outer span is wider than the inner ones (although there are no interesting styles set according to the Firefox style inspector. The fallback image is not at fault, you can safely delete it from the DOM and the spacing effect still occurs. If we modify the DOM a little bit, it works:

The formula, <span><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML">
  <semantics>
    <mrow class="MJX-TeXAtom-ORD">
      <mstyle displaystyle="true" scriptlevel="0">
        <mi>E</mi>
        <mo>=</mo>
        <mi>m</mi>
        <msup>
          <mi>c</mi>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>2</mn>
          </mrow>
        </msup>
      </mstyle>
    </mrow>
    <annotation encoding="application/x-tex">{\displaystyle E=mc^{2}}</annotation>
  </semantics>
</math></span>, is valid.
<meta class="mwe-math-fallback-image-inline" aria-hidden="true" style="background-image: url('https://www.mediawiki.org/api/rest_v1/media/math/render/svg/9f73dbd37a0cac34406ee89057fa1b36a1e6a18e'); background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.338ex;height: 2.676ex; width: 9.025ex;"></span>

But inserting it after the fallback image does not work either:

<p>The formula, <span><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML">
  <semantics>
    <mrow class="MJX-TeXAtom-ORD">
      <mstyle displaystyle="true" scriptlevel="0">
        <mi>E</mi>
        <mo>=</mo>
        <mi>m</mi>
        <msup>
          <mi>c</mi>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>2</mn>
          </mrow>
        </msup>
      </mstyle>
    </mrow>
    <annotation encoding="application/x-tex">{\displaystyle E=mc^{2}}</annotation>
  </semantics>
</math></span>
<meta class="mwe-math-fallback-image-inline" aria-hidden="true" style="background-image: url('https://www.mediawiki.org/api/rest_v1/media/math/render/svg/9f73dbd37a0cac34406ee89057fa1b36a1e6a18e'); background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.338ex;height: 2.676ex; width: 9.025ex;">, is valid.</span></p>

Okay, apparently the line break before the fallback image is the reason for the space. This works:

The formula, <span><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML">
  <semantics>
    <mrow class="MJX-TeXAtom-ORD">
      <mstyle displaystyle="true" scriptlevel="0">
        <mi>E</mi>
        <mo>=</mo>
        <mi>m</mi>
        <msup>
          <mi>c</mi>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>2</mn>
          </mrow>
        </msup>
      </mstyle>
    </mrow>
    <annotation encoding="application/x-tex">{\displaystyle E=mc^{2}}</annotation>
  </semantics>
</math></span><meta class="mwe-math-fallback-image-inline" aria-hidden="true" style="background-image: url('https://www.mediawiki.org/api/rest_v1/media/math/render/svg/9f73dbd37a0cac34406ee89057fa1b36a1e6a18e'); background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.338ex;height: 2.676ex; width: 9.025ex;"></span>, is valid.

And this is also the DOM in my local Wikimedia instance. So the linebreak is only at https://www.mediawiki.org/wiki/User:Physikerwelt, but not on my dev environment.

Yes. The explicit linebreak has been removed more than a year ago.
https://gerrit.wikimedia.org/r/#/c/170644/1/MathMathML.php
I wonder which component causes that the space is reintroduced.

@Tobi_WMDE_SW why was the project TCB-Team-Sprint-2016-03-02 removed?

We did not plan to work on this in the next sprint that started today. Do you think there is still anything we can help you with?

@Tobi_WMDE_SW Yes defenetely. We found that this problem does not occour in development environments but in production. So unless we can identify which component that is avilible in production but not in the development environment is responsible for the problem, it's unlikely that any progress can be made with this task.

@Physikerwelt so the problem is introduced by some other component and it is not an issue with the math extension, right? Which development for the math extension is this issue exactly blocking at the moment? I see no other blocked task except T126636.

@Tobi_WMDE_SW this task is not actively blocking developments, but it's annoying users in production. That's the reason why I really want to get this fixed as soon as possible.

Physikerwelt changed the task status from Open to Stalled.Apr 7 2016, 2:23 PM
Physikerwelt claimed this task.

This is now fixed. Where and why it's fixed is unknown.
cf. https://www.mediawiki.org/wiki/User:Physikerwelt