Merge "Render MathML for smash command from texified mhchem"

This commit is contained in:
jenkins-bot 2023-09-19 09:14:00 +00:00 committed by Gerrit Code Review
commit 5ef83ce3b6
4 changed files with 81 additions and 1 deletions

View file

@ -531,7 +531,7 @@ class BaseMappings {
"phantom" => 'phantom',
"vphantom" => [ 'phantom', 1, 0 ],
"hphantom" => [ 'phantom', 0, 1 ],
"smash" => 'Smash',
"smash" => 'smash',
"acute" => [ 'accent', '00B4' ],
"grave" => [ 'accent', '0060' ],
"ddot" => [ 'accent', '00A8' ],

View file

@ -943,6 +943,37 @@ class BaseParsing {
return $mstyle->encapsulateRaw( $mspace->encapsulate() );
}
public static function smash( $node, $passedArgs, $operatorContent, $name ) {
$mpArgs = [];
$inner = "";
if ( $node instanceof Fun2sq ) {
$arg1 = $node->getArg1();
$arg1i = "";
if ( $arg1 instanceof Curly ) {
$arg1i = $arg1->getArg()->render();
}
if ( str_contains( $arg1i, "{b}" ) ) {
$mpArgs = [ "depth" => "0" ];
}
if ( str_contains( $arg1i, "{t}" ) ) {
$mpArgs = [ "height" => "0" ];
}
if ( str_contains( $arg1i, "{tb}" ) || str_contains( $arg1i, "{bt}" ) ) {
$mpArgs = [ "height" => "0", "depth" => "0" ];
}
$inner = $node->getArg2()->renderMML() ?? "";
} elseif ( $node instanceof Fun1 ) {
// Implicitly assume "tb" as default mode
$mpArgs = [ "height" => "0", "depth" => "0" ];
$inner = $node->getArg()->renderMML() ?? "";
}
$mrow = new MMLmrow();
$mpAdded = new MMLmpadded( "", $mpArgs );
return $mrow->encapsulateRaw( $mpAdded->encapsulateRaw( $inner ) );
}
public static function texAtom( $node, $passedArgs, $operatorContent, $name, $texClass = null ) {
switch ( $name ) {
case "mathclose":

View file

@ -2120,6 +2120,7 @@
"nullary_macro": true
},
"\\smash": {
"fun_ar1": true,
"fun_ar1opt": true,
"mhchemtexified_required": true
},

View file

@ -84,4 +84,52 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
$checkRes["input"]->renderMML() );
}
public function testSmash1() {
$input = "\\smash[t]{2}";
$texVC = new TexVC();
$warnings = [];
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
$warnings, true );
$this->assertStringContainsString( '<mpadded height="0">', $checkRes["input"]->renderMML() );
}
public function testSmash2() {
$input = "\\smash[b]{x}";
$texVC = new TexVC();
$warnings = [];
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
$warnings, true );
$this->assertStringContainsString( '<mpadded depth="0">', $checkRes["input"]->renderMML() );
}
public function testSmash3() {
$input = "\\smash[bt]{2}";
$texVC = new TexVC();
$warnings = [];
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
$warnings, true );
$this->assertStringContainsString( '<mpadded height="0" depth="0">',
$checkRes["input"]->renderMML() );
}
public function testSmash4() {
$input = "\\smash[tb]{2}";
$texVC = new TexVC();
$warnings = [];
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
$warnings, true );
$this->assertStringContainsString( '<mpadded height="0" depth="0">',
$checkRes["input"]->renderMML() );
}
public function testSmash5() {
$input = "\\smash{2}";
$texVC = new TexVC();
$warnings = [];
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
$warnings, true );
$ar = $checkRes["input"]->renderMML();
$this->assertStringContainsString( '<mpadded height="0" depth="0"', $ar );
}
}