Page MenuHomePhabricator

Bad spacing of <math>x := 1</math> in MathML
Closed, ResolvedPublicBUG REPORT

Assigned To
Authored By
Dexxor
Aug 12 2025, 7:56 PM
Project Tags
Referenced Files
F71674025: image.png
Feb 4 2026, 3:44 PM
F71661149: Screenshot 2026-02-03 at 20.58.42.png
Feb 3 2026, 7:59 PM
F66743453: image.png
Oct 11 2025, 7:16 PM

Description

Enable "MathML (experimental; no images)" in Special:Preferences → Apperance → Math. Then preview a page with the contents <math>x := 1</math>.

This renders like x: = 1 in Firefox (see figure 1) but it should render like x := 1 because the := operator is used to define the variable x. In client-side MathJax mode it looks good.

This is the MathML generated:

<mi>x</mi><mo stretchy="false">:</mo><mo stretchy="false">=</mo><mn>1</mn>

For comparison, https://temml.org/ generates

<mi>x</mi><mo lspace="0.2222em" rspace="0em">:</mo><mo lspace="0em">=</mo><mn>1</mn>

and https://latexml.mathweb.org/editor generates

<mi>x</mi><mo>:=</mo><mn>1</mn>

image.png (161×77 px, 3 KB)

Figure 1: Firefox rendering

Event Timeline

Can you include screenshots in the description?

Change #1225554 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Improve spacing for := operator in MathML

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

I submitted the patch: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1225554 for this task.

Changes Made:

Reduced colon operator rspace from 0.278em to 0.222em in BaseMethods.php
Updated all test expectations in reference.json
Updated LiteralTest.php test assertion

Result:

The := operator now renders with tighter spacing, making it appear more like a single operator

Change #1227366 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Add := operator definition to texutil.json

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

Change #1227366 abandoned by Aarohisharma3:

[mediawiki/extensions/Math@master] Add := operator definition to texutil.json

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

Change #1229137 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Document `:=` operator spacing with MathJax/TeX origins

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

Change #1229138 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Add PHPUnit tests for operator spacing refactoring

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

Change #1225149 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Refactor colon operator spacing to use JSON configuration

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

@Aarohisharma3 you have been doing excellent work. Now please try to break down things to atomic commits (only a few lines). The most obvious change would be to the grammar change https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1225149/6/src/WikiTexVC/parser.pegjs with the corresponding php file and the tests. This will change our output from

<mi>x</mi><mo stretchy="false">:</mo><mo stretchy="false">=</mo><mn>1</mn>

to

<mi>x</mi><mo stretchy="false">:=</mo><mn>1</mn>

( while I am not 100% sure about the stretchy)

What I would suggest to do is the following

  1. Checkout a new branch (from within the math extension dir run git checkout -b T401746 gerrit/master T401746 (can be anything but I tend to use the ticket name if I have no better idea for a topic)
  2. Change the grammar file as you did in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1225149/6/src/WikiTexVC/parser.pegjs
  3. Generate the parser PHP file via maintenance/buildPHPparser.js
  4. Add mathml test. (Go to the file tests/phpunit/integration/WikiTexVC/data/reference.json and add some tex input at the end such as
{
        "input": "x := 1",
        "params": [],
        "bug": "T401746",
        "output": ""
}
  1. then run maintenance/FixNativeReferences.php which will replace output by the actual rendering.
  2. (optional, add more tests)

maybe something like

	public function testColonEquals() {
		$result = $this->texVC->check( ':=' );
		$firstChild = $result['input']->first();
		$this->assertInstanceOf( Literal::class, $firstChild );
		$this->assertEquals( ':=', $firstChild->getArg() );
	}

which can go to

tests/phpunit/unit/WikiTexVC/ApiTest.php

as you don't need to generate MathML here it can be in unit (no need to move it to integration).

  1. run style checks composer fix
  2. run type checking composer phan
  3. run unit tests

The result is than a an atomic change that can be easily, reviewed and tested.

The changes of the spacing is then a second commit I guess. Here MathML defines how the operators are supposed to be rendered. https://www.w3.org/TR/mathml-core/#operator-dictionary-human . From the comments I think the values defined there are good. If some browsers don't render the operators using the spaces defined there, we should in the code link to the upstream tickets about fixing that. Maybe instead of having the community file a bug for each problem, we might want to have a systematic check for the entire table.

Thanks for the review!

I will split this into two separate commits as suggested:
one commit for : operator spacing (T414276)
one commit for := operator spacing (T401746)
This will make the changes atomic and easier to test manually.
After splitting, I’ll re-run the PHPUnit + integration tests to ensure behavior is unchanged.

Thanks again for the guidance!

Change #1229587 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

Change #1229587 abandoned by Aarohisharma3:

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

Change #1229591 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

Patch uploaded to Gerrit: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1229591

This patch fixes the := parsing issue to render as a single MathML token.
All unit and integration tests pass.

Patch uploaded to Gerrit: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1229591

This patch fixes the := parsing issue to render as a single MathML token.
All unit and integration tests pass.

I think you didn't commit the files you intended to commit.

Thanks for pointing this out! I’ll double-check my commit and push the missing files if needed.

Change #1229603 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

Change #1229591 abandoned by Aarohisharma3:

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

Change #1229608 had a related patch set uploaded (by Aarohisharma3; author: Aarohisharma3):

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

Change #1229608 abandoned by Aarohisharma3:

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

Change #1229138 abandoned by Thiemo Kreuz (WMDE):

[mediawiki/extensions/Math@master] Add PHPUnit tests for operator spacing refactoring

Reason:

This is a copy of I80de68a, patchset 7.

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

Change #1225149 abandoned by Physikerwelt:

[mediawiki/extensions/Math@master] Refactor colon operator spacing to use JSON configuration

Reason:

Please look at https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1229603 which is almost done.

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

Change #1229137 abandoned by Physikerwelt:

[mediawiki/extensions/Math@master] Document `:=` operator spacing with MathJax/TeX origins

Reason:

Please look at https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1229603 instead

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

Change #1229603 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Fix := operator parsing to render as single MathML token

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

@Physikerwelt , thanks! How did you cleared the cache? I did an "?action=purge" but that did not the job for me.

This time it worked. Last time I had to do action=purge twice on beta. I never had to do that locally. Maybe purging is a bit unstable on beta. However, I never could reproduce this behavior.

Change #1225554 abandoned by Physikerwelt:

[mediawiki/extensions/Math@master] Improve spacing for := operator in MathML

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