Fix parsing macros in mbox for TexUtilTest

* testindices 638 to 654 and 13

Bug: T327392

Change-Id: I1c83290f50f3fe7ee7e512574150d6be9723b3e7
This commit is contained in:
Stegmujo 2023-02-07 13:49:43 +00:00
parent 39c400a431
commit 78b7769149
No known key found for this signature in database
GPG key ID: BB616B7CC84186BE
3 changed files with 40 additions and 26 deletions

View file

@ -593,6 +593,25 @@ class BaseMappings {
"mmlToken" => 'MmlToken'
];
private const NULLARYMACROS = [
"AA" => "\u00C5",
"Coppa" => "\u03D8",
"Digamma" => "\u03DC",
"Koppa" => "\u03DE",
"Sampi" => "\u03E0",
"Stigma" => "\u03DA",
"coppa" => "\u03D9",
"euro" => "\u20AC",
"geneuro" => "\u20AC",
"geneuronarrow" => "\u20AC",
"geneurowide" => "\u20AC",
"koppa" => "\u03DF",
"officialeuro" => "\u20AC",
"sampi" => "\u03E1",
"stigma" => "\u03DB",
"textvisiblespace" => "\u2423"
];
private const ENVIRONMENT = [
"array" => [ 'AlignedArray' ],
"equation" => [ 'Equation', null, true ],
@ -839,4 +858,8 @@ class BaseMappings {
public static function getDelimiterByKey( $key ) {
return MMLutil::getMappingByKey( $key, self::DELIMITER, true );
}
public static function getNullaryMacro( $key ) {
return MMLutil::getMappingByKey( $key, self::NULLARYMACROS, true );
}
}

View file

@ -792,20 +792,18 @@ class BaseParsing {
public static function hBox( $node, $passedArgs, $operatorContent, $name, $smth = null ) {
switch ( $name ) {
case "mbox":
// These seem special case for mbox, otherwise mbox parsed like hbox
if ( $operatorContent == "\\textvisiblespace" ) {
// there is also custom mapping for now to that,
// for TexUtilMMLTest this seems to only occur here though
$mo = new MMLmo();
$mmlMrow = new MMLmrow();
if ( $operatorContent != null ) {
$op = MMLutil::inputPreparation( $operatorContent );
$macro = BaseMappings::getNullaryMacro( $op );
$input = $macro[0] ?? $operatorContent;
return $mmlMrow->encapsulateRaw( $mo->encapsulateRaw( $input ) );
} else {
$mmlMrow = new MMLmrow();
$mtext = new MMLmtext();
return $mmlMrow->encapsulateRaw( $mtext->encapsulateRaw( "␣" ) );
} elseif ( $operatorContent != null ) { // ok ?? \\AA \\Coppa ....
$mmlMrow = new MMLmrow();
$mtext = new MMLmtext( "", [ "mathcolor" => "red" ] );
return $mmlMrow->encapsulateRaw( $mtext->encapsulateRaw( $operatorContent ) );
return $mmlMrow->encapsulateRaw( $mtext->encapsulateRaw( "\mbox" ) );
}
// no break
case "hbox":
$mmlMrow = new MMLmrow();
$mstyle = new MMLmstyle( "", [ "displaystyle" => "false", "scriptlevel" => "0" ] );

View file

@ -4,6 +4,9 @@ declare( strict_types = 1 );
namespace MediaWiki\Extension\Math\TexVC\Nodes;
use MediaWiki\Extension\Math\TexVC\MMLnodes\MMLmrow;
use MediaWiki\Extension\Math\TexVC\MMLnodes\MMLmtext;
class Box extends TexNode {
/** @var string */
@ -40,21 +43,11 @@ class Box extends TexNode {
}
public function renderMML( $arguments = [] ) {
return $this->parseToMML( $this->getArgs()[0], $arguments, null );
/**
* $mrow = new MMLmrow();
* $mtext = new MMLmtext();
*
* $renderedMML = $mrow->encapsulate(
* $mtext->encapsulate( $this->arg )
* );
* $color = BaseMappings::getColorByKey($this->arg);
* if($color){
* $mstyle = new MMLmstyle();
* $renderedMML = $renderedMML . $mstyle->getEnd();
* }
* return $renderedMML;
*/
$mrow = new MMLmrow();
$mtext = new MMLmtext();
return $mrow->encapsulateRaw(
$mtext->encapsulateRaw( $this->getArg() )
);
}
public function extractIdentifiers( $args = null ) {