Page MenuHomePhabricator

a\operatorname{sn}b rendered with no spaces before and after operator in MathML mode
Closed, ResolvedPublic3 Estimated Story PointsBUG REPORT

Assigned To
Authored By
SalixAlba
Sep 27 2024, 10:45 AM
Referenced Files
F65756495: image.png
Aug 15 2025, 2:35 PM
F65756493: image.png
Aug 15 2025, 2:35 PM
F57641523: Screenshot 2024-10-25 at 06.05.59.png
Oct 25 2024, 5:17 AM
F57635116: Screenshot 2024-10-23 at 01.36.08.png
Oct 23 2024, 12:39 AM
F57611523: image.png
Oct 13 2024, 7:31 PM
F57594772: image.png
Oct 7 2024, 1:06 PM
F57561945: image.png
Sep 27 2024, 10:45 AM
F57561942: image.png
Sep 27 2024, 10:45 AM

Description

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

  • Enter the formula a\operatorname{sn}b

What happens?:

Rendered as

image.png (45×73 px, 1 KB)

What should have happened instead?:

Space should be included before and after the operator.

In SVG mode:

image.png (53×97 px, 2 KB)

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

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

Chrome 129.

Event Timeline

See T375863 for related but worse bug in client-side MathJax mode.

It seems we miss a lspace here.

LaTeXML output

<mi>a</mi>
<mo lspace="0.167em">⁢</mo>
<mrow>
	<mi>sn</mi>
	<mo lspace="0.167em">⁡</mo>
	<mi>b</mi>
</mrow>

vs ours

<mi>a</mi>
<mrow data-mjx-texclass="ORD">
	<mi data-mjx-texclass="OP" mathvariant="normal">s</mi>
	<mi data-mjx-texclass="OP" mathvariant="normal">n</mi>
</mrow>
<mi>b</mi>

As we treat sn as individual elements in the parse tree. An acceptable solution would be

<mi>a</mi>
<mo lspace="0.167em" />⁡
<mrow data-mjx-texclass="ORD">
	<mi data-mjx-texclass="OP" mathvariant="normal">s</mi>
	<mi data-mjx-texclass="OP" mathvariant="normal">n</mi>
</mrow>
<mo lspace="0.167em"/>
<mi>b</mi>
Physikerwelt set the point value for this task to 3.
Physikerwelt changed the task status from Open to In Progress.Oct 1 2024, 9:01 PM

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

[mediawiki/extensions/Math@master] WIP: Add more space around \operatorname

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

It's easy to implement that space is always added. However, this would render the wikitext

a<math>\operatorname{sn}</math>b

with space between a sn b.

If no space should only be added if there is any other math before or after the \operatorname thing, this would be complicated as operatorname is currently rendered stateless, so it can neither easily look ahead nor behind.

@SalixAlba what do you think?

