Fix Parsing of Mod elements with and without params

* some adaptions to test and comparator
* minor fix in mappings for ncong
* introduce a LaTeXML Fallback for the tex-cases:
** "\ce{\ca}"
** "\mod"

Bug: T327392

Change-Id: Ie2efa392bd517a28fe8b6e8d0cecdba64cd1c415
This commit is contained in:
Stegmujo 2023-02-07 10:34:48 +00:00
parent 9a365685ce
commit 39c400a431
4 changed files with 21 additions and 17 deletions

View file

@ -232,7 +232,7 @@ class AMSMappings {
"precnapprox" => '\u2AB9',
"succnapprox" => '\u2ABA',
"nsim" => '\u2241',
"ncong" => '\u2247',
"ncong" => '\u2246',
"nshortmid" => [ '\u2224', [ "variantForm" => true ] ],
"nshortparallel" => [ '\u2226', [ "variantForm" => true ] ],
"nmid" => '\u2224',

View file

@ -37,6 +37,7 @@ use MediaWiki\Extension\Math\TexVC\Nodes\Fun1nb;
use MediaWiki\Extension\Math\TexVC\Nodes\Fun2sq;
use MediaWiki\Extension\Math\TexVC\Nodes\Literal;
use MediaWiki\Extension\Math\TexVC\Nodes\TexArray;
use MediaWiki\Extension\Math\TexVC\Nodes\TexNode;
/**
* Parsing functions for specific recognized mappings.
@ -342,14 +343,9 @@ class BaseParsing {
switch ( $name ) {
case "mod":
$mmlRow = new MMLmrow();
$mspace = new MMLmspace( "", [ "width" => "0.444em" ] );
$mspace2 = new MMLmspace( "", [ "width" => "0.333em" ] );
$mo = new MMLmo( "", [ "stretchy" => "false" ] );
$mi = new MMLmi();
return $mmlRow->encapsulateRaw(
$mspace->encapsulate() . $mo->encapsulate( "(" ) .
$mi->encapsulate( "mod" ) . $mspace2->encapsulate( "" ) .
$mo->encapsulate( ")" ) );
$mo = new MMLmo( "", [ "lspace" => "2.5pt", "rspace" => "2.5pt" ] );
$inner = $node->getArg() instanceof TexNode ? $node->getArg()->renderMML() : "";
return $mmlRow->encapsulateRaw( $mo->encapsulate( "mod" ) . $inner );
case "pmod":
// tbd indicate in mapping that this is composed within php
$mmlRow = new MMLmrow();
@ -357,9 +353,11 @@ class BaseParsing {
$mspace2 = new MMLmspace( "", [ "width" => "0.333em" ] );
$mo = new MMLmo( "", [ "stretchy" => "false" ] );
$mi = new MMLmi();
$inner = $node->getArg() instanceof TexNode ? $node->getArg()->renderMML() : "";
return $mmlRow->encapsulateRaw( $mspace->encapsulate() .
$mo->encapsulate( "(" ) . $mi->encapsulate( "mod" ) .
$mspace2->encapsulate() . $node->getArg()->renderMML() . $mo->encapsulate( ")" ) );
$mspace2->encapsulate() . $inner . $mo->encapsulate( ")" ) );
case "varlimsup":
case "varliminf":
// hardcoded macro in php (there is also a dynamic mapping which is not completely resolved atm)
@ -409,8 +407,10 @@ class BaseParsing {
$mmlRow = new MMLmrow( TexClass::ORD );
$mstyle = new MMLmstyle( "", [ "scriptlevel" => "0" ] );
$mspace = new MMLmspace( "", [ "width" => "0.167em" ] );
$inner = $node->getArg() instanceof TexNode ?
$mmlRow->encapsulateRaw( $node->getArg()->renderMML() ) : "";
return $mmlRow->encapsulateRaw( $mo->encapsulate( "mod" ) .
$mmlRow->encapsulateRaw( $mstyle->encapsulateRaw( $mspace->getEmpty() ) ) );
$inner . $mmlRow->encapsulateRaw( $mstyle->encapsulateRaw( $mspace->getEmpty() ) ) );
case "implies":
$mstyle = new MMLmstyle( "", [ "scriptlevel" => "0" ] );
$mspace = new MMLmspace( "", [ "width" => "0.278em" ] );

View file

@ -18,6 +18,8 @@ class MMLComparator {
private const IGNOREDELEMENTKEYS = [
"semantics",
"annotation",
"annotation-xml",
"csymbol",
"mrow",
"mstyle"
];
@ -39,7 +41,7 @@ class MMLComparator {
"math" => [ "alttext", "display" ],
"mi" => [ "class", "data-mjx-variant", "mathvariant", "data-mjx-texclass", "data-mjx-alternate" ],
"mo" => [ "data-mjx-pseudoscript", "stretchy", "fence", "data-mjx-texclass", "texClass", "class",
"data-mjx-alternate", "form", "accent" ],
"data-mjx-alternate", "form", "accent", "lspace", "rspace", "xref", "id" ],
"mtext" => [ "texClass" ]
];

View file

@ -65,18 +65,20 @@ class MMLGenerationTexUtilTest extends MediaWikiUnitTestCase {
$mathMLtexVC = MMLTestUtil::getMMLwrapped( $resultT["input"] ) ?? "<math> error texvc </math>";
$mmlComparator = new MMLComparator();
$compRes = $mmlComparator->compareMathML( $input->mmlMathoid, $mathMLtexVC );
$usedMMLRef = $input->mmlMathoid;
if ( !$usedMMLRef ) {
$usedMMLRef = $input->mmlLaTeXML;
}
$compRes = $mmlComparator->compareMathML( $usedMMLRef, $mathMLtexVC );
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $title, $input->tex, $input->mmlLaTeXML,
$input->mmlMathoid, $mathMLtexVC, $compRes['similarityF'] ], false, self::$GENERATEHTML );
// Comparing the result either to MathML result from Mathoid
if ( !self::$SKIPXMLVALIDATION ) {
if ( !$input->mmlMathoid ) {
$this->fail( "No Mathoid reference found for: " . $input->tex );
}
if ( $compRes['similarityF'] >= self::$SIMILARITYTRESH ) {
$this->assertTrue( true );
} else {
$this->assertXmlStringEqualsXmlString( $input->mmlMathoid, $mathMLtexVC );
$this->assertXmlStringEqualsXmlString( $usedMMLRef, $mathMLtexVC );
}
} else {
$this->assertTrue( true );