From 78b7769149ac5b40b6e50f0646cefbd513e4204e Mon Sep 17 00:00:00 2001 From: Stegmujo Date: Tue, 7 Feb 2023 13:49:43 +0000 Subject: [PATCH] Fix parsing macros in mbox for TexUtilTest * testindices 638 to 654 and 13 Bug: T327392 Change-Id: I1c83290f50f3fe7ee7e512574150d6be9723b3e7 --- src/TexVC/MMLmappings/BaseMappings.php | 23 +++++++++++++++++++++++ src/TexVC/MMLmappings/BaseParsing.php | 20 +++++++++----------- src/TexVC/Nodes/Box.php | 23 ++++++++--------------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/TexVC/MMLmappings/BaseMappings.php b/src/TexVC/MMLmappings/BaseMappings.php index 3bd737360..3b3be7bf8 100644 --- a/src/TexVC/MMLmappings/BaseMappings.php +++ b/src/TexVC/MMLmappings/BaseMappings.php @@ -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 ); + } } diff --git a/src/TexVC/MMLmappings/BaseParsing.php b/src/TexVC/MMLmappings/BaseParsing.php index ac5c35026..2fc8680d5 100644 --- a/src/TexVC/MMLmappings/BaseParsing.php +++ b/src/TexVC/MMLmappings/BaseParsing.php @@ -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" ] ); diff --git a/src/TexVC/Nodes/Box.php b/src/TexVC/Nodes/Box.php index 4235273fc..52c5e72d8 100644 --- a/src/TexVC/Nodes/Box.php +++ b/src/TexVC/Nodes/Box.php @@ -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 ) {