Merge "Add missing apply after operatorname"

This commit is contained in:
jenkins-bot 2024-10-16 11:32:32 +00:00 committed by Gerrit Code Review
commit 3c4141423e
3 changed files with 44 additions and 20 deletions

View file

@ -355,12 +355,13 @@ class BaseParsing {
public static function handleOperatorName( $node, $passedArgs, $operatorContent, $name ) {
// In example "\\operatorname{a}"
$applyFct = self::getApplyFct( $operatorContent );
$mmlNot = "";
if ( isset( $operatorContent['not'] ) && $operatorContent['not'] == true ) {
if ( isset( $operatorContent['not'] ) && $operatorContent['not'] ) {
$mmlNot = MMLParsingUtil::createNot();
}
$passedArgs = array_merge( $passedArgs, [ Tag::CLASSTAG => TexClass::OP, "mathvariant" => Variants::NORMAL ] );
return $mmlNot . $node->getArg()->renderMML( $passedArgs );
return $mmlNot . $node->getArg()->renderMML( $passedArgs ) . $applyFct;
}
public static function lap( $node, $passedArgs, $operatorContent, $name ) {
@ -618,16 +619,9 @@ class BaseParsing {
}
public static function namedOp( $node, $passedArgs, $operatorContent, $name, $id = null ) {
/* Determine wether the named function should have an added apply function. The operatorContent is defined
/* Determine whether the named function should have an added apply function. The operatorContent is defined
as state in parsing of TexArray */
$applyFct = "";
if ( array_key_exists( "foundNamedFct", $operatorContent ) ) {
$hasNamedFct = $operatorContent['foundNamedFct'][0];
$hasValidParameters = $operatorContent["foundNamedFct"][1];
if ( $hasNamedFct && $hasValidParameters ) {
$applyFct = MMLParsingUtil::renderApplyFunction();
}
}
$applyFct = self::getApplyFct( $operatorContent );
if ( $node instanceof Literal ) {
$mi = new MMLmi( "", $passedArgs );
@ -935,14 +929,7 @@ class BaseParsing {
public static function namedFn( $node, $passedArgs, $operatorContent, $name, $smth = null ) {
// Determine wether the named function should have an added apply function. The state is defined in
// parsing of TexArray
$applyFct = "";
if ( array_key_exists( "foundNamedFct", $operatorContent ) ) {
$hasNamedFct = $operatorContent['foundNamedFct'][0];
$hasValidParameters = $operatorContent["foundNamedFct"][1];
if ( $hasNamedFct && $hasValidParameters ) {
$applyFct = MMLParsingUtil::renderApplyFunction();
}
}
$applyFct = self::getApplyFct( $operatorContent );
if ( $node instanceof Literal ) {
$mi = new MMLmi();
return $mi->encapsulateRaw( $name ) . $applyFct;
@ -1305,4 +1292,16 @@ class BaseParsing {
)
);
}
private static function getApplyFct( $operatorContent ): string {
$applyFct = "";
if ( array_key_exists( "foundNamedFct", $operatorContent ) ) {
$hasNamedFct = $operatorContent['foundNamedFct'][0];
$hasValidParameters = $operatorContent["foundNamedFct"][1];
if ( $hasNamedFct && $hasValidParameters ) {
$applyFct = MMLParsingUtil::renderApplyFunction();
}
}
return $applyFct;
}
}

View file

@ -176,6 +176,8 @@ class TexArray extends TexNode implements \ArrayAccess, \IteratorAggregate {
$tu->latex_function_names( $currentNodeContent->getArg() ) ) {
$hasNamedFct = true;
}
} elseif ( $currentNode instanceof Fun1nb && $currentNode->getFname() === '\\operatorname' ) {
$hasNamedFct = true;
}
// Check if there is a valid argument as next parameter

View file

@ -165,6 +165,30 @@ class BaseParsingTest extends TestCase {
$this->assertStringContainsString( 'top bottom', $result );
}
public function testHandleOperatorName() {
$node = new Fun1(
'\\operatorname',
( new Literal( 'sn' ) )
);
$result = BaseParsing::handleOperatorName( $node, [], [
"foundNamedFct" => [ true, true ]
], 'operatorname' );
$this->assertStringContainsString( 'sn</mi>', $result );
$this->assertStringContainsString( '<mo>&#x2061;</mo>', $result );
}
public function testHandleOperatorLast() {
$node = new Fun1(
'\\operatorname',
( new Literal( 'sn' ) )
);
$result = BaseParsing::handleOperatorName( $node, [], [
"foundNamedFct" => [ true, false ]
], 'operatorname' );
$this->assertStringContainsString( 'sn</mi>', $result );
$this->assertStringNotContainsString( '<mo>&#x2061;</mo>', $result );
}
public function testColumnSpecs() {
$matrix = ( new TexVC() )->parse( '\\begin{array}{lcr}
z & = & a \\\\
@ -173,5 +197,4 @@ f(x,y,z) & = & x + y + z
$result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' );
$this->assertStringContainsString( 'left center right ', $result );
}
}