mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-13 17:56:59 +00:00
Merge "Add missing apply after operatorname"
This commit is contained in:
commit
3c4141423e
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>⁡</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>⁡</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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue