Page MenuHomePhabricator

\align aligns fields in the centre rather that on the left in MathML mode
Closed, ResolvedPublicBUG REPORT

Assigned To
Authored By
SalixAlba
Sep 21 2024, 1:53 AM
Referenced Files
F66007405: Screenshot 2025-09-11 at 08.50.35.png
Sep 11 2025, 6:53 AM
F65759217: image.png
Aug 16 2025, 11:38 AM
F65720080: Screenshot 2025-08-06 at 23.27.25.png
Aug 6 2025, 9:27 PM
F65720078: Screenshot 2025-08-06 at 23.26.29.png
Aug 6 2025, 9:27 PM
F65720075: Screenshot 2025-08-06 at 23.25.03.png
Aug 6 2025, 9:27 PM
F60773518: image.png
May 28 2025, 5:00 PM
F57608964: Screenshot 2024-10-13 at 00-00-58 localhost.png
Oct 12 2024, 10:01 PM
F57601835: image.png
Oct 9 2024, 7:36 PM

Description

Steps to replicate the issue (include links if applicable):

  • Set user preference to MathML mode
  • Enter the expression

<math display="block">\begin{align}
\frac{dy}{du} &= f'(u) = e^u, \\
\frac{du}{dv} &= g'(v) = \cos v, \\
\frac{dv}{dx} &= h'(x) = 2x.
\end{align}</math>

What happens?:
The second fields are centre aligned

image.png (253×330 px, 10 KB)

I've draw boxes around the content of the second field

What should have happened instead?:

The second fields are left aligned

image.png (317×388 px, 20 KB)

rendered using SVG mode

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Chrome 128

Event Timeline

In LaTeX should the align environment has an implicit {rlrl...} horizontal alignment. https://ctan.math.illinois.edu/obsolete/info/math/voss/mathmode/Mathmode.pdf (page 25)

We don't quite follow the latex spec as \begin{align} has should have equation numbers, our is more like \begin{align*} with no numbering.

First field are also center aligned rather than right aligned

image.png (235×491 px, 15 KB)

The same problem occurs with \begin{cases}

f(n) =
\begin{cases}
 n/2, & \text{if }n\text{ is even} \\
 3n+1, & \text{if }n\text{ is odd}
\end{cases}

image.png (114×397 px, 9 KB)

The conditions should be left alligned.

I had looked into the alignment problems before and it's relatively easy to adjust the output, cf. T350736 However, I don't fully understand what the desired MathML Layout is. One strategy is to copy the settings from the new arxiv HTML rendering, e.g, https://arxiv.org/html/2409.12006v1. Do you think it looks good there?

Also T352608 is related. I now updated https://www.w3.org/wiki/Math_Tools#Tools_for_MathML_Core to have a list of possible realizations in MathML.

For example http://fred-wang.github.io/TeXZilla/ generates for the cases example the follwing.

<mtable displaystyle="false" columnalign="left left">

We generate

<mtable columnspacing="1em" rowspacing="4pt">

I will start with generating the coumnalign attribute, maybe this solves most of the problems already.

Change #1074702 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Fix: Use align information in matrix constructs

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

Change #1074702 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Fix: Use align information in matrix constructs

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

Hum, things seem to have gone back again.

Current rendering from https://en.wikipedia.beta.wmflabs.org/wiki/T375317

image.png (408×546 px, 28 KB)

It would be good to check for more than 2 fields. Which should be aligned r-l-r-l etc.

https://www.latex-project.org/help/documentation/amsldoc.pdf page 7 has

\begin{align}
x&=y & X&=Y & a&=b+c\\
x’&=y’ & X’&=Y’ & a’&=b\\
x+x’&=y+y’ & X+X’&=Y+Y’ & a’b&=c’b
\end{align}

Rendered as

image.png (149×947 px, 22 KB)

Hum, things seem to have gone back again.

Current rendering from https://en.wikipedia.beta.wmflabs.org/wiki/T375317

I can not reproduce this.

It would be good to check for more than 2 fields. Which should be aligned r-l-r-l etc.

For that example, it would be columnalign="right left right left right left right left right left right left" and also important columnspacing="0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em" (taken from current svg rendering)

SalixAlba reopened this task as Open.EditedOct 9 2024, 7:21 PM

Still broken with chrome and edge, windows. Current rendering of
https://en.wikipedia.beta.wmflabs.org/wiki/T375317

image.png (484×662 px, 31 KB)

Also broken in Firefox with the first field, which should be right aligned.

<math forcemathmode="native">\begin{align}
 z & =  a \\
 f(x,y,z) & = x + y + z
\end{align}</math>

Rendered on beta as

image.png (101×365 px, 5 KB)

Rather than SVG

image.png (102×385 px, 7 KB)

I've added this to the end of https://en.wikipedia.beta.wmflabs.org/wiki/T375317

Still broken with chrome and edge, windows. Current rendering of
https://en.wikipedia.beta.wmflabs.org/wiki/T375317

image.png (484×662 px, 31 KB)

I think this is rather a new/independent bug.

Also broken in Firefox with the first field, which should be right aligned.

<math forcemathmode="native">\begin{align}
 z & =  a \\
 f(x,y,z) & = x + y + z
\end{align}</math>

Rendered on beta as

image.png (101×365 px, 5 KB)

Rather than SVG

image.png (102×385 px, 7 KB)

I've added this to the end of https://en.wikipedia.beta.wmflabs.org/wiki/T375317

I'll fix this.

There is a dedicated test, that wants the standard alignment to be left (T348791)

Change #1079626 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Use the same formatting for align as MathJax

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

Physikerwelt changed the task status from Open to In Progress.Oct 12 2024, 10:03 PM
Physikerwelt triaged this task as Medium priority.

Change #1079626 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Use the same formatting for align as MathJax

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

I believe it's related to https://issues.chromium.org/issues/40889720, in which Chrome doesn't support the columnalign attribute at all.

That seems good.

I'd like to check the case of multiple fields which for \begin{align} should be aligned right-left-right-left etc.

Change #1176552 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Use polyfill for columnalign

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

Change #1176552 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Use polyfill for columnalign

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

It looks good to me now on Firefox and Chrome on beta. However, MathJax does not seem to support CSS, so this has no alignment now.

Im not sure if the alignment in https://de.wikipedia.beta.wmcloud.org/wiki/Intbar#Algin should also be fixed. I think it is not fixed.

image.png (1×1 px, 206 KB)

I'm using Ubuntu 24.04 and Chrome.

Im not sure if the alignment in https://de.wikipedia.beta.wmcloud.org/wiki/Intbar#Algin should also be fixed. I think it is not fixed.

I think that might be a cache issue. I modified the equation to force the system to recalculate the expressions and thats fixed it.

I tried doing a purge with https://de.wikipedia.beta.wmcloud.org/w/index.php?title=Intbar&action=purge&mathpurge=true that normally fixes things but not here for some reason.

@Christian1985 that's how it looks to me in Chrome. Please reopen if that's incorrect or looks different to you.

Screenshot 2025-09-11 at 08.50.35.png (1×967 px, 168 KB)

I'm afraid that this might have broken alignment in MathJax, I'll double check and open a new ticket if my fear is justified.