Page MenuHomePhabricator

Too much space around / in MathML formatting mode
Closed, ResolvedPublicBUG REPORT

Assigned To
Authored By
SalixAlba
Sep 22 2024, 8:51 AM
Referenced Files
F57711110: Screenshot 2024-11-16 at 20.33.32.png
Nov 16 2024, 7:35 PM
Restricted File
Sep 28 2024, 9:29 PM
Restricted File
Sep 28 2024, 9:29 PM
F57565972: image.png
Sep 28 2024, 5:25 PM
F57565953: image.png
Sep 28 2024, 5:25 PM
F57565950: image.png
Sep 28 2024, 5:25 PM
F57564874: image.png
Sep 28 2024, 9:15 AM
F57564859: image.png
Sep 28 2024, 9:15 AM

Description

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

  • Set Math rendering preference to MathML
  • Set math font to Cambria Math in chrome settings
  • Enter the formula <math>\frac{a}{b/2}<math>

What happens?:

Rendered as

image.png (104×95 px, 2 KB)

What should have happened instead?:

In LaTeX it is rendered as

image.png (81×72 px, 1 KB)

With less space on either-side of the /.

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

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

Chrome 129

Event Timeline

In MathJax rendering it looks good to me

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

@SalixAlba would you agree?

From what I see:

<mfrac>
	<mrow data-mjx-texclass="ORD">
		<mi>a</mi>
	</mrow>
	<mrow data-mjx-texclass="ORD">
		<mrow data-mjx-texclass="ORD">
			<mi>b</mi>
			<mo>/</mo>
			<mn>2</mn>
		</mrow>
	</mrow>
</mfrac>

I don't see space manipulations in the MathML output.

As a reference also the LaTeXML rendering looks similar

image.png (59×87 px, 2 KB)

<mfrac>
	<mi>a</mi>
	<mrow>
		<mi>b</mi>
		<mo>/</mo>
		<mn>2</mn>
	</mrow>
</mfrac>

looks identical.

As the rendering is equally large among browsers, it is either the expected behavior or an issue with the MathML spec itself. What is your feeling @SalixAlba

In Firefox you can use

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>a</mi>
  <mo>+</mo>
  <mi>b</mi>
  <mpadded width="0.1em" lspace="-0.15em"> 
    <mo>/</mo>
  </mpadded>
  <mi>c</mi>
</math>

Which renders as

image.png (83×171 px, 2 KB)

But, negative lspace is not part of MathML core, and is not supported by Chrome. Which renders as

image.png (74×147 px, 1 KB)

Clearly not great.

The problem seems to be in the Operator directory (https://w3c.github.io/mathml/#oper-dict)
where / solidus has an lspace of 4 and rspace of 4.

We can override these attribute for individual operators

<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><mo>+</mo><mi>b</mi>
<mo lspace="0" rspace="0">/</mo></mpadded><mi>c</mi>
</math>

Renders as

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

In Chrome and Firefox. Which looks acceptable.

Whether we should is another question.

I really don't know. Maybe it is not desired that + and /have different spacing. If you want we could ask the w3c math WG?

I'm inclined to think that we want to be closer to LaTeX conventions than MathML ones, so lspace="0" and rspace="0" is appropriate.

There is a related question about the | operator, used in conditional probability <math>p(a|b)</math>
and rendered with lots of space.

{F57566599}

SVG is tighter

{F57566610}

MathML has different default space when its a prefix op (lspace=rspace=0) and an infix op (lspace=rspace=5).

This seems to give inconsistent spacing, when used as bra-kets so <math>|b\rangle</math> has no space but <math>\langle a | b \rangle</math> has more space.

There is a related question about the | operator, used in conditional probability <math>p(a|b)</math>
and rendered with lots of space.

{F57566599}

SVG is tighter

{F57566610}

MathML has different default space when its a prefix op (lspace=rspace=0) and an infix op (lspace=rspace=5).

This seems to give inconsistent spacing, when used as bra-kets so <math>|b\rangle</math> has no space but <math>\langle a | b \rangle</math> has more space.

Unfortunately, I can not see the pictures. It seems they are access-restricted.

I'm inclined to think that we want to be closer to LaTeX conventions than MathML ones, so lspace="0" and rspace="0" is appropriate.

I think it would be good to check what others (e.g. arxiv) do here.

Physikerwelt changed the task status from Open to Stalled.Oct 12 2024, 10:02 PM
Physikerwelt changed the task status from Stalled to Open.Nov 9 2024, 7:14 PM
Physikerwelt added a subscriber: Krinkle.

@Krinkle This is a mistake in the spec, which is going to be fixed upstream https://github.com/w3c/mathml-core/issues/260#issuecomment-2444013254 . Should we still overwrite the defaults or wait until browsers eventually pick up the change in the spec?

@Physikerwelt What happens if, after we roll this out, one of the browsers picks up the change in spec. Does that conflict in any way? If not, I suppose if could go ahead with our overwrite in the mean time.

There is quite a long lee way for browser adoption in practice. It seems likely to be at least 12 months before all three implement it. Then, another 4-6 months for their release cycle to end. Then the browser release adoption rate which in the case of Mobile Safari is ~4 months to get 90% of the peak of a single version's usage of Mobile Safari. With all that in place we'd still only be at 70-80% in terms of actual traffic. If you want to reach 90% it'd optimistically be 3 years away as more of the long tail upgrades, including forks and repackaged versions (such as UC Web, ref T178356#8740573).

@Physikerwelt What happens if, after we roll this out, one of the browsers picks up the change in spec. Does that conflict in any way? If not, I suppose if could go ahead with our overwrite in the mean time.

No, it's not a problem. We would follow the suggestion of @SalixAlba

I'm inclined to think that we want to be closer to LaTeX conventions than MathML ones, so lspace="0" and rspace="0" is appropriate.

with a custom CSS class. For browsers that would have already picked up the change, the CSS class would have no effect (despite a neglectable performance decrease).

I want to make sure that we don't reinvent the wheel. I would guess there are many instances where Wikimedians (here @SalixAlba) discover problems in standards, which are then fixed for everyone. Do we have a process for that?

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

[mediawiki/extensions/Math@master] Overwrite spacing for divide

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

Change #1089140 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Overwrite spacing for divide

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

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

[mediawiki/extensions/Math@REL1_43] Overwrite spacing for divide

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

Change #1091836 merged by jenkins-bot:

[mediawiki/extensions/Math@REL1_43] Overwrite spacing for divide

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

Fixed for MediaWiki see https://en.wikipedia.beta.wmflabs.org/wiki/T375337

Screenshot 2024-11-16 at 20.33.32.png (834×595 px, 137 KB)

for the rest of the world, it will take some time until it will be adopted and we can eventually remove the additional overwrite here. I am closing this ticket regardless.