Merge "Render MathML for some letters used in mhchem"

This commit is contained in:
jenkins-bot 2023-10-05 15:14:13 +00:00 committed by Gerrit Code Review
commit 383428b478
3 changed files with 59 additions and 0 deletions

View file

@ -774,6 +774,20 @@ class BaseMappings {
"varointclockwise" => [ 'oint', '\u2232', [ "texClass" => TexClass::OP ] ],
"\\P" => [ 'oint', '\u00B6', [ "texClass" => TexClass::OP ] ],
'textvisiblespace' => [ 'Insert', '\u2423' ], // From TextCompMappings.js (only makro it seems)
"Alpha" => [ 'customLetters', "A" ],
"Beta" => [ 'customLetters', "B" ],
"Chi" => [ 'customLetters', "X" ],
"Epsilon" => [ 'customLetters', "E" ],
"Eta" => [ 'customLetters', "H" ],
"Iota" => [ 'customLetters', "I" ],
"Kappa" => [ 'customLetters', "K" ],
"Mu" => [ 'customLetters', "M" ],
"Nu" => [ 'customLetters', "N" ],
"Omicron" => [ 'customLetters', "O" ],
"Rho" => [ 'customLetters', "P" ],
"Tau" => [ 'customLetters', "T" ],
"Zeta" => [ 'customLetters', "Z" ],
"ca" => [ "customLetters", "∼", true ]
];
private const ALL = [

View file

@ -211,6 +211,18 @@ class BaseParsing {
return "tbd chemCustom";
}
public static function customLetters( $node, $passedArgs, $operatorContent, $name, $char, $isOperator = false ) {
$mrow = new MMLmrow();
if ( $isOperator ) {
$mo = new MMLmo();
return $mrow->encapsulateRaw( $mo->encapsulateRaw( $char ) );
}
$mi = new MMLmi( "", [ "mathvariant" => "normal" ] );
return $mrow->encapsulateRaw( $mi->encapsulateRaw( $char ) );
}
public static function cFrac( $node, $passedArgs, $operatorContent, $name ) {
$mrow = new MMLmrow();
$mfrac = new MMLmfrac();

View file

@ -15,6 +15,39 @@ use MediaWikiUnitTestCase;
*/
final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
public static function provideTestCasesLetters() {
return [
[ "Alpha" , "A" ],
[ "Beta" , "B" ] ,
[ "Chi" , "X" ],
[ "Epsilon" , "E" ],
[ "Eta" , "H" ],
[ "Iota" , "I" ],
[ "Kappa" , "K" ],
[ "Mu" , "M" ],
[ "Nu" , "N" ],
[ "Omicron" , "O" ],
[ "Rho" , "P" ],
[ "Tau" , "T" ],
[ "Zeta" , "Z" ]
];
}
/**
* @dataProvider provideTestCasesLetters
*/
public function testmhchemLetters( $case, $result ) {
$input = "\ce{\\" . $case . " \ca }";
$texVC = new TexVC();
$options = [ "usemhchem" => true, "usemhchemtexified" => true ];
$warnings = [];
$res = $texVC->check( $input, $options, $warnings, true );
$mml = $res['input']->renderMML();
$this->assertStringContainsString( '<mi', $mml );
$this->assertStringContainsString( $result . '</mi>', $mml );
$this->assertStringContainsString( '<mo>&#x223C;</mo>', $mml );
}
public function testHarpoonsLeftRight() {
$input = "A \\longLeftrightharpoons L";
$texVC = new TexVC();