From 078193531627accfca1cacd58797682976c0a804 Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Fri, 29 Nov 2024 01:13:15 +0100 Subject: [PATCH] Fix: Don't render ' inside LR structures $\left(a\right)'$ produced rendered MathML output that looked like $\left(a'\right)'$. * Remove the deriv (') state when rendering the element within the brackets. Bug: T381102 Change-Id: Id7f192c1f6b7bf4109e735e393e2546e5a39efd7 --- src/WikiTexVC/Nodes/Lr.php | 3 ++- tests/phpunit/unit/WikiTexVC/Nodes/LrTest.php | 13 +++++++++++++ tests/phpunit/unit/WikiTexVC/Nodes/TexArrayTest.php | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/WikiTexVC/Nodes/Lr.php b/src/WikiTexVC/Nodes/Lr.php index 228066457..89249d63d 100644 --- a/src/WikiTexVC/Nodes/Lr.php +++ b/src/WikiTexVC/Nodes/Lr.php @@ -74,7 +74,8 @@ class Lr extends TexNode { $moRight = new MMLmo( TexClass::CLOSE, $rightAttrs ); $right = $moRight->encapsulateRaw( $this->right ); } - + // Don't apply outer ' inside the LR structure + unset( $state['deriv'] ); $inner = $this->getArg()->renderMML( [], $state ); $mrow = new MMLmrow( TexClass::INNER ); return $mrow->encapsulateRaw( diff --git a/tests/phpunit/unit/WikiTexVC/Nodes/LrTest.php b/tests/phpunit/unit/WikiTexVC/Nodes/LrTest.php index c36e0e165..d621373e1 100644 --- a/tests/phpunit/unit/WikiTexVC/Nodes/LrTest.php +++ b/tests/phpunit/unit/WikiTexVC/Nodes/LrTest.php @@ -56,4 +56,17 @@ class LrTest extends MediaWikiUnitTestCase { 'Should extract identifiers' ); } + public function testRenderA() { + $n = new Lr( '(', ')', new TexArray( new Literal( 'A' ) ) ); + $mml = $n->renderMML(); + $this->assertStringContainsString( 'A', $mml ); + $this->assertStringContainsString( ')', $mml ); + } + + public function testRenderADeriv() { + $n = new Lr( '(', ')', new TexArray( new Literal( 'A' ) ) ); + $mml = $n->renderMML( [], [ 'deriv' => 1 ] ); + $this->assertStringNotContainsString( '′', $mml ); + } + } diff --git a/tests/phpunit/unit/WikiTexVC/Nodes/TexArrayTest.php b/tests/phpunit/unit/WikiTexVC/Nodes/TexArrayTest.php index ab1e3cba4..76d1453db 100644 --- a/tests/phpunit/unit/WikiTexVC/Nodes/TexArrayTest.php +++ b/tests/phpunit/unit/WikiTexVC/Nodes/TexArrayTest.php @@ -151,4 +151,9 @@ class TexArrayTest extends MediaWikiUnitTestCase { $this->assertEquals( $custom, $res[0] ); } + public function testRenderADeriv() { + $n = new TexArray( new Literal( 'A' ) ); + $mml = $n->renderMML( [], [ 'deriv' => 1 ] ); + $this->assertStringContainsString( '′', $mml ); + } }