Page MenuHomePhabricator

Too much space in alignat in MathML and Client side MathJax
Closed, ResolvedPublicBUG REPORT

Description

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

  • Set math format to MathML or Client side MathJax
  • Enter formula:
\begin{alignat}{3} f(a,b) & = (a+b)^2 && = (a+b)(a+b) \\ & = a^2+ab+ba+b^2 && = a^2+2ab+b^2 \\ \end{alignat}

What happens?:

Renders as

image.png (697×409 px, 44 KB)

What should have happened instead?:

image.png (689×158 px, 26 KB)

Note the excess space before the = signs.

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

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

Ecosia browser (chromium)

Details

Related Changes in Gerrit:

Event Timeline

Krinkle renamed this task from Too much space in alignat in MathMl and Client SVG to Too much space in alignat in MathML and Client side MathJax.Aug 19 2026, 6:34 PM
Krinkle triaged this task as Low priority.
Krinkle updated the task description. (Show Details)

@Jacobolus does what you see in your browser look very different to the above images? If so can you add a screenshot. I'm wondering if this is a Safari only bug.

The above images are basically what I see, The spacing is all messed up and looks awful. We get examples like:

Screenshot 2026-08-20 at 6.58.18 AM.png (1,454×500 px, 109 KB)

Where we are supposed to see something more like

Screenshot 2026-08-20 at 6.57.51 AM.png (1,448×516 px, 115 KB)

Or

{F99233626}

instead of

{F99233625}

Or (this one is with the \align environment)

{F99232887}

instead of

{F99232886}

Physikerwelt moved this task from Inbox to Ready to implement on the Math board.

The above images are basically what I see, The spacing is all messed up and looks awful. We get examples like:

Screenshot 2026-08-20 at 6.58.18 AM.png (1,454×500 px, 109 KB)

Where we are supposed to see something more like

Screenshot 2026-08-20 at 6.57.51 AM.png (1,448×516 px, 115 KB)

Thank you. This is a clear bug, which I can fix.

Unfortunately, I don't see the other screenshots.

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

[mediawiki/extensions/Math@master] Fix alignat syntax

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

@Jacobolus last four images are restricted for some reason.

The documentation at https://www.latex-project.org/help/documentation/amsldoc.pdf seems as clear as mud. This https://tex.stackexchange.com/questions/49014/aligning-equations-with-text-with-alignat post makes it a bit clearer

alignat doesn't add space between the columns;
the columns are as many rl pairs as specified by the argument.

So columns should be right aligned, left aligned, right aligned, left aligned, etc.

Currently in

\begin{alignat}{2} 
right & left & right & left \\ 
r & l & r & l 
\end{alignat}

Client side SVG and MathML render the 3rd and 4th columns centre aligned, when they should be right and left aligned.

image.png (452×682 px, 66 KB)

Also there seems to be space added if an operator comes after an &, and different spacing if its before an &. This video explains the expected behaviour.
https://youtu.be/m_jNKZH5-Ts?si=xxXR6_-zYlOgPTj8&t=231

Let me re-upload. I think maybe when I edit a comment the newly added images get blocked.


Here's the alignat example:

"Server-side SVG":

Screenshot 2026-08-20 at 7.16.34 AM.png (1,464×310 px, 118 KB)

"Client-side SVG":

Screenshot 2026-08-20 at 7.15.53 AM.png (1,646×362 px, 121 KB)

\begin{alignat}{9}
\frac{\pi}{2} ~&=~ \arcsin(x) &&+ \arccos(x) ~&&=~ \arctan(r) &&+ \arccot(r) ~&&=~ \arcsec(s) &&+ \arccsc(s) \\[0.4ex]
\pi ~&=~ \arccos(x) &&+ \arccos(-x) ~&&=~ \arccot(r) &&+ \arccot(-r) ~&&=~ \arcsec(s) &&+ \arcsec(-s) \\[0.4ex]
0 ~&=~ \arcsin(x) &&+ \arcsin(-x) ~&&=~ \arctan(r) &&+ \arctan(-r) ~&&=~ \arccsc(s) &&+ \arccsc(-s) \\[1.0ex]
\end{alignat}

Aside: If I were writing this, I wouldn't use the extra ~ spaces, and would probably do something like:

