Page MenuHomePhabricator

\textstyle not applied to \binom in MathML
Closed, ResolvedPublic

Assigned To
Authored By
Dexxor
Aug 12 2025, 4:36 PM
Referenced Files
F66080720: Screenshot 2025-09-19 at 12.48.46.png
Sep 19 2025, 10:51 AM
F65742391: image.png
Aug 12 2025, 4:36 PM
F65742386: image.png
Aug 12 2025, 4:36 PM
Subscribers

Description

Enable "MathML (experimental; no images)" in Special:Preferences → Apperance → Math. Then preview a page with the contents <math>\textstyle\sum_{i=0}^r \binom{m}{i}</math>. Due to \textstyle, the sum symbol and the binomial coefficient should be replaced by smaller versions that takes less vertical space. However, only the sum gets smaller, resulting in:

image.png (509×831 px, 69 KB)

But it should look like

image.png (315×810 px, 43 KB)

This is the MathML generated:

<math xmlns="http://www.w3.org/1998/Math/MathML" class="mwe-math-element mwe-math-element-inline">
  <mrow data-mjx-texclass="ORD">
    <mstyle displaystyle="true" scriptlevel="0">
      <mstyle displaystyle="false" scriptlevel="0">
        <msubsup>
          <mo stretchy="false">∑</mo>
          <mrow data-mjx-texclass="ORD">
            <mrow data-mjx-texclass="ORD">
              <mi>i</mi>
              <mo stretchy="false">=</mo>
              <mn>0</mn>
            </mrow>
          </mrow>
          <mrow data-mjx-texclass="ORD">
            <mi>r</mi>
          </mrow>
        </msubsup>
        <mrow data-mjx-texclass="ORD">
          <mstyle displaystyle="true" scriptlevel="0">
            <mrow data-mjx-texclass="ORD">
              <mrow data-mjx-texclass="OPEN">
                <mo minsize="2.047em">(</mo>
              </mrow>
              <mfrac linethickness="0">
                <mrow data-mjx-texclass="ORD">
                  <mi>m</mi>
                </mrow>
                <mrow data-mjx-texclass="ORD">
                  <mi>i</mi>
                </mrow>
              </mfrac>
              <mrow data-mjx-texclass="CLOSE">
                <mo minsize="2.047em">)</mo>
              </mrow>
            </mrow>
          </mstyle>
        </mrow>
      </mstyle>
    </mstyle>
  </mrow>
</math>

I obtained the second screenshot by changing displaystyle="true" to displaystyle="false" and removing minsize="2.047em".

Event Timeline

Interestingly, \tbinom{n}{k} works just fine.

Physikerwelt triaged this task as Medium priority.

Double checking target rendering with overleaf:

Screenshot 2025-09-19 at 12.48.46.png (882×2 px, 146 KB)

This suggests tat \binom (in contrast to \tbinom) might overwrite its displaystyle (or \tbinom explictly sets displaystyle to false).

Physikerwelt changed the task status from Open to In Progress.Sep 19 2025, 9:46 PM

It's defined in texutil.json

json
	"\\binom": {
		"ams_required": true,
		"callback": [
			"genFrac",
			"(",
			")",
			"0",
			"0"
		],
		"fun_ar2": true
	},
	"\\tbinom": {
		"ams_required": true,
		"callback": [
			"genFrac",
			"(",
			")",
			"0",
			"1"
		],
		"fun_ar2": true
	},

the last digit determins the style via

			$styleDigit = intval( $style, 10 );
			$styleAlpha = [ 'D', 'T', 'S', 'SS' ][$styleDigit];
			if ( $styleAlpha == null ) {
				return new MMLmrow( TexClass::ORD, [], new MMLmtext( "", [], "Bad math style" ) );
			}

			if ( $styleAlpha === 'D' ) {
				// NodeUtil_js_1.default.setProperties(frac, { displaystyle: true, scriptlevel: 0 });

				// tbd add props
				$displayStyle = "true";
				$styleAttr = [ "minsize" => "2.047em" ];

			} else {
				$styleAttr = [ "minsize" => "1.2em" ];
			}

So there is no obvious bug.

Physikerwelt changed the task status from In Progress to Open.Sep 19 2025, 10:04 PM

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

[mediawiki/extensions/Math@master] Fix: \textstyle not applied to \binom in MathML

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

Physikerwelt changed the task status from Open to In Progress.Oct 17 2025, 3:40 AM
Physikerwelt moved this task from Inbox to Code Review on the Math board.
Physikerwelt changed the task status from In Progress to Open.Oct 17 2025, 5:35 AM

Change #1196752 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Fix: \textstyle not applied to \binom in MathML

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