diff --git a/src/WikiTexVC/Nodes/DQ.php b/src/WikiTexVC/Nodes/DQ.php index 7ee3f1e5a..ddbaab80d 100644 --- a/src/WikiTexVC/Nodes/DQ.php +++ b/src/WikiTexVC/Nodes/DQ.php @@ -8,6 +8,7 @@ use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseParsing; use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow; use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsub; use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmunder; +use MediaWiki\Extension\Math\WikiTexVC\TexUtil; class DQ extends TexNode { /** @var TexNode */ @@ -57,6 +58,12 @@ class DQ extends TexNode { $outer = new MMLmunder(); } else { $outer = new MMLmsub(); + if ( ( $state['styleargs']['displaystle'] ?? 'true' ) === 'true' ) { + $tu = TexUtil::getInstance(); + if ( $this->base instanceof Literal && $tu->operator( trim( $this->base->getArg() ) ) ) { + $outer = new MMLmunder(); + } + } } // Otherwise use default fallback $mmlMrow = new MMLmrow(); diff --git a/src/WikiTexVC/TexUtil.php b/src/WikiTexVC/TexUtil.php index 114e26289..f859734e2 100644 --- a/src/WikiTexVC/TexUtil.php +++ b/src/WikiTexVC/TexUtil.php @@ -6,6 +6,12 @@ namespace MediaWiki\Extension\Math\WikiTexVC; use InvalidArgumentException; +/** + * @method is_literal(string $litArg) + * @method latex_function_names(string $getArg) + * @method nullary_macro(string $litArg) + * @method operator(string $getArg) + */ class TexUtil { /** @var self|null */ private static $instance = null; diff --git a/src/WikiTexVC/texutil.json b/src/WikiTexVC/texutil.json index 6ab4d718d..068060a90 100644 --- a/src/WikiTexVC/texutil.json +++ b/src/WikiTexVC/texutil.json @@ -476,13 +476,16 @@ "big_literals": true }, "\\bigcap": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigcirc": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigcup": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigg": { "big_literals": true @@ -497,38 +500,48 @@ "big_literals": true }, "\\bigodot": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigoplus": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigotimes": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigr": { "big_literals": true }, "\\bigsqcup": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigstar": { "ams_required": true, - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigtriangledown": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigtriangleup": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\biguplus": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigvee": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\bigwedge": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\binom": { "ams_required": true, @@ -725,7 +738,8 @@ "teubner_required": true }, "\\coprod": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\cos": { "latex_function_names": true @@ -1144,15 +1158,18 @@ }, "\\iiiint": { "ams_required": true, - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\iiint": { "ams_required": true, - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\iint": { "ams_required": true, - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\image": { "nullary_macro_aliase": "\\Im" @@ -1182,14 +1199,17 @@ "nullary_macro": true }, "\\int": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\intBar": { "nullary_macro": true, + "operator": true, "stix_required": true }, "\\intbar": { "nullary_macro": true, + "operator": true, "stix_required": true }, "\\intent": { @@ -1199,7 +1219,8 @@ "\\intercal": { "ams_required": true, "is_literal": true, - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\iota": { "is_literal": true, @@ -1946,7 +1967,8 @@ "nullary_macro": true }, "\\prod": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\projlim": { "ams_required": true, @@ -2248,7 +2270,8 @@ "nullary_macro": true }, "\\sum": { - "nullary_macro": true + "nullary_macro": true, + "operator": true }, "\\sup": { "latex_function_names": true diff --git a/tests/phpunit/unit/WikiTexVC/Nodes/DQTest.php b/tests/phpunit/unit/WikiTexVC/Nodes/DQTest.php index e2a4c4bd8..3d85df2bd 100644 --- a/tests/phpunit/unit/WikiTexVC/Nodes/DQTest.php +++ b/tests/phpunit/unit/WikiTexVC/Nodes/DQTest.php @@ -4,6 +4,8 @@ namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes; use ArgumentCountError; use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow; +use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsub; +use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmunder; use MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ; use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal; use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray; @@ -56,4 +58,16 @@ class DQTest extends MediaWikiUnitTestCase { $this->assertStringContainsString( ( new MMLmrow() )->getEmpty(), $dq->renderMML() ); } + public function testBigSum() { + $dq = new DQ( new Literal( '\\sum' ), new Literal( 'i' ) ); + $this->assertStringContainsString( ( new MMLmunder() )->getStart(), $dq->renderMML() ); + } + + public function testSmallSum() { + $dq = new DQ( new Literal( '\\sum' ), new Literal( 'i' ) ); + $this->assertStringContainsString( + ( new MMLmsub() )->getStart(), + $dq->renderMML( [], [ 'styleargs' => [ 'displaystle' => 'false' ] ] ) ); + } + } diff --git a/tests/phpunit/unit/WikiTexVC/TexUtilTest.php b/tests/phpunit/unit/WikiTexVC/TexUtilTest.php index 8ba268fd9..a388d6570 100644 --- a/tests/phpunit/unit/WikiTexVC/TexUtilTest.php +++ b/tests/phpunit/unit/WikiTexVC/TexUtilTest.php @@ -76,6 +76,7 @@ class TexUtilTest extends MediaWikiUnitTestCase { 'mhchem_single_macro', 'nullary_macro', 'nullary_macro_in_mbox', + 'operator', 'other_delimiters1', 'other_delimiters2', 'over_operator',