Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace MediaWiki\Extension\Math\WikiTexVC\Nodes;
6
7 class Declh extends TexNode {
8
9 /** @var string */
10 private $fname;
11 /** @var TexArray */
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 * @return string
22 */
23 public function getFname(): string {
24 return $this->fname;
25 }
26
27 /**
28 * @return TexArray
29 */
30 public function getArg(): TexArray {
31 return $this->arg;
32 }
33
34 /** @inheritDoc */
35 public function inCurlies() {
36 return $this->render();
37 }
38
39 /** @inheritDoc */
40 public function render() {
41 return '{' . $this->fname . ' ' . $this->arg->inCurlies() . '}';
42 }
43
44 /** @inheritDoc */
45 public function renderMML( $arguments = [], &$state = [] ) {
46 return $this->parseToMML( $this->fname, $arguments, null );
47 }
48
49 /** @inheritDoc */
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 /** @inheritDoc */
63 public function extractSubscripts() {
64 $f = $this->fname;
65 // @see
66 // http://tex.stackexchange.com/questions/98406/which-command-should-i-use-for-textual-subscripts-in-math-mode
67 // cf https://phabricator.wikimedia.org/T56818 a is always RM
68 // for f there are only four cases
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 }