\begin{alignat}{6}
\frac{\pi}{2} &= \arcsin x &&+ \arccos x
  &&= \arctan r &&+ \arccot r
  &&= \arcsec s &&+ \arccsc s, \\[2pt]
\pi &= \arccos x &&+ \arccos(-x)
  &&= \arccot r &&+ \arccot(-r)
  &&= \arcsec s &&+ \arcsec(-s), \\[6pt]
0 &= \arcsin x &&+ \arcsin(-x)
  &&= \arctan r &&+ \arctan(-r)
  &&= \arccsc s &&+ \arccsc(-s).
\end{alignat}

Trying to even out the space between lines. But the renderer should match author intent, giving them the amount of horizontal and vertical space they ask for.


Here's the align example:

"Server-side SVG":

Screenshot 2026-08-20 at 7.02.48 AM.png (722×246 px, 45 KB)

"Client-side SVG"

Screenshot 2026-08-20 at 7.02.20 AM.png (690×252 px, 41 KB)

\begin{align}
F_0 &= 0,& F_1 &= 1,& F_{n+1} &= F_n + F_{n-1}, \\[3mu]
L_0 &= 2,& L_1 &= 1,& L_{n+1} &= L_n + L_{n-1}, \\[3mu]
\varphi^0 &= 1,
  & \varphi^1 &= \varphi,
  & \varphi^{n+1} &= \varphi^{n} + \varphi^{n-1}, \\[3mu]
\overline\varphi^0 &= 1,
  & \overline\varphi^1 &= \overline\varphi,
  & \overline\varphi^{n+1} &= \overline\varphi^{n} + \overline\varphi^{n-1}.
\end{align}

@Jacobolus last four images are restricted for some reason.

The documentation at https://www.latex-project.org/help/documentation/amsldoc.pdf seems as clear as mud. This https://tex.stackexchange.com/questions/49014/aligning-equations-with-text-with-alignat post makes it a bit clearer

Yes. For some reason, I only assigned half of the required rows.

Currently in

\begin{alignat}{2} 
right & left & right & left \\ 
r & l & r & l 
\end{alignat}

After the recently uploaded patch, this renders with native in FF as

Screenshot 2026-08-20 at 19.22.28.png (276×160 px, 8 KB)

is that the intended outcome?

In alignat (unlike align) there should not be extra space between pairs. In LaTeX running on my local computer, your example renders as:

Screenshot 2026-08-20 at 11.13.57 AM.png (334×164 px, 10 KB)

If you want a slightly trickier example, you can try something like:

\begin{alignat}{4} 
r_1 &= l_1 + 0 &&= l_1,\   & r_2 + 0\cdot 0 &> l_2 \\ 
R_1 &= L_1 &&= L_1,\   & R_2 &< L_2 \\ 
\text{(right)} & \text{(left)} && \text{(left)} & \text{(right)} & \text{(left)}
\end{alignat}

Which should render along the lines of:

Screenshot 2026-08-20 at 11.26.19 AM.png (602×218 px, 20 KB)

The "server-side SVG" mode does the right thing:

Screenshot 2026-08-20 at 11.29.45 AM.png (624×184 px, 34 KB)

The "client-side SVG" mode does not:

Screenshot 2026-08-20 at 11.30.27 AM.png (742×200 px, 34 KB)

Thank you, that is helpful. FYI, we looked into the MathJax source code when implementing the native rendering mode. However, to get rendering in Chrome (without SVG) as well, we needed to move some information into CSS. Some of this is now lost in the SVG T435274, and something was wrong in the first place.

Change #1327581 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Fix alignat syntax

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

Are there already bug reports/fixes for these other two align-related bugs. Both seem critical to me:

  1. extra vertical spacing instructions at line breaks do not behave as expected (e.g. \\[2pt], \\[3px], or \\[5mu]). I don't think Mediawiki's "server-side SVG" renderer is entirely consistent with LaTeX on which units to support in this context. The most backwards-compatible would be to precisely match the previous behavior. A plausible alternative might be to support whatever units LaTeX supports, and write a bot to change other units to pt across the site (maybe rounded to the nearest 0.1).
  1. A trailing line break (\\) at the end of an align/aligned environment needs to do nothing. Currently it renders unsightly additional vertical whitespace, which breaks layouts on many math articles on English Wikipedia.

See https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Mathematics/MathFormattingBugs for concrete examples of these issues.

Why is this marked "resolved"? The current state is still moderately broken.