Debian Codegraph @

extensions/Math/src/WikiTexVC/Nodes/UQ.php

raw symbols SCIP
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace MediaWiki\Extension\Math\WikiTexVC\Nodes;
6
7 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmi;
8 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmover;
9 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow;
10 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsup;
11 use MediaWiki\Extension\Math\WikiTexVC\TexUtil;
12
13 class UQ extends TexNode {
14
15 /** @var TexNode */
16 private $base;
17 /** @var TexNode */
18 private $up;
19
20 public function __construct( TexNode $base, TexNode $up ) {
21 parent::__construct( $base, $up );
22 $this->base = $base;
23 $this->up = $up;
24 }
25
26 /**
27 * @return TexNode
28 */
29 public function getBase(): TexNode {
30 return $this->base;
31 }
32
33 /**
34 * @return TexNode
35 */
36 public function getUp(): TexNode {
37 return $this->up;
38 }
39
40 /** @inheritDoc */
41 public function render() {
42 return $this->base->render() . '^' . $this->up->inCurlies();
43 }
44
45 /** @inheritDoc */
46 public function renderMML( $arguments = [], &$state = [] ) {
47 $mrow = new MMLmrow();
48 $mmlBase = new MMLmsup();
49 $base = $this->getBase();
50 $up = $this->getUp();
51
52 $tu = TexUtil::getInstance();
53
54 if ( $base instanceof Fun1 && $tu->over_operator( $base->getFname() ) ) {
55 $mmlBase = new MMLmover();
56 }
57
58 // If the superscript has empty elements, render them with empty mi elements to prevent browser issues
59 $mi = new MMLmi();
60 if ( $base instanceof TexArray && $base->getLength() == 0 ) {
61 $baseRendered = $mi->getEmpty();
62 } else {
63 $baseRendered = $base->renderMML( $arguments, $state );
64 }
65 if ( $up instanceof TexArray && $up->getLength() == 0 ) {
66 $upRendered = $mi->getEmpty();
67 } else {
68 // up is inferring a new mrow if it has some content
69 $upRendered = $mrow->encapsulateRaw( $up->renderMML( $arguments, $state ) );
70 }
71
72 return $mmlBase->encapsulateRaw( $baseRendered . $upRendered );
73 }
74
75 }