# Description

MathJax has started centering displayed equations. For example
https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Mathematics&curid=148395&diff=594391082&oldid=594388357
the display equation is centered. Previously they were aligned left.

Looking at the generated the code we see
<div class="MathJax_Display" role="textbox" aria-readonly="true" style="text-align: center;">

<span class="MathJax" id="MathJax-Element-2-Frame" style=""> ...
</span>

</div>

the centering is in the code rather than in a style sheet.

Aligning equations to the left is the desirable format.

Version: unspecified
Severity: normal

# Details

Reference
bz61051

### Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:07 AM
bzimport set Reference to bz61051.
bzimport added a subscriber: Unknown Object (MLST).
SalixAlba created this task.Feb 7 2014, 7:34 PM
• Bug 61139 has been marked as a duplicate of this bug. ***
Pkra added a comment.Feb 10 2014, 6:03 PM

This is caused by a custom MathJax extension used in the MediaWiki Math Extension, wiki2jax, https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FMath/ff83048597fb256c2579f16ddcd982ef2ae75460/modules%2FMathJax%2Funpacked%2Fextensions%2Fwiki2jax.js. That custom extension contains a simple heuristic (part of the ConvertMath function) to identify display style equations.

Aligning equations to the left is the desirable format.

IIUC that's simply due to the :$...$ hack which the community adopted because the math extension lacks support for display style -- see https://bugzilla.wikimedia.org/show_bug.cgi?id=12223. Traditionally, display-style math layout is centered.

I think you opened a discussion about community preference on the WikiProject Math page, too. So perhaps it's best to wait until there's a more definitive response.

Physikerwelt will correct me, but once Math extension 2.0 is ready, the heuristic would also apply to the default image rendering.

Peter.

physik wrote:

No Math 2.0 will have a selector to switch the style.

Currently the situation is as follows:
The PNG mode creates a new latex document for each equation and puts $$followed by the secured user input followed by$$ into the document body. The resulting dvi image is cropped to that the equation that was rendered centered on a page generated by latex is no longer centered. So it's not centered displaystyle.