I'm afraid \operatorname needs to be context-dependent. We don't want to add spaces if before or after it we have a delimiter. For example, a(\operatorname{sn}(b)), a[\operatorname{sn}[[b]], a\{\operatorname{sn}\{b\}\} should all be rendered without extra spaces, either before or after.

@Stegmujo, do you have any idea how we could treat \operatorname{xxx} like the other operators, such as \log? It was not immediately obvious to me by looking at the code.

Another case where we can just add space is when brackets are added, say <math>\operatorname{G}(V, g)</math> eg in https://en.wikipedia.org/wiki/Talk:Geometric_algebra/Archive_4#Definition

Another case where we can just add space is when brackets are added, say <math>\operatorname{G}(V, g)</math> eg in https://en.wikipedia.org/wiki/Talk:Geometric_algebra/Archive_4#Definition

So you would say this needs a space or it should have no space? On overleaf there is no space

image.png (76×74 px, 3 KB)

from the input

\begin{align}
\operatorname{G}(V, g)\\
\mathrm{G}(V, g)\\
\operatorname{G}V \\
\mathrm{G}V 
\end{align}
Physikerwelt changed the task status from In Progress to Open.Oct 7 2024, 1:23 PM

That overleaf behaviour is what I would expect.

Strategy Follow the rendering of \log. Thus, make \operatorname{log} look like \log, which is currently not the case

image.png (66×90 px, 3 KB)

Change #1077109 abandoned by Physikerwelt:

[mediawiki/extensions/Math@master] WIP: Add more space around \operatorname

Reason:

dead end

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

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

[mediawiki/extensions/Math@master] Add missing apply after operatorname

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

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

[mediawiki/extensions/Math@master] Squash literals in operatornames

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

Change #1079668 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Add missing apply after operatorname

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

Change #1079674 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Squash literals in operatornames

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

For what its worth, this space is missing in MathJax MathML's rendering as well (Firefox):

Screenshot 2024-10-23 at 01.36.08.png (1×1 px, 301 KB)

It does have an empty <mo> though, and it groups "sn" and "b" together in one mrow.

Above based on latest rendering on Beta at https://en.wikipedia.beta.wmflabs.org/wiki/Extension:Math/Native_MathML/Reported_Cases

@Krinkle You have to use action=purge to get the latest rendering. The MathML you are looking at is the hidden one generated by mathoid. The "empty" element is an invisible function application, so only invisible but not empty.

@Physikerwelt I understand. I made it visible for that reason. My point was to show that the space was also missing in Mathoid's MathML rendering.

Two days ago, the space between "sn" and "b" appeared to be missing from both:

Screenshot 2024-10-23 at 01.36.08.png (1×1 px, 301 KB)

Today, it appears fixed in both, despite the Mathoid MathoidML not having changed:

Screenshot 2024-10-25 at 06.05.59.png (1×1 px, 270 KB)

I realize now that the reason that the space appeared to be missing from the Mathoid MathML, is that I broke it shortly before making the screenshot via the console. It was fine before. I accidentally removed the line break inside <mo> <!-- --></mo> while removing data attributes for screenshot clarity. There is something funny going on where an empty <mo></mo> displays the space, <mo> </mo> with only a space, displays the space, <mo> <!-- --></mo> with a space and a comment, displays the space. But... having <mo><!-- --></mo> with only a comment makes the space dissappear in Firefox. That's something I would not have predicted. I would have expected a strictly empty element to behave the same as an element with only a comment. Or at best for the comment to make it "less" empty. Instead, the presence of the comment seems to collapse or nullify the element in a special way.

Oh well, mystery solved.

I created this codepen with a minimal examples that shows that

<mrow>
  <mi>a</mi>
  <mi>b</mi>
  <mi>c</mi>
  <mi>d</mi>
</mrow>

renders without space while

<mrow>
  <mi>a</mi>
  <mi>bc</mi>
  <mi>d</mi>
</mrow>

adds space. To seperate this from the invisible apply operator. I hope this is helpful for people stubling over this ticket in the future.

This is now working correctly on Firefox

image.png (197×207 px, 6 KB)

But not in Chrome

image.png (173×199 px, 5 KB)

Arg, I can see that from the codepen. It almost seems that Chrome has changed its rendering. @fredw Do you think that's possible?

I think we need help from someone with knowledge about Chrome. In the output, there is definitely an invisible function application. So at least there should be some space after sn. I created another CodePen to highlight the problem https://codepen.io/physikerwelt/pen/NPGorVd and filed an upstream Chrome bug https://issues.chromium.org/issues/443107123

We discussed that today in the MathML meeting and decided to implement that with explicit spaces.

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

[mediawiki/extensions/Math@master] Use mo instead mi for \operatorname rendering

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

I created this codepen with a minimal examples that shows that ...

Now, we use mo instead of mi

<mrow>
  <mi>a</mi>
  <mo>bc</mo>
  <mi>d</mi>
</mrow>

Change #1196740 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Use mo instead mi for \operatorname rendering

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