| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types = 1 ); |
| 4 |
|
| 5 |
namespace MediaWiki\Extension\Math\WikiTexVC\Nodes; |
| 6 |
|
| 7 |
class Declh extends TexNode { |
| 8 |
|
| 9 |
|
| 10 |
private $fname; |
| 11 |
|
| 12 |
private $arg; |
| 13 |
|
| 14 |
public function __construct( string $fname, TexArray $arg ) { |
| 15 |
parent::__construct( $fname, $arg ); |
| 16 |
$this->fname = $fname; |
| 17 |
$this->arg = $arg; |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public function getFname(): string { |
| 24 |
return $this->fname; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public function getArg(): TexArray { |
| 31 |
return $this->arg; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
public function inCurlies() { |
| 36 |
return $this->render(); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
public function render() { |
| 41 |
return '{' . $this->fname . ' ' . $this->arg->inCurlies() . '}'; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
public function renderMML( $arguments = [], &$state = [] ) { |
| 46 |
return $this->parseToMML( $this->fname, $arguments, null ); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
public function extractIdentifiers( $args = null ) { |
| 51 |
if ( $args == null ) { |
| 52 |
$args = [ $this->arg ]; |
| 53 |
} |
| 54 |
|
| 55 |
$identifier = parent::extractIdentifiers( $args ); |
| 56 |
if ( isset( $identifier[0] ) ) { |
| 57 |
return [ implode( '', $identifier ) ]; |
| 58 |
} |
| 59 |
return $identifier; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
public function extractSubscripts() { |
| 64 |
$f = $this->fname; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
switch ( $f ) { |
| 70 |
case '\\rm': |
| 71 |
$f = '\\mathrm'; |
| 72 |
break; |
| 73 |
case '\\it': |
| 74 |
$f = '\\mathit'; |
| 75 |
break; |
| 76 |
case '\\cal': |
| 77 |
$f = '\\mathcal'; |
| 78 |
break; |
| 79 |
case '\\bf': |
| 80 |
$f = '\\mathbf'; |
| 81 |
} |
| 82 |
|
| 83 |
$x = $this->arg->extractSubscripts(); |
| 84 |
if ( isset( $x[0] ) ) { |
| 85 |
return [ $f . '{' . $x . '}' ]; |
| 86 |
} |
| 87 |
return parent::extractSubscripts(); |
| 88 |
} |
| 89 |
|
| 90 |
} |