The default for Math2.0 intends to keep this layout, but also offers to alternatives "displaystyle" which centers equations and "inline" which uses the inline mode (so the layout fit's into the text).

To convert the old math elements one could write a bot that transforms
:$to math elements with the displaystyle property. Another bot could search for html math and convert it back to math tags. I would prefer to keep that two phase approach. If this option is merged mathjax will behave like all other rendering modes. (Frédéric an me tested that.) So the centered equation in MathJax are a bug in the middle of changing from version 1.1 to version 2.0 physik wrote: Of course I would really get some feedback about this problem from the community... Chaning the code is easy... but getting feedback or codereview is realy hard. I've just open an RFC on the question of should display equations to be centered? As this affects multiple wiki's is is open to users from all projects. https://en.wikipedia.org/wiki/Wikipedia_talk:WikiProject_Mathematics#Should_display_equations_be_centered.3F anmichvon-wikipedia wrote: One possible workarround is appending &nbsp; behind the equitation. :[itex]...$ &nbsp; <!-- hard blank works around bug 61051 -->

But who removes the garbage, when 61051 is fixed?

So what about a template that just delivers the hard space and can be cleanly deployed and removed by bots?

:$...$ {{Bugfix-61051|Don't touch, will be removed automatically if and when...}}

Possible Contras:

• Deployment by bot would produce many instances that could affect the servers load.
• Bug will be fixed in short time, so don't mess around that much. It just isn't worth the effort.
• Might collide with other bot jobs involved in the migration from version 1.1 to version 2.0.

Pros:

• Workable plan to resolve the situation.
• No garbage left over after jobs are done, if properly in concert with other operations of the migration.

User:Pyrometer (Home-Wiki: de.wikipedia.org)

An alternative temporary workaround would be to add the CSS rule somewhere in the global site wide CSS or a users common.css

.MathJax_Display { text-align : left !important; }

this would align all display equations to the left without having to change any wikitext. This would eliminate the problems in comment 6 but does require a friendly admin.

physik wrote:

oups... I don't like that workaround at all.
I think I'll force mathjax to render everything on the left side for now.

physik wrote:

mh... bad news. I can not reproduce the problem locally.
If I copy the example
"I use MathJax, so my view may not be typical, but there could be a problem here.
:$a R b \and b R c \rightarrow a R c$
Yep, it's a problem here, also."
from the page I get
"<dl>
<dd><span class="MathJax_Preview"></span><span style="" aria-readonly="true" role="textbox" id="MathJax-Element-1-Frame" ..."
even though I was using action=purge&debug=true

DOn't know if this helps but a simple example using the MathJax content delivery network creates centered equations.

<script type="text/javascript"

src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">

</script>

<script type="text/javascript">
MathJax.Hub.Config({

		jax : [ "input/TeX", "output/HTML-CSS" ],
extensions : [ "tex2jax.js" ],
"HTML-CSS" : {
scale : 150
},
tex2jax : {
inlineMath : [ [ '$', '$' ], [ '\$$', '\$$' ] ]
}

});
</script>
<body>
<dl>
<dt>
$$1 + 2 + 3 + \dots = -{1 \over 12}.$$
</dt>
</dl>
</body>
</html>

The bit which sets up the centering is in
https://github.com/mathjax/MathJax/blob/master/jax/output/HTML-CSS/config.js

physik wrote:

Hi Richard Morris,

I'm trying to reproduce it the well defined Vagrant development environment as described here. That I set up as described here.
http://www.formulasearchengine.com/sites/formulasearchengine.com/files/How%20to%20review%20the%20math%20extension_0.pdf

Did anyone manage to reproduce the problem with vagrant?
It would be very interesting how the production environment differs from vagrant with regard to MathJax. I was thinking that the problem might be related to my browser cache... but I can see the problem at enwiki
Best
Physikerwelt

physik wrote:

Are there special system stylesheets that are loaded that do not belong to the default mediawiki schema?

Pkra added a comment.Feb 13 2014, 9:26 PM

@Physikerwelt why don't you just disable the heuristic? Or as a compromise, instead of making the equation display-style, make it inline but add \displaystyle to it to get display-style layout.

Whatever comes out of the RFC could inform Math 2.0 for how to implement real display math.

Just seen there is a related thread on the MathJax mailing list

https://groups.google.com/forum/#!topic/mathjax-users/JwE_lr-HtpQ

Looks like there is a

displayAlign: "center"

parameter you can set in the hub see

http://docs.mathjax.org/en/latest/options/hub.html

Things get a bit tricky if we want to allow both left aligned and center aligned equations.

Hello,

Thank you for all the work. I just want to say the consensus in the math editor community is to stop centering the equations. So, if possible, you can start fixing this bug.

physik wrote:

For me it looks as I could simply merge my patch that I have already implemented.
However, I'd like to wait until https://bugzilla.wikimedia.org/show_bug.cgi?id=61006 is merged. Just to be sure, that noting breaks.

Fix MathJax centers equations

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

physik wrote:

https://gerrit.wikimedia.org/r/119010 should fix the problem
now someone has to do the code review.

mal.malego wrote:

So far I have ignored all these bug reports, and it seems for good. It is funny how much I am blamed here for all these bugs while clearly my code has had it right from the very start. The heuristic is not about selecting centered or left-aligned maths, it is about deciding the way big operators are rendered. From the very first day my script had included as part of the MathJax config environment
displayAlign: "left"
It seems that all my work was in vain, as if it hadn't existed at all. Sigh, I shall not read any of these comments.

fredw added a comment.Apr 6 2014, 5:46 PM

(In reply to nageh from comment #19)

So far I have ignored all these bug reports, and it seems for good. It is
funny how much I am blamed here for all these bugs while clearly my code has
had it right from the very start. The heuristic is not about selecting
centered or left-aligned maths, it is about deciding the way big operators
are rendered. From the very first day my script had included as part of the
MathJax config environment
displayAlign: "left"
It seems that all my work was in vain, as if it hadn't existed at all. Sigh,

I'm not sure where you see that you are blamed. I think everybody recognize your efforts with client-side MathJax on MediaWiki. But if the MathJax option has never been enabled by default, there are good reasons (e.g. performance just to mention one of them). So Moritz has done an awesome work to implement server-side conversion, improves the texvc situation and more. Unfortunately, this is a big and complicate change and review has been slow. The goal is to have the traditional inline mode / display mode that we find in math documents and the default/current MediaWiki rendering "inline displaystyle". This handles whether the equation is centered or not and whether the displaystyle is used or not. Moritz has done several versions and branches to try to get the patch accepted and things may have been broken in the battle. Again, I don't think anyone blamed you. I'm sorry to see that you take that personally, instead of encouraging Moritz (and others)'s effort.

mal.malego wrote:

Ha. I do get a bit sensible when I see things being discussed that have long been addressed in my code as if I hadn't done any work on it at all, and when I see comments in the git repository that seem to imply that problems were due to bugs in my code.
As far as Moritz's efforts are concerned, I'm not exactly familiar with his works but I wish him well and encourage him.
Peace out.

mal.malego wrote:

And I still don't understand why the "heuristic is unwanted by the community" according to the comment in the source file. I thought this was only about that display equations should be left-aligned (which they always were in my code)?

fredw added a comment.Apr 6 2014, 7:33 PM

(In reply to nageh from comment #22)

And I still don't understand why the "heuristic is unwanted by the
community" according to the comment in the source file. I thought this was
only about that display equations should be left-aligned (which they always
were in my code)?

At some point some changes caused the heuristic to force the equation to be centered (probably because we removed displayAlign: "left" too early in the development) so that's probably what Moritz meant by "unwanted by the community". I think you should not pay too much attention to this comment (actually I believe it should be removed, it's not really useful to have it). The plan to add an explicit display attribute is exactly to avoid this kind of unexpected behaviors and inconsistencies between MathJax/mathoid/LaTeXML/texvc...

fredw added a comment.Apr 6 2014, 7:49 PM

So to be more accurate, I believe the real issue is that the heuristic forced MathJax's "display mode". But because this "display mode" does not exist (yet) in MediaWiki, Nageh added this displayAlign: "left" config to get MediaWiki's default mode.

Moritz's plan was to generalize the math modes to have, inline/display (the classical modes line in MathJax, TeX, MathML etc) and "inline displaystyle" (MediaWiki's default). In his branch, the displayAlign: "left" was removed because the display and centering/displaystyle stuff is done elsewhere in MediaWiki. However, because it was hard to get review, he only merged changes step-by-step and unfortunately displayAlign: "left" was removed before the whole math modes are ready... So actually the only thing necessary for 119010 was to keep this heuristic and add this config option back.

But as Moritz said on the entry, he is willing to make progress on the new modes and get his work merged, not only to fix bugs. Hopefully, we will recover the desired rendering soon.

Just to add a further complication.

Bug 37938 is about support for definition lists in VE. As you all know Wikitext plays fast and loose with these transforming : into <dd>. VE being pretty strict with its html does not play nicely with these. I recently found a tricky bug where its difficult to add text after a maths equation

Quite what VE's long term plan for using : as indentation I'm not quite so sure on.

As to "heuristic is unwanted by the community". I think this refers to poll at
https://en.wikipedia.org/wiki/Wikipedia_talk:WikiProject_Mathematics#Should_display_equations_be_centered.3F
which was closed at "Consensus is overwhelmingly in favour of left alignment.". The heuristic was mentioned a little in the discussion. I don't think many really understood what heuristic was about so we can't really conclude what the community thinks of the idea.

Change 119010 merged by TheDJ:
Fix MathJax centers equations

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

mal.malego wrote:

See, this is what sets me up. "It's a heuristic written specifically for MediaWiki's math extension." Bullshit! The heuristic was written specifically for my mathJax user script to cleverly tell apart inline math (where indices of large operators are ordered horizontally) from display math (where indices are stacked). This was actually all explained in bug 35188. And display math has always been left-aligned with my script.

fredw added a comment.Apr 7 2014, 10:08 AM

(In reply to nageh from comment #27)

See, this is what sets me up. "It's a heuristic written specifically for
MediaWiki's math extension." Bullshit! The heuristic was written
specifically for my mathJax user script to cleverly tell apart inline math
(where indices of large operators are ordered horizontally) from display
math (where indices are stacked). This was actually all explained in bug

1. And display math has always been left-aligned with my script.

Nageh: I'm not sure what is your intention, but your complaints do not sound very constructive. The comment you state seems to be from Peter Krautzberger so you should ask him directly. But in my opinion, he is just saying that this heuristic is not part of the MathJax code and didn't mean to accuse you of anything. Honestly, I really don't understand why you are getting nervous for that.

physik wrote:

nageh: Form a client-side perspective this approach is perfectly fine. However, after discussions wiht Gabriel, I'm convinced that there are good (technical) reasons that tag extension should be functionally dependend from their input and not from their context.
On the other hand this means that the math extension can not decide if the input was :<math or just <math because the : context is hidden.
The only workable solution is to add an aditional parameter to the math tag.

physik wrote:

I could not find any centered equations anymore. Please reopen in case I missed something.