Skip to content

Commit ede31d0

Browse files
committed
Fix k=1 should appear under sum in displaystyle
* In test MathNativeTests: "\sum_{k=1}^N k^2" * also verify that textstyle variant works correctly Bug: T315978 Change-Id: I8f6cd5ef1e4539616439542184cb7d9dc5cf2363
1 parent 9450bb2 commit ede31d0

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/TexVC/Nodes/FQ.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use MediaWiki\Extension\Math\TexVC\MMLmappings\BaseParsing;
88
use MediaWiki\Extension\Math\TexVC\MMLnodes\MMLmrow;
9+
use MediaWiki\Extension\Math\TexVC\MMLnodes\MMLmstyle;
910
use MediaWiki\Extension\Math\TexVC\MMLnodes\MMLmsubsup;
1011
use MediaWiki\Extension\Math\TexVC\MMLnodes\MMLmunderover;
1112

@@ -84,10 +85,18 @@ public function renderMML( $arguments = [], $state = [] ) {
8485
$emptyMrow = $mrow->getEmpty();
8586
}
8687
// This seems to be the common case
87-
return $melement->encapsulateRaw(
88+
$inner = $melement->encapsulateRaw(
8889
$emptyMrow .
8990
$this->getBase()->renderMML( [], $state ) .
9091
$mrow->encapsulateRaw( $this->getDown()->renderMML( [], $state ) ) .
9192
$mrow->encapsulateRaw( $this->getUp()->renderMML( [], $state ) ) );
93+
94+
if ( $melement instanceof MMLmunderover ) {
95+
$args = $state['styleargs'] ?? [ "displaystyle" => "true", "scriptlevel" => 0 ];
96+
$style = new MMLmstyle( "", $args );
97+
return $style->encapsulateRaw( $inner );
98+
}
99+
100+
return $inner;
92101
}
93102
}

tests/phpunit/unit/TexVC/MMLRenderTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@
1414
* @covers \MediaWiki\Extension\Math\TexVC\TexVC
1515
*/
1616
class MMLRenderTest extends MediaWikiUnitTestCase {
17-
public function testUnderbrace() {
18-
$input = "\underbrace{ a+b+\cdots+z }_{26}";
17+
18+
public function testUnder() {
19+
$input = "\\underbrace{ a+b+\\cdots+z }_{26}";
1920
$mathMLtexVC = $this->generateMML( $input );
2021
$this->assertStringContainsString( "<munder>", $mathMLtexVC );
2122
$this->assertStringNotContainsString( "<msub>", $mathMLtexVC );
2223
}
2324

25+
public function testSumDisplaystyle() {
26+
$input = "\sum_{k=1}^N k^2";
27+
$mathMLtexVC = $this->generateMML( $input );
28+
$this->assertStringContainsString( "<mstyle displaystyle=\"true\" scriptlevel=\"0\">", $mathMLtexVC );
29+
}
30+
31+
public function testSumTextstyle() {
32+
$input = "\\textstyle \sum_{k=1}^N k^2";
33+
$mathMLtexVC = $this->generateMML( $input );
34+
$this->assertStringContainsString( "<mstyle displaystyle=\"false\" scriptlevel=\"0\">", $mathMLtexVC );
35+
}
36+
2437
public function testPilcrow() {
2538
$input = "\P";
2639
$mathMLtexVC = $this->generateMML( $input );

0 commit comments

Comments
 (0)