Page MenuHomePhabricator

Sums and other large operators keep display style inside fractions and \sqrt (should use inline style)
Closed, ResolvedPublicBUG REPORT

Description

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

  • With Client side MathJax rendering:
<math forcemathmode=mathjax>\frac{\sum_{k=1}^N k^2}{a}</math>

<math forcemathmode=mathjax>\textstyle \sqrt{\sum_{k=1}^N k^2 }</math>
  • Compare with Server side MathJax rendering (forcemathmode=mathml)

What happens?:

Screenshot 2026-09-30 at 16.47.27.png (658×836 px, 70 KB)

Screenshot 2026-09-30 at 16.47.43.png (660×740 px, 72 KB)

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

Event Timeline

MSantos triaged this task as High priority.Sep 28 2026, 6:58 PM

The image included with this bug report doesn't appear.

Can whoever fixes this also make sure that the problem is fixed at a fundamental level? I imagine there are probably other combinations of nested stuff that lead to the same outcome, but I didn't exhaustively test every imaginable combination.

That's caused by a bug in Phab (T310833), that often causes images to become private such that the author sees them in the task, but everyone else doesn't. I've replaced it with another.

I’m interested in working on this task. From my initial understanding, the issue appears to be related to how displaystyle and other style properties are propagated through nested MathML elements before being processed by MathJax. I’m planning to investigate the MathML transformation/filtering in the Math extension and address the style propagation at the appropriate level, rather than adding a special case for \sum or other individual operators. I’ll also make sure the tests cover the examples in this task as well as relevant nested combinations.

@Osps7 I am happy to review your patch. There are already quite a few tests, for example, for https://phabricator.wikimedia.org/T382669. I would recommend you always compare with LaTeX and try to see how LaTeX does it by reading the LaTeX source, which is less confusing than reading the Stack Overflow comments, which are sometimes a bit off.

Hey @Osps7 I appreciate your enthusiasm and I think there are some options for you as sub-tasks on T375238, happy to help you navigate through it.

As this being a high priority tasks I'm reassigning it to proceed with the roll-out.

Physikerwelt changed the task status from Open to In Progress.Mon, Oct 19, 4:58 PM
Physikerwelt moved this task from Inbox to Ready to implement on the Math board.

Can whoever fixes this also make sure that the problem is fixed at a fundamental level? I imagine there are probably other combinations of nested stuff that lead to the same outcome, but I didn't exhaustively test every imaginable combination.

That's quite a fundamental issue... we have a state variable that stores certain information regarding the style, and this state is not passed like TeX would do. It's about 30 different cases to investigate.

As I now have the dataset of all TeX input for all Wikimedia projects, I feel confident enough to change something at this level.

Even if every existing expression in Wikipedia is made to work by some combination of workarounds or conditional checks or whatever, if the behavior is different at a fundamental level, that seems like a significant problem, since future arbitrary combinations of nested content may behave differently from LaTeX in ways that make no sense to authors.

@Jacobolus, I fully agree. My point is the following.

90 of 673,419 enwiki formulae (~0.013%) hit the bug as filed. (The bug, however, can't be fixed by limiting it only to those cases, so 47 additional examples, mostly \dfrac cases, that follow a similar error pattern need to be taken into account.)

Making the implementation closer to TeX involves changing roughly 290 lines of code (about 190 added, 100 removed). Every line could involve a mistake and change many more formulae, so I want to make sure that only the intended cases change.

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

[mediawiki/extensions/Math@master] WIP: Set TeX math styles on the parse tree

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

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

[mediawiki/extensions/Math@master] Parse scripts without a base as one node

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

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

[mediawiki/extensions/Math@master] Rename Declh to Declaration

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

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

[mediawiki/extensions/Math@master] Move node-specific callbacks to their nodes

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

It seems like the version inside fractions is maybe fixed? But a sums in a square roots with \textstyle set is still the wrong size.

\textstyle needs to propagate through every level of nesting of arbitrary expressions, unless explicitly overridden.

Change #1357848 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Parse scripts without a base as one node

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

The same state problem loses the font inside \left…\right and \frac: <math>\mathbf{\left(C\right)}</math>, <math>\mathbb{\left(R\right)}</math>, <math>\mathrm{\left(x\right)}</math>, <math>\boldsymbol{\left(x\right)}</math> and <math>\mathbf{\frac{a}{b}}</math> give plain italic letters in the native MathML and client-side MathJax modes. LaTeX, server-side MathJax and LaTeXML take the font of the enclosing command. \mathbf{(C)} and \mathbf{\sqrt{c}} are right.
\left…\right and \frac render their content without the arguments of the enclosing command, where the font is set. Until I3ead1c (June 2025), letters inside \left…\right still got \mathbf, \mathbb, \mathcal and \mathfrak from the state; \mathrm, \boldsymbol and \frac were italic before that, too.
Of 672,902 enwiki formulae, 35 have \left inside the argument of a font command. 33 of them differ from server-side MathJax on master, none with If04d83 (patch set 4). 136 have \frac and the like inside \mathbf, \mathrm, \boldsymbol etc.; patch set 4 changes identifier styles in 128 of them.

Change #1358170 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Rename Declh to Declaration

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

Change #1358310 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Move node-specific callbacks to their nodes

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

Change #1357270 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Set TeX math styles on the parse tree

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

All changes are merged. Style commands now end with their group, and fractions and roots set their arguments in the TeX styles. This also fixes @Jacobolus's \textstyle \sqrt{\sum…} and the font cases \mathbf{\left(C\right)} and \mathbf{\frac{a}{b}}.

Live on beta: https://en.wikipedia.beta.wmcloud.org/wiki/T439460
Production follows with the next train.