Add state array to MathML rendering tree

For conditional rendering a state variable is needed.

Change-Id: Iac1a1058fecf89c58a02ca3b643e973b4742f51f
This commit is contained in:
Moritz Schubotz (physikerwelt) 2023-02-15 10:39:23 +01:00
parent f760f896b2
commit 6efbf4dd00
No known key found for this signature in database
GPG key ID: F803DB146DDF36C3
17 changed files with 34 additions and 32 deletions

View file

@ -39,7 +39,7 @@ class Big extends TexNode {
return '{' . $this->fname . ' ' . $this->arg . '}';
}
public function renderMML( $arguments = [] ): string {
public function renderMML( $arguments = [], $state = [] ): string {
return $this->parseToMML( $this->fname, $arguments, null );
}

View file

@ -42,7 +42,7 @@ class Box extends TexNode {
return '{' . $this->fname . '{' . $this->arg . '}}';
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
$mrow = new MMLmrow();
$mtext = new MMLmtext();
return $mrow->encapsulateRaw(

View file

@ -38,14 +38,16 @@ class ChemWord extends TexNode {
return $this->left->render() . $this->right->render();
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
$mmlMrow = new MMLmrow();
$mtextLeft = new MMLmtext( "", [ "mathcolor" => "red" ] );
$mtextRight = new MMLmtext();
// If right has empty literal content is resolved as dash
$right = $this->getRight()->getArgs()[0] == "" ? "-" : $this->getRight()->renderMML();
$right = $this->getRight()->getArgs()[0] == "" ? "-" : $this->getRight()->renderMML( [],
$state );
return $mmlMrow->encapsulateRaw( $mmlMrow->encapsulateRaw(
$mtextLeft->encapsulateRaw( $this->getLeft()->renderMML() ) . $mtextRight->encapsulateRaw( $right ) ) );
$mtextLeft->encapsulateRaw( $this->getLeft()->renderMML( [], $state ) )
. $mtextRight->encapsulateRaw( $right ) ) );
}
public function extractIdentifiers( $args = null ) {

View file

@ -25,11 +25,11 @@ class Curly extends TexNode {
return $this->arg->inCurlies();
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
// J4T set17
//$mmlRow = new MMLmrow();
//return $mmlRow->encapsulate(parent::renderMML($arguments));
return parent::renderMML( $arguments );
return parent::renderMML( $arguments, $state );
}
public function inCurlies() {

View file

@ -38,7 +38,7 @@ class DQ extends TexNode {
return $this->base->render() . '_' . $this->down->inCurlies();
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
$res = BaseMethods::checkAndParse( $this->base->getArgs()[0], $arguments, null, $this );
if ( $res ) {
return $res;
@ -47,8 +47,8 @@ class DQ extends TexNode {
$mmlMrow = new MMLmrow();
$msub = new MMLmsub();
return $msub->encapsulateRaw(
$this->base->renderMML() .
$mmlMrow->encapsulateRaw( $this->down->renderMML() ) );
$this->base->renderMML( [], $state ) .
$mmlMrow->encapsulateRaw( $this->down->renderMML( [], $state ) ) );
}
}

View file

@ -39,7 +39,7 @@ class Declh extends TexNode {
return '{' . $this->fname . ' ' . $this->arg->inCurlies() . '}';
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
return $this->parseToMML( $this->fname, $arguments, null );
}

View file

@ -50,13 +50,13 @@ class FQ extends TexNode {
return $this->base->render() . '_' . $this->down->inCurlies() . '^' . $this->up->inCurlies();
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
$bm = new BaseMethods();
if ( $this->getArgs()[0]->getLength() == 0 ) {
// this happens when FQ is located in Sideset (is this a common parsing way?)
$mrow = new MMLmrow();
return $mrow->encapsulateRaw( $this->getDown()->renderMML() ) .
$mrow->encapsulateRaw( $this->getUp()->renderMML() );
return $mrow->encapsulateRaw( $this->getDown()->renderMML( [], $state ) ) .
$mrow->encapsulateRaw( $this->getUp()->renderMML( [], $state ) );
}
// Not sure if this case is necessary ..
@ -76,8 +76,8 @@ class FQ extends TexNode {
// This seems to be the common case
$mrow = new MMLmrow();
return $melement->encapsulateRaw(
$this->getBase()->renderMML() .
$mrow->encapsulateRaw( $this->getDown()->renderMML() ) .
$mrow->encapsulateRaw( $this->getUp()->renderMML() ) );
$this->getBase()->renderMML( [], $state ) .
$mrow->encapsulateRaw( $this->getDown()->renderMML( [], $state ) ) .
$mrow->encapsulateRaw( $this->getUp()->renderMML( [], $state ) ) );
}
}

View file

@ -47,7 +47,7 @@ class Fun1 extends TexNode {
return '{' . $this->fname . ' ' . $this->arg->inCurlies() . '}';
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
return $this->parseToMML( $this->fname, $arguments, null );
}

View file

@ -14,7 +14,7 @@ class Fun1nb extends Fun1 {
return $this->fname . ' ' . $this->arg->inCurlies() . ' ';
}
public function renderMML( $arguments = [] ): string {
public function renderMML( $arguments = [], $state = [] ): string {
return $this->parseToMML( $this->fname, $arguments, null );
// This is very preliminary and should most probably be synced with the mappings from time to time
// this might move to Fun1.php

View file

@ -49,7 +49,7 @@ class Fun2 extends TexNode {
return '{' . $this->fname . ' ' . $this->arg1->inCurlies() . $this->arg2->inCurlies() . '}';
}
public function renderMML( $arguments = [] ): string {
public function renderMML( $arguments = [], $state = [] ): string {
return $this->parseToMML( $this->fname, $arguments, null );
}

View file

@ -51,7 +51,7 @@ class Infix extends TexNode {
$this->arg2->render() . '}';
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
return $this->parseToMML( $this->op, $arguments, null );
}

View file

@ -25,7 +25,7 @@ class Literal extends TexNode {
array_push( $this->extendedLiterals, '\\infty', '\\emptyset' );
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
if ( is_numeric( $this->arg ) ) {
$mn = new MMLmn( "", $arguments );
return $mn->encapsulateRaw( $this->arg );

View file

@ -54,7 +54,7 @@ class Lr extends TexNode {
return '\\left' . $this->left . $this->arg->render() . '\\right' . $this->right;
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
// TBD set attributes for right AND left correctly
$rightAttrs = [];
if ( $this->right == "." ) {
@ -75,7 +75,7 @@ class Lr extends TexNode {
$right = $moRight->encapsulateRaw( $this->right );
}
$inner = $this->getArg()->renderMML();
$inner = $this->getArg()->renderMML( [], $state );
$mrow = new MMLmrow( TexClass::INNER );
return $mrow->encapsulateRaw(
$left . $inner .

View file

@ -62,7 +62,7 @@ class Matrix extends TexNode {
return '{\\begin{' . $this->top . '}' . $this->renderMatrix( $this->mainarg ) . '\\end{' . $this->top . '}}';
}
public function renderMML( $arguments = [] ): string {
public function renderMML( $arguments = [], $state = [] ): string {
return $this->parseToMML( $this->getTop(), $arguments, null );
}

View file

@ -39,7 +39,7 @@ class TexArray extends TexNode {
return null;
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
// Everything here is for parsing displaystyle, probably refactored to TexVC grammar later
$fullRenderedArray = "";
$mmlStyle = null;
@ -57,13 +57,13 @@ class TexArray extends TexNode {
$mmlStyle = new MMLmstyle( "", $styleArguments );
$fullRenderedArray .= $mmlStyle->getStart();
if ( $next instanceof Curly ) {
$fullRenderedArray .= $next->renderMML( $arguments );
$fullRenderedArray .= $next->renderMML( $arguments, $state );
$fullRenderedArray .= $mmlStyle->getEnd();
$mmlStyle = null;
$i++;
}
} else {
$fullRenderedArray .= $current->renderMML( $arguments );
$fullRenderedArray .= $current->renderMML( $arguments, $state );
}
}
if ( $mmlStyle ) {

View file

@ -50,7 +50,7 @@ class TexNode {
return $out;
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
return array_reduce( $this->args, function ( $out, $child ) use ( $arguments ) {
return $out . $this->renderChildMML( $child, $arguments );
}, '' );

View file

@ -39,7 +39,7 @@ class UQ extends TexNode {
return $this->base->render() . '^' . $this->up->inCurlies();
}
public function renderMML( $arguments = [] ) {
public function renderMML( $arguments = [], $state = [] ) {
$mrow = new MMLmrow();
$mmlBase = new MMLmsup();
// Sometimes 'overbrace' or similar seems to determine the wrapping element here.
@ -47,9 +47,9 @@ class UQ extends TexNode {
$mmlBase = new MMLmover();
}
return $mmlBase->encapsulateRaw(
$this->base->renderMML( $arguments ) .
$this->base->renderMML( $arguments, $state ) .
$mrow->getStart() . // up is inferring a new mrow
$this->up->renderMML( $arguments ) .
$this->up->renderMML( $arguments, $state ) .
$mrow->getEnd()
);
}