From 87f03158129bece5caa6dba5c0062327d175a78b Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Sat, 12 Oct 2024 23:59:22 +0200 Subject: [PATCH] Use the same formatting for align as MathJax * Copy the default mtable attributes from MathJax * Adjust the test Bug: T348791 Bug: T375317 Change-Id: I274577e320056c1ac3a1f74cbc61941184afd61e --- src/WikiTexVC/MMLmappings/BaseParsing.php | 13 ++----------- src/WikiTexVC/MMLnodes/MMLmtable.php | 11 ++++++++++- tests/phpunit/unit/WikiTexVC/MMLRenderTest.php | 4 +++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/WikiTexVC/MMLmappings/BaseParsing.php b/src/WikiTexVC/MMLmappings/BaseParsing.php index c5fcf4dd4..ada6ccd4b 100644 --- a/src/WikiTexVC/MMLmappings/BaseParsing.php +++ b/src/WikiTexVC/MMLmappings/BaseParsing.php @@ -122,10 +122,7 @@ class BaseParsing { $smth2 = null ) { // Parsing is very similar to AmsEQArray, maybe extract function ... tcs: 178 $mrow = new MMLmrow(); - // tbd how are the table args composed ? - $tableArgs = [ "columnalign" => "right", - "columnspacing" => "0em", "displaystyle" => "true", "rowspacing" => "3pt" ]; - $mtable = new MMLmtable( "", $tableArgs ); + $mtable = new MMLmtable( "" ); $mtr = new MMLmtr(); $mtd = new MMLmtd(); $renderedInner = ""; @@ -141,14 +138,8 @@ class BaseParsing { } public static function amsEqnArray( $node, $passedArgs, $operatorContent, $name, $smth, $smth2 = null ) { - // this goes for name =="aligned" ... tcs: 358 420 421 $mrow = new MMLmrow(); - // tbd how are the table args composed ? - - $direction = ( $name == "aligned" ) ? "left" : "right"; - $tableArgs = [ "columnalign" => $direction, - "columnspacing" => "0em", "displaystyle" => "true", "rowspacing" => "3pt" ]; - $mtable = new MMLmtable( "", $tableArgs ); + $mtable = new MMLmtable( '' ); $mtr = new MMLmtr(); $mtd = new MMLmtd(); $renderedInner = ""; diff --git a/src/WikiTexVC/MMLnodes/MMLmtable.php b/src/WikiTexVC/MMLnodes/MMLmtable.php index e7f847661..b557d0f28 100644 --- a/src/WikiTexVC/MMLnodes/MMLmtable.php +++ b/src/WikiTexVC/MMLnodes/MMLmtable.php @@ -12,7 +12,16 @@ use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\TexClass; */ class MMLmtable extends MMLbase { - public function __construct( string $texclass = TexClass::ORD, array $attributes = [] ) { + /** defaults to mtable args as generated from MathJax for align(ed) environment + */ + public function __construct( + string $texclass = TexClass::ORD, + array $attributes = [ + 'columnalign' => 'right left right left right left right left right left right left', + 'columnspacing' => '0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em', + 'displaystyle' => 'true', + 'rowspacing' => '3pt' + ] ) { parent::__construct( "mtable", $texclass, $attributes ); } } diff --git a/tests/phpunit/unit/WikiTexVC/MMLRenderTest.php b/tests/phpunit/unit/WikiTexVC/MMLRenderTest.php index 5ec1e46d2..911469200 100644 --- a/tests/phpunit/unit/WikiTexVC/MMLRenderTest.php +++ b/tests/phpunit/unit/WikiTexVC/MMLRenderTest.php @@ -163,7 +163,9 @@ class MMLRenderTest extends MediaWikiUnitTestCase { public function testAlignLeft() { $input = " \begin{align} f(x) & = (a+b)^2 \\ & = a^2+2ab+b^2 \\ \\end{align} "; $mathMLtexVC = $this->generateMML( $input ); - $this->assertStringContainsString( "columnalign=\"left\"", $mathMLtexVC ); + $this->assertStringContainsString( "columnalign=\"right left right", $mathMLtexVC ); + $this->assertStringContainsString( "columnspacing=\"0em 2em 0em", $mathMLtexVC ); + $this->assertStringContainsString( "rowspacing=\"3pt\"", $mathMLtexVC ); $this->assertStringContainsString( "mtable", $mathMLtexVC ); }