From 95816376c12c60f17c6b135fae2cca55e912b22e Mon Sep 17 00:00:00 2001 From: Stegmujo Date: Thu, 16 Mar 2023 15:40:49 +0000 Subject: [PATCH] Fix spaces defined by tilde and backslash * MMLFullCoverageTest case: 261 Bug: T327391 Change-Id: I99def9fe47ceb4471826e96e25562c070c0f1303 --- src/TexVC/MMLmappings/BaseMappings.php | 37 +++++++++++--------- src/TexVC/MMLmappings/BaseMethods.php | 9 +++-- src/TexVC/MMLmappings/BaseParsing.php | 5 +++ src/TexVC/MMLmappings/OperatorDictionary.php | 2 +- src/TexVC/Nodes/Literal.php | 1 + 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/TexVC/MMLmappings/BaseMappings.php b/src/TexVC/MMLmappings/BaseMappings.php index daf52b458..7f9773cfb 100644 --- a/src/TexVC/MMLmappings/BaseMappings.php +++ b/src/TexVC/MMLmappings/BaseMappings.php @@ -18,21 +18,21 @@ class BaseMappings { // Macro Map 'special' private const SPECIAL = [ - '{' => 'Open', - '}' => 'Close', - '~' => 'Tilde', - '^' => 'Superscript', - '_' => 'Subscript', - ' ' => 'Space', - '\t' => 'Space', - '\r' => 'Space', - '\n' => 'Space', - '\\' => 'Prime', - '%' => 'Comment', - '&' => 'Entry', - '#' => 'Hash', - '\u00A0' => 'Space', - '\u2019' => 'Prime' + '{' => 'open', + '}' => 'close', + '~' => [ 'tilde',true ], + '^' => 'superscript', + '_' => 'subscript', + ' ' => 'space', + '\t' => 'space', + '\r' => 'space', + '\n' => 'space', + '\\' => 'prime', + '%' => 'comment', + '&' => 'entry', + '#' => 'hash', + '\u00A0' => 'space', + '\u2019' => 'prime' ]; private const MATHCHAR0MI = [ @@ -831,7 +831,12 @@ class BaseMappings { } public static function getSpecialByKey( $key ) { - return MMLutil::getMappingByKeySimple( $key, self::SPECIAL ); + $ret = MMLutil::getMappingByKeySimple( $key, self::SPECIAL ); + // Only activated elements get found in this mapping currently. + if ( is_array( $ret ) && count( $ret ) >= 2 && $ret[1] ) { + return $ret; + } + return null; } public static function getCancelByKey( $key ) { diff --git a/src/TexVC/MMLmappings/BaseMethods.php b/src/TexVC/MMLmappings/BaseMethods.php index 1a0d1e125..3e90283d7 100644 --- a/src/TexVC/MMLmappings/BaseMethods.php +++ b/src/TexVC/MMLmappings/BaseMethods.php @@ -47,7 +47,10 @@ class BaseMethods { if ( $resFct == null ) { $resFct = BaseMappings::getCustomByKey( $input ); if ( $resFct == null ) { - $resFct = BaseMappings::getMhChemByKey( $input ); + $resFct = BaseMappings::getSpecialByKey( $input ); + if ( $resFct == null ) { + $resFct = BaseMappings::getMhChemByKey( $input ); + } } } } @@ -130,7 +133,9 @@ class BaseMethods { case ">": $mmlMo = new MMLmo(); return $mmlMo->encapsulate( ">" ); - + case "\\": + $mmlMtext = new MMLmtext(); + return $mmlMtext->encapsulate( " " ); } return $input; } diff --git a/src/TexVC/MMLmappings/BaseParsing.php b/src/TexVC/MMLmappings/BaseParsing.php index fbe2ebdb1..235a99252 100644 --- a/src/TexVC/MMLmappings/BaseParsing.php +++ b/src/TexVC/MMLmappings/BaseParsing.php @@ -949,6 +949,11 @@ class BaseParsing { ); } + public static function tilde( $node, $passedArgs, $operatorContent, $name ) { + $mText = new MMLmtext( "", $passedArgs ); + return $mText->encapsulate( " " ); + } + public static function xArrow( $node, $passedArgs, $operatorContent, $name, $chr = null, $l = null, $r = null ) { $defWidth = "+" . MMLutil::round2em( ( $l + $r ) / 18 ); $defLspace = MMLutil::round2em( $l / 18 ); diff --git a/src/TexVC/MMLmappings/OperatorDictionary.php b/src/TexVC/MMLmappings/OperatorDictionary.php index 2f0b814a8..1d3eb8179 100644 --- a/src/TexVC/MMLmappings/OperatorDictionary.php +++ b/src/TexVC/MMLmappings/OperatorDictionary.php @@ -48,7 +48,7 @@ class OperatorDictionary { '>=' => [ " exports.MO.BIN5" ], '?' => [ " [1, 1], MmlNode_js_1.TEXCLASS.CLOSE], null]" ], '@' => [ " exports.MO.ORD11" ], - '\\' => [ " exports.MO.ORD" ], + '\\' => [ " exports.MO.ORD", true ], '^' => [ " exports.MO.ORD11" ], '_' => [ " exports.MO.ORD11" ], '|' => [ " [2, 2], MmlNode_js_1.TEXCLASS.ORD]," . diff --git a/src/TexVC/Nodes/Literal.php b/src/TexVC/Nodes/Literal.php index f784108c7..19b1e2385 100644 --- a/src/TexVC/Nodes/Literal.php +++ b/src/TexVC/Nodes/Literal.php @@ -94,6 +94,7 @@ class Literal extends TexNode { // No mi, if literal is from HBox return $input; } + // If falling through all sieves just create an MI element $mi = new MMLmi( "", $arguments ); return $mi->encapsulateRaw( $input ); // $this->arg