Merge "Treat \operatorname as a valid operator for limits"

This commit is contained in:
jenkins-bot 2024-11-08 05:19:01 +00:00 committed by Gerrit Code Review
commit f60ea98236
2 changed files with 29 additions and 3 deletions

View file

@ -128,9 +128,16 @@ class TexArray extends TexNode implements \ArrayAccess, \IteratorAggregate {
$tu = TexUtil::getInstance();
// Check whether the current node is a possible preceding literal
if ( !( $currentNode instanceof Literal
&& ( $tu->nullary_macro( trim( $currentNode->getArg() ) )
|| trim( $currentNode->getArg() ) == "\\lim" ) ) ) {
if ( !(
// logically superfluous brackets were inserted to improve readability
( $currentNode instanceof Literal &&
// Check if the current node is a nullary macro such as \iint, \sum, \prod, etc.
( $tu->nullary_macro( trim( $currentNode->getArg() ) )
// or a limit operator
|| ( trim( $currentNode->getArg() ) == "\\lim" ) ) ) ||
// or the special case of \operatorname
( $currentNode instanceof Fun1nb && $currentNode->getFname() == "\\operatorname" )
) ) {
return [ null, false ];
}

View file

@ -3,6 +3,8 @@
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
use InvalidArgumentException;
use MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ;
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Fun1nb;
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexNode;
@ -132,4 +134,21 @@ class TexArrayTest extends MediaWikiUnitTestCase {
$res = $ta->renderMML( [], [ 'squashLiterals' => true ] );
$this->assertEquals( '<mi>a</mi><mi>&#x03B3;</mi>', $res );
}
public function testSumInLimits() {
$ta = new TexArray();
$sum = new Literal( '\sum' );
$res = $ta->checkForLimits( $sum, new DQ( new Literal( '\limits' ), new Literal( 'n' ) ) );
$this->assertTrue( $res[1] );
$this->assertEquals( $sum, $res[0] );
}
public function testCustomOpInLimits() {
$ta = new TexArray();
$custom = new Fun1nb( '\operatorname', new TexArray( new Literal( 'S' ) ) );
$res = $ta->checkForLimits( $custom, new DQ( new Literal( '\limits' ), new Literal( 'n' ) ) );
$this->assertTrue( $res[1] );
$this->assertEquals( $custom, $res[0] );
}
}