| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types = 1 ); |
| 4 |
|
| 5 |
namespace MediaWiki\Extension\Math\WikiTexVC\Nodes; |
| 6 |
|
| 7 |
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseParsing; |
| 8 |
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow; |
| 9 |
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmstyle; |
| 10 |
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsubsup; |
| 11 |
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmunderover; |
| 12 |
use MediaWiki\Extension\Math\WikiTexVC\TexUtil; |
| 13 |
|
| 14 |
class FQ extends TexNode { |
| 15 |
|
| 16 |
|
| 17 |
private $base; |
| 18 |
|
| 19 |
private $up; |
| 20 |
|
| 21 |
private $down; |
| 22 |
|
| 23 |
public function __construct( TexNode $base, TexNode $down, TexNode $up ) { |
| 24 |
parent::__construct( $base, $down, $up ); |
| 25 |
$this->base = $base; |
| 26 |
$this->up = $up; |
| 27 |
$this->down = $down; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function getBase(): TexNode { |
| 34 |
return $this->base; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public function getUp(): TexNode { |
| 41 |
return $this->up; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function getDown(): TexNode { |
| 48 |
return $this->down; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
public function render() { |
| 53 |
return $this->base->render() . '_' . $this->down->inCurlies() . '^' . $this->up->inCurlies(); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
public function renderMML( $arguments = [], &$state = [] ) { |
| 58 |
if ( array_key_exists( "limits", $state ) ) { |
| 59 |
|
| 60 |
return BaseParsing::limits( $this, $arguments, $state, "" ); |
| 61 |
} |
| 62 |
$base = $this->getBase(); |
| 63 |
|
| 64 |
if ( $base->getLength() == 0 && !$base->isCurly() ) { |
| 65 |
|
| 66 |
$mrow = new MMLmrow(); |
| 67 |
return $mrow->encapsulateRaw( $this->getDown()->renderMML( [], $state ) ) . |
| 68 |
$mrow->encapsulateRaw( $this->getUp()->renderMML( [], $state ) ); |
| 69 |
} |
| 70 |
|
| 71 |
$melement = new MMLmsubsup(); |
| 72 |
|
| 73 |
if ( $base instanceof Literal ) { |
| 74 |
$litArg = trim( $base->getArgs()[0] ); |
| 75 |
$tu = TexUtil::getInstance(); |
| 76 |
|
| 77 |
if ( $tu->nullary_macro( $litArg ) && |
| 78 |
!$tu->is_literal( $litArg ) && |
| 79 |
|
| 80 |
( $state['styleargs']['displaystyle'] ?? 'true' ) === 'true' |
| 81 |
) { |
| 82 |
$melement = new MMLmunderover(); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
$mrow = new MMLmrow(); |
| 87 |
$emptyMrow = ""; |
| 88 |
|
| 89 |
if ( $base->isCurly() && $base->isEmpty() ) { |
| 90 |
$emptyMrow = $mrow->getEmpty(); |
| 91 |
} |
| 92 |
|
| 93 |
$inner = $melement->encapsulateRaw( |
| 94 |
$emptyMrow . |
| 95 |
$base->renderMML( [], $state ) . |
| 96 |
$mrow->encapsulateRaw( $this->getDown()->renderMML( $arguments, $state ) ) . |
| 97 |
$mrow->encapsulateRaw( $this->getUp()->renderMML( $arguments, $state ) ) ); |
| 98 |
|
| 99 |
if ( $melement instanceof MMLmunderover ) { |
| 100 |
$args = $state['styleargs'] ?? [ "displaystyle" => "true", "scriptlevel" => 0 ]; |
| 101 |
$style = new MMLmstyle( "", $args ); |
| 102 |
return $style->encapsulateRaw( $inner ); |
| 103 |
} |
| 104 |
|
| 105 |
return $inner; |
| 106 |
} |
| 107 |
} |