From 89c9bb770efb01a292ec6fb3850448c229216f5d Mon Sep 17 00:00:00 2001 From: Stegmujo Date: Tue, 14 Mar 2023 15:57:30 +0100 Subject: [PATCH] Fix gcd, min, max statements * with and without succeeding parentheses * indices in FullCoverageTest: 21,22,33 Bug: T331998 Change-Id: I3a14db18764cc6df9b83249d19ed7de3b6489b1b --- src/TexVC/MMLmappings/BaseParsing.php | 20 ++++++++++++++------ src/TexVC/MMLmappings/Util/MMLutil.php | 7 +++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/TexVC/MMLmappings/BaseParsing.php b/src/TexVC/MMLmappings/BaseParsing.php index b586f5826..c7e9d480f 100644 --- a/src/TexVC/MMLmappings/BaseParsing.php +++ b/src/TexVC/MMLmappings/BaseParsing.php @@ -519,16 +519,24 @@ class BaseParsing { public static function namedOp( $node, $passedArgs, $operatorContent, $name, $id = null ) { if ( !$id ) { - // $id = substr($name,1); eventually change how name is passed $id = $name; } - // This id statement probably wont work atm: + $args = count( $passedArgs ) >= 1 ? $passedArgs : [ "movablelimits" => "true" ]; - // lim inf + $texClass = TexClass::OP; + if ( $name == "min" || $name == "max" || $name === "gcd" ) { + $args["form" ] = "prefix"; + $texClass = ""; + } + $id = str_replace( " ", ' ', $id ); - $mo = new MMLmo( TexClass::OP, $args ); - // "movesupsub"=>"true" activate this also as attribute ? - return $mo->encapsulateRaw( $id ); + $mo = new MMLmo( $texClass, $args ); + $ret = $mo->encapsulateRaw( $id ); + if ( $operatorContent == "(" ) { + $moOp = new MMLmo( "", [ "stretchy" => "false" ] ); + $ret .= $moOp->encapsulateRaw( "(" ); + } + return $ret; } public static function over( $node, $passedArgs, $operatorContent, $name, $id = null ) { diff --git a/src/TexVC/MMLmappings/Util/MMLutil.php b/src/TexVC/MMLmappings/Util/MMLutil.php index 56afdb6ee..e26105ec3 100644 --- a/src/TexVC/MMLmappings/Util/MMLutil.php +++ b/src/TexVC/MMLmappings/Util/MMLutil.php @@ -10,6 +10,7 @@ use IntlChar; class MMLutil { /** * Splits a regular expression in the form '\operatorname {someparams} + * Also recognizes succeeding parentheses '\operatorname (' as params * @param string $input tex expression * @return array|null found groups or null */ @@ -17,6 +18,12 @@ class MMLutil { $pattern = "/([\\a-zA-Z\s]+)\{([^}]+)\}/"; $matches = []; $matched = preg_match_all( $pattern, $input, $matches ); + if ( $matched ) { + return $matches; + } + $pattern2 = "/([\\a-zA-Z\s]+)(\()/"; + $matches = []; + $matched = preg_match_all( $pattern2, $input, $matches ); return $matched ? $matches : null; }