Merge "Use munder instead of msub for large operators"

This commit is contained in:
jenkins-bot 2024-10-16 12:38:21 +00:00 committed by Gerrit Code Review
commit 9c9c20e09e
5 changed files with 72 additions and 21 deletions

View file

@ -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();

View file

@ -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;

View file

@ -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

View file

@ -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' ] ] ) );
}
}

View file

@ -76,6 +76,7 @@ class TexUtilTest extends MediaWikiUnitTestCase {
'mhchem_single_macro',
'nullary_macro',
'nullary_macro_in_mbox',
'operator',
'other_delimiters1',
'other_delimiters2',
'over_operator',