mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Add missing apply after operatorname
* Reapply the logic of \log rendering to \operatorname * Deduplicate applyFunctionDetection Note this still does not solve the rendering problem for operator names with more than one letter as these generate mrow elements with single letters. Those are not rendered with space in FF. Bug: T375861 Change-Id: I913d865b49d5894a63c8b9d244768f9bb1df4e28
This commit is contained in:
parent
602043027d
commit
9a27d92c09
|
@ -364,12 +364,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 ) {
|
||||
|
@ -627,16 +628,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 );
|
||||
|
@ -944,14 +938,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;
|
||||
|
@ -1314,4 +1301,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