| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math\Tests\WikiTexVC; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\Tag; |
| 6 |
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\TexClass; |
| 7 |
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\Util\MMLTestUtil; |
| 8 |
use MediaWiki\Extension\Math\WikiTexVC\TexVC; |
| 9 |
use MediaWikiUnitTestCase; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class MMLRenderTest extends MediaWikiUnitTestCase { |
| 18 |
|
| 19 |
public function testMathFRakUnicode() { |
| 20 |
$input = "\\mathfrak{O}, \\mathfrak{K}, \\mathfrak{t}, \\mathfrak{C}"; |
| 21 |
$mathMLtexVC = $this->generateMML( $input ); |
| 22 |
$this->assertStringContainsString( '𝔒', $mathMLtexVC ); |
| 23 |
$this->assertStringContainsString( '𝔎', $mathMLtexVC ); |
| 24 |
$this->assertStringContainsString( '𝔱', $mathMLtexVC ); |
| 25 |
$this->assertStringContainsString( 'ℭ', $mathMLtexVC ); |
| 26 |
} |
| 27 |
|
| 28 |
public function testMathCalUnicode() { |
| 29 |
$input = "\\mathcal{O}, \\mathcal{K}, \\mathcal{t}, \\mathcal{c}"; |
| 30 |
$mathMLtexVC = $this->generateMML( $input ); |
| 31 |
$this->assertStringContainsString( '𝒪', $mathMLtexVC ); |
| 32 |
$this->assertStringContainsString( '𝒦', $mathMLtexVC ); |
| 33 |
$this->assertStringContainsString( '𝓉', $mathMLtexVC ); |
| 34 |
$this->assertStringContainsString( '𝒸', $mathMLtexVC ); |
| 35 |
} |
| 36 |
|
| 37 |
public function testDoubleStruckLiteralUnicode() { |
| 38 |
$input = "\\mathbb{Q}, \\R, \\Complex, \\mathbb{4}"; |
| 39 |
$mathMLtexVC = $this->generateMML( $input ); |
| 40 |
$this->assertStringContainsString( 'ℚ', $mathMLtexVC ); |
| 41 |
$this->assertStringContainsString( 'ℝ', $mathMLtexVC ); |
| 42 |
$this->assertStringContainsString( 'ℂ', $mathMLtexVC ); |
| 43 |
$this->assertStringContainsString( '𝟜', $mathMLtexVC ); |
| 44 |
} |
| 45 |
|
| 46 |
public function testBoldUnicode() { |
| 47 |
$input = "\\mathbf{4}, {\\bf Q} {\\bf a}"; |
| 48 |
$mathMLtexVC = $this->generateMML( $input ); |
| 49 |
$this->assertStringContainsString( '𝐚', $mathMLtexVC ); |
| 50 |
$this->assertStringContainsString( '𝐐', $mathMLtexVC ); |
| 51 |
$this->assertStringContainsString( '𝟒', $mathMLtexVC ); |
| 52 |
} |
| 53 |
|
| 54 |
public function testNoLimits() { |
| 55 |
$input = "\\displaystyle \int\\nolimits_0^\infty f(x) dx"; |
| 56 |
$mathMLtexVC = $this->generateMML( $input ); |
| 57 |
$this->assertStringContainsString( 'movablelimits="false"', $mathMLtexVC ); |
| 58 |
$this->assertStringNotContainsString( "nolimits", $mathMLtexVC ); |
| 59 |
} |
| 60 |
|
| 61 |
public function testGenfracStretching() { |
| 62 |
$input = "\\tbinom{n}{k} \\dbinom{n}{k} \\binom{n}{k}"; |
| 63 |
$mathMLtexVC = $this->generateMML( $input ); |
| 64 |
$this->assertStringNotContainsString( "maxsize", $mathMLtexVC ); |
| 65 |
} |
| 66 |
|
| 67 |
public function testBracketSizesOpen() { |
| 68 |
$input = "\bigl( \Bigl( \biggl( \Biggl( "; |
| 69 |
$mathMLtexVC = $this->generateMML( $input ); |
| 70 |
$this->assertStringContainsString( 'minsize', $mathMLtexVC ); |
| 71 |
$this->assertStringContainsString( 'maxsize', $mathMLtexVC ); |
| 72 |
} |
| 73 |
|
| 74 |
public function testBracketSizesClose() { |
| 75 |
$input = "\bigr) \Bigr) \biggr) \Biggr) "; |
| 76 |
$mathMLtexVC = $this->generateMML( $input ); |
| 77 |
$this->assertStringContainsString( 'minsize', $mathMLtexVC ); |
| 78 |
$this->assertStringContainsString( 'maxsize', $mathMLtexVC ); |
| 79 |
} |
| 80 |
|
| 81 |
public function testLimOperatorSpacing() { |
| 82 |
$input = "\liminf v, \limsup w \injlim x \projlim y"; |
| 83 |
$mathMLtexVC = $this->generateMML( $input ); |
| 84 |
$this->assertStringContainsString( "lim inf", $mathMLtexVC ); |
| 85 |
$this->assertStringContainsString( "lim sup", $mathMLtexVC ); |
| 86 |
$this->assertStringContainsString( "inj lim", $mathMLtexVC ); |
| 87 |
$this->assertStringContainsString( "proj lim", $mathMLtexVC ); |
| 88 |
} |
| 89 |
|
| 90 |
public function testTrimNull() { |
| 91 |
$input = "\\bigl( \\begin{smallmatrix}a&b\\\\ c&d\\end{smallmatrix} \\bigr)"; |
| 92 |
$mathMLtexVC = $this->generateMML( $input ); |
| 93 |
$this->assertStringContainsString( "mtable", $mathMLtexVC ); |
| 94 |
} |
| 95 |
|
| 96 |
public function testApplyOperator1() { |
| 97 |
$input = "\sup x"; |
| 98 |
$mathMLtexVC = $this->generateMML( $input ); |
| 99 |
$this->assertStringContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 100 |
} |
| 101 |
|
| 102 |
public function testApplyOperator2() { |
| 103 |
$input = "\sup"; |
| 104 |
$mathMLtexVC = $this->generateMML( $input ); |
| 105 |
$this->assertStringNotContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 106 |
} |
| 107 |
|
| 108 |
public function testApplyOperator3() { |
| 109 |
$input = "\sup \sin"; |
| 110 |
$mathMLtexVC = $this->generateMML( $input ); |
| 111 |
$this->assertStringContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 112 |
} |
| 113 |
|
| 114 |
public function testApplyFunction1() { |
| 115 |
$input = "\sin x"; |
| 116 |
$mathMLtexVC = $this->generateMML( $input ); |
| 117 |
$this->assertStringContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 118 |
} |
| 119 |
|
| 120 |
public function testApplyFunction2() { |
| 121 |
$input = "\sin"; |
| 122 |
$mathMLtexVC = $this->generateMML( $input ); |
| 123 |
$this->assertStringNotContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 124 |
} |
| 125 |
|
| 126 |
public function testApplyFunction3() { |
| 127 |
$input = "\sin{x}"; |
| 128 |
$mathMLtexVC = $this->generateMML( $input ); |
| 129 |
$this->assertStringContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 130 |
} |
| 131 |
|
| 132 |
public function testApplyFunction4() { |
| 133 |
$input = "\sin \sin"; |
| 134 |
$mathMLtexVC = $this->generateMML( $input ); |
| 135 |
$this->assertStringContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 136 |
} |
| 137 |
|
| 138 |
public function testApplyFunction5() { |
| 139 |
$input = "\cos(x)"; |
| 140 |
$mathMLtexVC = $this->generateMML( $input ); |
| 141 |
$this->assertStringContainsString( "<mo>⁡</mo>", $mathMLtexVC ); |
| 142 |
} |
| 143 |
|
| 144 |
public function testSpacesNoMstyle() { |
| 145 |
$input = "\bmod \, \!"; |
| 146 |
$mathMLtexVC = $this->generateMML( $input ); |
| 147 |
$this->assertStringContainsString( "mspace", $mathMLtexVC ); |
| 148 |
$this->assertStringNotContainsString( "mstyle", $mathMLtexVC ); |
| 149 |
} |
| 150 |
|
| 151 |
public function testBigl() { |
| 152 |
$input = "\bigl("; |
| 153 |
$mathMLtexVC = $this->generateMML( $input ); |
| 154 |
$this->assertStringContainsString( TexClass::OPEN, $mathMLtexVC ); |
| 155 |
} |
| 156 |
|
| 157 |
public function testMsupNumChild1() { |
| 158 |
$input = "\sum^{^N}_{k}"; |
| 159 |
$mathMLtexVC = str_replace( [ "\n", " " ], "", $this->generateMML( $input ) ); |
| 160 |
$this->assertStringContainsString( "<msup><mi/><mrow", $mathMLtexVC ); |
| 161 |
} |
| 162 |
|
| 163 |
public function testMsupNumChild2() { |
| 164 |
$input = "\sum^{a^N}_{k}"; |
| 165 |
$mathMLtexVC = str_replace( [ "\n", " " ], "", $this->generateMML( $input ) ); |
| 166 |
$this->assertStringNotContainsString( "<msup><mi/><mrow", $mathMLtexVC ); |
| 167 |
} |
| 168 |
|
| 169 |
public function testUndersetNumChild() { |
| 170 |
$input = "\underset{\mathrm{def}}{}"; |
| 171 |
$mathMLtexVC = $this->generateMML( $input ); |
| 172 |
$this->assertStringNotContainsString( "munder", $mathMLtexVC ); |
| 173 |
} |
| 174 |
|
| 175 |
public function testUndersetNumChild2() { |
| 176 |
$input = "\underset{\mathrm{def}}{\mathrm{g}}"; |
| 177 |
$mathMLtexVC = $this->generateMML( $input ); |
| 178 |
$this->assertStringContainsString( "munder", $mathMLtexVC ); |
| 179 |
} |
| 180 |
|
| 181 |
public function testAlignLeft() { |
| 182 |
$input = " \begin{align} f(x) & = (a+b)^2 \\ & = a^2+2ab+b^2 \\ \\end{align} "; |
| 183 |
$mathMLtexVC = $this->generateMML( $input ); |
| 184 |
$this->assertStringContainsString( "columnalign=\"right left right", $mathMLtexVC ); |
| 185 |
$this->assertStringContainsString( "columnspacing=\"0em 2em 0em", $mathMLtexVC ); |
| 186 |
$this->assertStringContainsString( "rowspacing=\"3pt\"", $mathMLtexVC ); |
| 187 |
$this->assertStringContainsString( "mtable", $mathMLtexVC ); |
| 188 |
} |
| 189 |
|
| 190 |
public function testLeftRightAttributes() { |
| 191 |
$input = "\\left( \\right) \\left[ \\right]"; |
| 192 |
$mathMLtexVC = $this->generateMML( $input ); |
| 193 |
$this->assertStringContainsString( "<mo", $mathMLtexVC ); |
| 194 |
$this->assertStringNotContainsString( "stretchy", $mathMLtexVC ); |
| 195 |
} |
| 196 |
|
| 197 |
public function testIntbar1() { |
| 198 |
$input = "\intbar"; |
| 199 |
$mathMLtexVC = $this->generateMML( $input ); |
| 200 |
$this->assertStringContainsString( "<mo", $mathMLtexVC ); |
| 201 |
$this->assertStringContainsString( "⨍", $mathMLtexVC ); |
| 202 |
} |
| 203 |
|
| 204 |
public function testIntBar2() { |
| 205 |
$input = "\intBar"; |
| 206 |
$mathMLtexVC = $this->generateMML( $input ); |
| 207 |
$this->assertStringContainsString( "<mo", $mathMLtexVC ); |
| 208 |
$this->assertStringContainsString( "⨎", $mathMLtexVC ); |
| 209 |
} |
| 210 |
|
| 211 |
public function testAtop() { |
| 212 |
$input = "{ a \atop b }"; |
| 213 |
$mathMLtexVC = $this->generateMML( $input ); |
| 214 |
$this->assertStringContainsString( "<mfrac linethickness=\"0\">", $mathMLtexVC ); |
| 215 |
} |
| 216 |
|
| 217 |
public function testChoose() { |
| 218 |
$input = "{ a \choose b }"; |
| 219 |
$mathMLtexVC = $this->generateMML( $input ); |
| 220 |
$this->assertStringContainsString( "<mfrac linethickness=\"0\">", $mathMLtexVC ); |
| 221 |
$this->assertStringContainsString( ")", $mathMLtexVC ); |
| 222 |
$this->assertStringContainsString( "(", $mathMLtexVC ); |
| 223 |
} |
| 224 |
|
| 225 |
public function testOver() { |
| 226 |
$input = "{a \over b }"; |
| 227 |
$mathMLtexVC = $this->generateMML( $input ); |
| 228 |
$this->assertStringContainsString( "<mfrac>", $mathMLtexVC ); |
| 229 |
} |
| 230 |
|
| 231 |
public function testBigcup() { |
| 232 |
$input = "\bigcup_{i=_1}^n E_i"; |
| 233 |
$mathMLtexVC = $this->generateMML( $input ); |
| 234 |
$this->assertStringContainsString( "munderover", $mathMLtexVC ); |
| 235 |
} |
| 236 |
|
| 237 |
public function testBigcap() { |
| 238 |
$input = "\bigcap_{i=_1}^n E_i"; |
| 239 |
$mathMLtexVC = $this->generateMML( $input ); |
| 240 |
$this->assertStringContainsString( "munderover", $mathMLtexVC ); |
| 241 |
} |
| 242 |
|
| 243 |
public function testScriptAlignment() { |
| 244 |
$input = "\log_{10} f"; |
| 245 |
$mathMLtexVC = $this->generateMML( $input ); |
| 246 |
$this->assertStringNotContainsString( "<mo></mo>", $mathMLtexVC ); |
| 247 |
$this->assertStringContainsString( "<msub>", $mathMLtexVC ); |
| 248 |
} |
| 249 |
|
| 250 |
public function testNotOperatorname() { |
| 251 |
$input = "\\not\operatorname{R}"; |
| 252 |
$mathMLtexVC = $this->generateMML( $input ); |
| 253 |
$this->assertStringContainsString( "<mpadded width=\"0\">", $mathMLtexVC ); |
| 254 |
$this->assertStringContainsString( "<mtext>⧸</mtext>", $mathMLtexVC ); |
| 255 |
} |
| 256 |
|
| 257 |
public function testUnder() { |
| 258 |
$input = "\\underbrace{ a+b+\\cdots+z }_{26}"; |
| 259 |
$mathMLtexVC = $this->generateMML( $input ); |
| 260 |
$this->assertStringContainsString( "<munder>", $mathMLtexVC ); |
| 261 |
$this->assertStringNotContainsString( "<msub>", $mathMLtexVC ); |
| 262 |
} |
| 263 |
|
| 264 |
public function testSumDisplaystyle() { |
| 265 |
$input = "\sum_{k=1}^N k^2"; |
| 266 |
$mathMLtexVC = $this->generateMML( $input ); |
| 267 |
$this->assertStringContainsString( "<mstyle displaystyle=\"true\" scriptlevel=\"0\">", $mathMLtexVC ); |
| 268 |
} |
| 269 |
|
| 270 |
public function testSumTextstyle() { |
| 271 |
$input = "\\textstyle \sum_{k=1}^N k^2"; |
| 272 |
$mathMLtexVC = $this->generateMML( $input ); |
| 273 |
$this->assertStringContainsString( "<mstyle displaystyle=\"false\" scriptlevel=\"0\">", $mathMLtexVC ); |
| 274 |
} |
| 275 |
|
| 276 |
public function testPilcrow() { |
| 277 |
$input = "\P"; |
| 278 |
$mathMLtexVC = $this->generateMML( $input ); |
| 279 |
$this->assertStringContainsString( "<mo>¶</mo>\n</math>", $mathMLtexVC ); |
| 280 |
} |
| 281 |
|
| 282 |
public function testLesserThan() { |
| 283 |
$input = "<, \\nless,"; |
| 284 |
$mathMLtexVC = $this->generateMML( $input ); |
| 285 |
$this->assertStringContainsString( "<mo><</mo>", $mathMLtexVC ); |
| 286 |
} |
| 287 |
|
| 288 |
public function testSidesetError() { |
| 289 |
$input = "\\sideset{_1^2}{_3^4}"; |
| 290 |
$mathMLtexVC = $this->generateMML( $input ); |
| 291 |
$this->assertStringContainsString( "merror", $mathMLtexVC ); |
| 292 |
} |
| 293 |
|
| 294 |
public function testEmptySidesetDQ() { |
| 295 |
$input = "\\sideset{}{}a_b"; |
| 296 |
$mathMLtexVC = $this->generateMML( $input ); |
| 297 |
$this->assertStringNotContainsString( "merror", $mathMLtexVC ); |
| 298 |
} |
| 299 |
|
| 300 |
public function testEmptySidesetUQ() { |
| 301 |
$input = "\\sideset{}{}a^b"; |
| 302 |
$mathMLtexVC = $this->generateMML( $input ); |
| 303 |
$this->assertStringNotContainsString( "merror", $mathMLtexVC ); |
| 304 |
} |
| 305 |
|
| 306 |
public function testSidesetSum() { |
| 307 |
$input = "\\sideset{_1^2}{_3^4}\\sum"; |
| 308 |
$mathMLtexVC = $this->generateMML( $input ); |
| 309 |
$this->assertStringNotContainsString( "merror", $mathMLtexVC ); |
| 310 |
$this->assertStringContainsString( "mmultiscripts", $mathMLtexVC ); |
| 311 |
$this->assertStringContainsString( "<mprescripts/>", $mathMLtexVC ); |
| 312 |
$this->assertStringContainsString( ">∑", $mathMLtexVC ); |
| 313 |
} |
| 314 |
|
| 315 |
public function testSidesetProd() { |
| 316 |
$input = "\\sideset{_1^2}{_3^4}\\prod"; |
| 317 |
$mathMLtexVC = $this->generateMML( $input ); |
| 318 |
$this->assertStringNotContainsString( "merror", $mathMLtexVC ); |
| 319 |
$this->assertStringContainsString( "mmultiscripts", $mathMLtexVC ); |
| 320 |
$this->assertStringContainsString( "<mprescripts/>", $mathMLtexVC ); |
| 321 |
$this->assertStringContainsString( ">∏", $mathMLtexVC ); |
| 322 |
} |
| 323 |
|
| 324 |
public function testSidesetFQ() { |
| 325 |
$input = "\\sideset{_1^2}{_3^4}\prod_a^b"; |
| 326 |
$mathMLtexVC = $this->generateMML( $input ); |
| 327 |
$this->assertStringNotContainsString( "merror", $mathMLtexVC ); |
| 328 |
$this->assertStringContainsString( "mmultiscripts", $mathMLtexVC ); |
| 329 |
$this->assertStringContainsString( "<mprescripts/>", $mathMLtexVC ); |
| 330 |
$this->assertStringContainsString( ">∏", $mathMLtexVC ); |
| 331 |
$this->assertStringContainsString( "<mi>a</mi>", $mathMLtexVC ); |
| 332 |
$this->assertStringContainsString( "<mi>b</mi>", $mathMLtexVC ); |
| 333 |
$this->assertStringContainsString( "movablelimits", $mathMLtexVC ); |
| 334 |
} |
| 335 |
|
| 336 |
public function testLimitsProd() { |
| 337 |
$input = "\\prod\\limits_{j=1}^k A_{\\alpha_j}"; |
| 338 |
$mathMLtexVC = $this->generateMML( $input ); |
| 339 |
$this->assertStringContainsString( "munderover", $mathMLtexVC ); |
| 340 |
$this->assertStringContainsString( "∏", $mathMLtexVC, ); |
| 341 |
$this->assertStringContainsString( "msub", $mathMLtexVC, ); |
| 342 |
} |
| 343 |
|
| 344 |
public function testLimitsSum() { |
| 345 |
$input = "\\sum\\limits_{j=1}^k A_{\\alpha_j}"; |
| 346 |
$mathMLtexVC = $this->generateMML( $input ); |
| 347 |
$this->assertStringContainsString( "munderover", $mathMLtexVC ); |
| 348 |
$this->assertStringContainsString( "∑", $mathMLtexVC, ); |
| 349 |
$this->assertStringContainsString( "msub", $mathMLtexVC, ); |
| 350 |
} |
| 351 |
|
| 352 |
public function testLimitsLim() { |
| 353 |
$input = "\\lim_{x \\to 2}"; |
| 354 |
$mathMLtexVC = $this->generateMML( $input ); |
| 355 |
$this->assertStringContainsString( "lim", $mathMLtexVC ); |
| 356 |
$this->assertStringContainsString( "munder", $mathMLtexVC, ); |
| 357 |
} |
| 358 |
|
| 359 |
public function testRenderSpaceSemicolon() { |
| 360 |
$input = "{\\;}"; |
| 361 |
$mathMLtexVC = $this->generateMML( $input ); |
| 362 |
$this->assertStringContainsString( "mspace", $mathMLtexVC, ); |
| 363 |
} |
| 364 |
|
| 365 |
public function testSpacesAndCommas() { |
| 366 |
$input = "{a}{b , c}\\,"; |
| 367 |
$mathMLtexVC = $this->generateMML( $input ); |
| 368 |
$this->assertStringContainsString( "<mo>,", $mathMLtexVC ); |
| 369 |
$this->assertStringContainsString( "mspace", $mathMLtexVC, ); |
| 370 |
} |
| 371 |
|
| 372 |
public function testPrecedingSubscriptsFQ() { |
| 373 |
$input = "{}_1^2\\!\\Omega_3^4"; |
| 374 |
$mathMLtexVC = $this->generateMML( $input ); |
| 375 |
$this->assertStringContainsString( "<mrow " . Tag::CLASSTAG . "=\"ORD\"/>", $mathMLtexVC ); |
| 376 |
$this->assertStringContainsString( "msubsup", $mathMLtexVC, ); |
| 377 |
} |
| 378 |
|
| 379 |
public function testPrecedingSubscriptsDQ() { |
| 380 |
$input = "{}_pF_q"; |
| 381 |
$mathMLtexVC = $this->generateMML( $input ); |
| 382 |
$this->assertStringContainsString( "<mrow " . Tag::CLASSTAG . "=\"ORD\"/>", $mathMLtexVC ); |
| 383 |
$this->assertStringContainsString( "msub", $mathMLtexVC, ); |
| 384 |
} |
| 385 |
|
| 386 |
public function testPilcrowAndSectionSign() { |
| 387 |
$input = "\\P P \\S S"; |
| 388 |
$mathMLtexVC = $this->generateMML( $input ); |
| 389 |
$this->assertStringContainsString( "<mi>P", $mathMLtexVC ); |
| 390 |
$this->assertStringContainsString( "<mi>S", $mathMLtexVC, ); |
| 391 |
$this->assertStringContainsString( "¶", $mathMLtexVC, ); |
| 392 |
$this->assertStringContainsString( "§", $mathMLtexVC, ); |
| 393 |
} |
| 394 |
|
| 395 |
public function testDerivatives1() { |
| 396 |
$input = "b_{f''}"; |
| 397 |
$mathMLtexVC = $this->generateMML( $input ); |
| 398 |
$this->assertStringContainsString( "<mo>″", $mathMLtexVC ); |
| 399 |
$this->assertStringContainsString( "msup", $mathMLtexVC, ); |
| 400 |
} |
| 401 |
|
| 402 |
public function testDerivatives2() { |
| 403 |
$input = "f''''(x)"; |
| 404 |
$mathMLtexVC = $this->generateMML( $input ); |
| 405 |
$this->assertStringContainsString( "<mo>⁗", $mathMLtexVC ); |
| 406 |
$this->assertStringContainsString( "msup", $mathMLtexVC, ); |
| 407 |
} |
| 408 |
|
| 409 |
public function testLimitsTextstyle() { |
| 410 |
$input = "\\textstyle \\lim_{n \\to \\infty}x_n"; |
| 411 |
$mathMLtexVC = $this->generateMML( $input ); |
| 412 |
$this->assertStringContainsString( "lim", $mathMLtexVC ); |
| 413 |
$this->assertStringContainsString( "munder", $mathMLtexVC, ); |
| 414 |
$this->assertStringContainsString( "movablelimits=\"true\"", $mathMLtexVC ); |
| 415 |
} |
| 416 |
|
| 417 |
public function testColorGeneration1() { |
| 418 |
$input = "\\color{Dandelion}{Dandelion}"; |
| 419 |
$mathMLtexVC = $this->generateMML( $input ); |
| 420 |
$this->assertStringContainsString( "#FDBC42", $mathMLtexVC ); |
| 421 |
} |
| 422 |
|
| 423 |
public function testColorGeneration2() { |
| 424 |
$input = "\\color{ForestGreen}{ForestGreen}"; |
| 425 |
$mathMLtexVC = $this->generateMML( $input ); |
| 426 |
$this->assertStringContainsString( "#009B55", $mathMLtexVC ); |
| 427 |
} |
| 428 |
|
| 429 |
public function testColorGeneration3() { |
| 430 |
$input = "\\color{Rhodamine}{Rhodamine}"; |
| 431 |
$mathMLtexVC = $this->generateMML( $input ); |
| 432 |
$this->assertStringContainsString( "#EF559F", $mathMLtexVC ); |
| 433 |
} |
| 434 |
|
| 435 |
public function testStyle1() { |
| 436 |
$input = "\\displaystyle \{U(\omega )\cdot \sigma _{H}(\omega )\} z"; |
| 437 |
$mathMLtexVC = $this->generateMML( $input ); |
| 438 |
$this->assertStringContainsString( "<mstyle displaystyle=\"true\" scriptlevel=\"0\">", $mathMLtexVC ); |
| 439 |
$this->assertStringContainsString( "<mi>z</mi>", $mathMLtexVC ); |
| 440 |
$this->assertStringContainsString( "</mstyle>", $mathMLtexVC, ); |
| 441 |
} |
| 442 |
|
| 443 |
public function testStyle2() { |
| 444 |
$input = "\\displaystyle abc \\textstyle def"; |
| 445 |
$mathMLtexVC = $this->generateMML( $input ); |
| 446 |
$this->assertStringContainsString( "<mstyle displaystyle=\"false\" scriptlevel=\"0\">", $mathMLtexVC ); |
| 447 |
$this->assertStringContainsString( "</mstyle>", $mathMLtexVC, ); |
| 448 |
} |
| 449 |
|
| 450 |
public function testStyle3() { |
| 451 |
$input = "\\scriptstyle{abc} def \\textstyle ghi"; |
| 452 |
$mathMLtexVC = $this->generateMML( $input ); |
| 453 |
$this->assertStringContainsString( "<mstyle displaystyle=\"false\" scriptlevel=\"1\">", $mathMLtexVC ); |
| 454 |
$this->assertStringContainsString( "</mstyle>", $mathMLtexVC, ); |
| 455 |
} |
| 456 |
|
| 457 |
public function testStyle4() { |
| 458 |
$input = "\\textstyle b > \\textstyle \\delta"; |
| 459 |
$mathMLtexVC = $this->generateMML( $input ); |
| 460 |
$count = 0; |
| 461 |
str_replace( "<mstyle displaystyle", "", $mathMLtexVC, $count ); |
| 462 |
$this->assertEquals( 2, $count ); |
| 463 |
} |
| 464 |
|
| 465 |
public function testSpaceText() { |
| 466 |
$input = "\\text{if}~n\ \\text{is even} "; |
| 467 |
$mathMLtexVC = $this->generateMML( $input ); |
| 468 |
$this->assertStringContainsString( "<mtext", $mathMLtexVC ); |
| 469 |
$this->assertStringNotContainsString( " ", $mathMLtexVC ); |
| 470 |
} |
| 471 |
|
| 472 |
public function testSpaceOther() { |
| 473 |
|
| 474 |
$input = "\,e_{x}=\sum _{t=1}^{\infty }\ _{t}p_{x}"; |
| 475 |
$mathMLtexVC = $this->generateMML( $input ); |
| 476 |
$this->assertStringContainsString( "<mspace", $mathMLtexVC ); |
| 477 |
} |
| 478 |
|
| 479 |
public function testGenfracDQ() { |
| 480 |
$input = "\\binom{m}{k - j}_{\!\!q}"; |
| 481 |
$mathMLtexVC = $this->generateMML( $input ); |
| 482 |
$this->assertStringContainsString( "<mi>q</mi>", $mathMLtexVC ); |
| 483 |
$this->assertStringContainsString( "msub", $mathMLtexVC ); |
| 484 |
} |
| 485 |
|
| 486 |
public function testDQZeroArgs() { |
| 487 |
$input = "nF^{_{}}/RT"; |
| 488 |
$mathMLtexVC = $this->generateMML( $input ); |
| 489 |
$this->assertStringContainsString( "msup", $mathMLtexVC ); |
| 490 |
} |
| 491 |
|
| 492 |
public function testMatrixDQ() { |
| 493 |
$input = "\\begin{pmatrix} S \\\\Se\\\\Te\\end{pmatrix}_2"; |
| 494 |
$mathMLtexVC = $this->generateMML( $input ); |
| 495 |
$this->assertStringContainsString( "mtable", $mathMLtexVC ); |
| 496 |
$this->assertStringContainsString( "msub", $mathMLtexVC ); |
| 497 |
$this->assertStringContainsString( "<mn>2</mn>", $mathMLtexVC ); |
| 498 |
} |
| 499 |
|
| 500 |
public function testAttributeDuplicate() { |
| 501 |
|
| 502 |
$input = "\\mu_{\\operatorname{\\inf}}"; |
| 503 |
$mathMLtexVC = $this->generateMML( $input ); |
| 504 |
$this->assertStringContainsString( "μ", $mathMLtexVC ); |
| 505 |
} |
| 506 |
|
| 507 |
private function generateMML( $input, $chem = false ) { |
| 508 |
$texVC = new TexVC(); |
| 509 |
$resultT = $texVC->check( $input, [ |
| 510 |
'debug' => false, |
| 511 |
'usemathrm' => false, |
| 512 |
'oldtexvc' => false, |
| 513 |
'usemhchem' => $chem |
| 514 |
] ); |
| 515 |
|
| 516 |
return MMLTestUtil::getMMLwrapped( $resultT["input"] ) ?? "<math> error texvc </math>"; |
| 517 |
} |
| 518 |
|
| 519 |
public function testOperatorAccentPlain() { |
| 520 |
|
| 521 |
$input = "\\operatorname{a}'"; |
| 522 |
$mathMLtexVC = $this->generateMML( $input ); |
| 523 |
$posSupEnd = strpos( $mathMLtexVC, "</msup>" ); |
| 524 |
$posFunApply = strpos( $mathMLtexVC, "⁡</mo>" ); |
| 525 |
$posAccent = strpos( $mathMLtexVC, "′</mo>" ); |
| 526 |
$posA = strpos( $mathMLtexVC, "a</mi>" ); |
| 527 |
$this->assertGreaterThan( $posSupEnd, $posFunApply, "Function application should be last" ); |
| 528 |
$this->assertGreaterThan( $posAccent, $posSupEnd, "Accent needs to be within msup" ); |
| 529 |
$this->assertGreaterThan( $posA, $posAccent, "Accent should follow a" ); |
| 530 |
} |
| 531 |
|
| 532 |
public function testOperatorAccentApplied() { |
| 533 |
|
| 534 |
$input = "\\operatorname{a}'x"; |
| 535 |
$mathMLtexVC = $this->generateMML( $input ); |
| 536 |
$this->assertStringContainsString( "mo", $mathMLtexVC ); |
| 537 |
$this->assertStringContainsString( "msup", $mathMLtexVC ); |
| 538 |
$this->assertStringContainsString( "x2061;", $mathMLtexVC ); |
| 539 |
} |
| 540 |
|
| 541 |
public function testAmsDelim1() { |
| 542 |
$input = "\\ulcorner a \\urcorner"; |
| 543 |
$mml = $this->generateMML( $input ); |
| 544 |
$this->assertStringContainsString( "⌜", $mml ); |
| 545 |
$this->assertStringContainsString( "⌝", $mml ); |
| 546 |
} |
| 547 |
|
| 548 |
public function testlVert() { |
| 549 |
$input = "\\lVert a \\rVert"; |
| 550 |
$mml = $this->generateMML( $input ); |
| 551 |
$this->assertStringContainsString( "‖", $mml ); |
| 552 |
$this->assertStringNotContainsString( "OPEN", $mml ); |
| 553 |
$this->assertStringNotContainsString( "CLOSE", $mml ); |
| 554 |
} |
| 555 |
} |