Merge "Squash literals in operatornames"

This commit is contained in:
jenkins-bot 2024-10-16 12:18:09 +00:00 committed by Gerrit Code Review
commit 188d13ca64
3 changed files with 33 additions and 1 deletions

View file

@ -361,7 +361,7 @@ class BaseParsing {
$mmlNot = MMLParsingUtil::createNot();
}
$passedArgs = array_merge( $passedArgs, [ Tag::CLASSTAG => TexClass::OP, "mathvariant" => Variants::NORMAL ] );
return $mmlNot . $node->getArg()->renderMML( $passedArgs ) . $applyFct;
return $mmlNot . $node->getArg()->renderMML( $passedArgs, [ 'squashLiterals' => true ] ) . $applyFct;
}
public static function lap( $node, $passedArgs, $operatorContent, $name ) {

View file

@ -193,12 +193,32 @@ class TexArray extends TexNode implements \ArrayAccess, \IteratorAggregate {
return [ $hasNamedFct, $hasValidParameters ];
}
private function squashLiterals() {
$tmp = '';
foreach ( $this->args as $arg ) {
if ( !( $arg instanceof Literal ) ) {
return;
}
// Don't squash if there is a macro in the literal
if ( preg_match( "/[\\\\]/", $arg->getArg() ) ) {
return;
}
$tmp .= $arg->getArg();
}
$this->args = [ new Literal( $tmp ) ];
$this->curly = false;
}
public function renderMML( $arguments = [], $state = [] ) {
// Everything here is for parsing displaystyle, probably refactored to WikiTexVC grammar later
$fullRenderedArray = "";
$mmlStyles = [];
$currentColor = null;
if ( array_key_exists( 'squashLiterals', $state ) ) {
$this->squashLiterals();
}
for ( $i = 0, $count = count( $this->args ); $i < $count; $i++ ) {
$current = $this->args[$i];
if ( isset( $this->args[$i + 1] ) ) {

View file

@ -120,4 +120,16 @@ class TexArrayTest extends MediaWikiUnitTestCase {
$ta = new TexArray();
$ta[0] = 'a';
}
public function testSquashLiterals() {
$ta = new TexArray( new Literal( 'a' ), new Literal( 'b' ) );
$res = $ta->renderMML( [], [ 'squashLiterals' => true ] );
$this->assertEquals( '<mi>ab</mi>', $res );
}
public function testSquashLiteralsMacro() {
$ta = new TexArray( new Literal( 'a' ), new Literal( '\gamma' ) );
$res = $ta->renderMML( [], [ 'squashLiterals' => true ] );
$this->assertEquals( '<mi>a</mi><mi>&#x03B3;</mi>', $res );
}
}