Use munder instead of msub for large operators

* Add new class to identify what a (large) operator is
* Add some IDE hints about what methods exist in texutil
* Add tests for operators in display and block style

Bug: T375907
Change-Id: If734f194cd8fa30efaf6d8c8d89f85e3e1c96276
This commit is contained in:
physikerwelt 2024-10-13 21:13:56 +02:00
parent 9321d6ffc7
commit ec44827976
No known key found for this signature in database
GPG key ID: FCC793EFFA5FB13C
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',