Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 554 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
LaTeXTranslator | |
0.00% |
0 / 554 |
|
0.00% |
0 / 3 |
756 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 545 |
|
0.00% |
0 / 1 |
506 | |||
brackR | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
processInput | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | class LaTeXTranslator { |
4 | |
5 | /** @var string[][] */ |
6 | private $replacements; |
7 | |
8 | /** |
9 | * @var string contains frequently occurring regex for recurisve extraction of nested parenthesis |
10 | */ |
11 | private $par = "(\\{(?>[^{}]|(?-1))*\\})"; |
12 | /** |
13 | * @var string contains frequently occurring regex for single argument of number or Greek letter |
14 | */ |
15 | private $arg = "(\\\\[?[A-Za-z]*\\]?|[0-9]|[A-Za-z]{1})"; |
16 | |
17 | function __construct() { |
18 | # reference: http://stackoverflow.com/a/28611214/4521584 |
19 | $this->replacements = [ |
20 | [ |
21 | # Trignometric & Trig Integrals: \acosh@{x} |
22 | 'search' => |
23 | "~\\\\(a?(?>cos|sin|tan|csc|cot|sec)h?)(int)?@{0,2}(" . $this->arg . "|" . |
24 | $this->par . ")~i", |
25 | # Trignometric: ArcCosh[x] |
26 | 'replace' => static function ( array $m ) { |
27 | return ( $m[1][0] == 'a' ? 'Arc' . ucfirst( strtolower( substr( $m[1], 1 ) ) ) |
28 | : ucfirst( strtolower( $m[1] ) ) ) . |
29 | ( strlen( $m[2] ) > 0 ? 'Integral' : '' ) . '[' . |
30 | LaTeXTranslator::brackR( $m[3] ) . ']'; |
31 | } |
32 | ], |
33 | [ |
34 | # Logarithm |
35 | 'search' => |
36 | "~\\\\(?>log|ln)b?" . $this->par . "?@{0,2}(" . $this->arg . "|" . $this->par . |
37 | ")~i", |
38 | # Logarithm: Log[x] |
39 | 'replace' => static function ( array $m ) { |
40 | return 'Log[' . ( strlen( $m[1] ) > 0 ? $m[1] . ',' : '' ) . |
41 | LaTeXTranslator::brackR( $m[2] ) . ']'; |
42 | } |
43 | ], |
44 | [ |
45 | # Airy: \AiryAi@{z} |
46 | 'search' => "~\\\\Airy([B|A]i)@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
47 | # Airy: AiryAi[z] |
48 | 'replace' => static function ( array $m ) { |
49 | return 'Airy' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
50 | } |
51 | ], |
52 | [ |
53 | # Airy Modulus M: \AiryModulusM@{z} |
54 | 'search' => "~\\\\AiryModulusM@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
55 | # Airy Modulus M: Sqrt[AiryAi[x]^2+AiryBi[x]^2] |
56 | 'replace' => static function ( array $m ) { |
57 | return 'Sqrt[AiryAi[' . LaTeXTranslator::brackR( $m[1] ) . ']^2+AiryBi[' . |
58 | LaTeXTranslator::brackR( $m[1] ) . ']^2]'; |
59 | } |
60 | ], |
61 | [ |
62 | # Arithmetic Geometric Mean: \AGM@{a}{g} |
63 | 'search' => |
64 | "~\\\\AGM@{0,2}(" . $this->arg . "|" . $this->par . ")(" . $this->arg . "|" . |
65 | $this->par . ")~i", |
66 | # Arithmetic Geometric Mean: ArithmeticGeometricMean[a,b] |
67 | 'replace' => static function ( array $m ) { |
68 | return 'ArithmeticGeometricMean[' . LaTeXTranslator::brackR( $m[1] ) . ',' . |
69 | LaTeXTranslator::brackR( $m[4] ) . ']'; |
70 | } |
71 | ], |
72 | [ |
73 | # Anger: \AngerJ{\nu}@{z} |
74 | 'search' => "~\\\\AngerJ" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
75 | ")~i", |
76 | # Anger: AngerJ[\nu,z] |
77 | 'replace' => static function ( array $m ) { |
78 | return 'AngerJ[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
79 | } |
80 | ], |
81 | [ |
82 | # Appell: \AppellFi@{\alpha}{\beta}{\beta'}{\gamma}{x}{y} |
83 | 'search' => "~\\\\AppellF[i{1,3}v?]@{0,2}(" . $this->arg . "|" . $this->par . ")(" . |
84 | $this->arg . "|" . $this->par . ")(" . $this->arg . "|" . $this->par . |
85 | ")(" . $this->arg . "|" . $this->par . ")(" . $this->arg . "|" . |
86 | $this->par . ")(" . $this->arg . "|" . $this->par . ")~i", |
87 | # Appell: AppellF1[\alpha,\beta,\beta',\gamma,x,y] |
88 | 'replace' => static function ( array $m ) { |
89 | return 'AppellF1[' . |
90 | LaTeXTranslator::brackR( $m[1] ) . ',' . |
91 | LaTeXTranslator::brackR( $m[4] ) . ',' . |
92 | LaTeXTranslator::brackR( $m[7] ) . ',' . |
93 | LaTeXTranslator::brackR( $m[10] ) . ',' . |
94 | LaTeXTranslator::brackR( $m[13] ) . ',' . |
95 | LaTeXTranslator::brackR( $m['16'] ) . ']'; |
96 | } |
97 | ], |
98 | [ |
99 | # Barnes G: \BarnesGamma@{z} |
100 | 'search' => "~\\\\BarnesGamma@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
101 | # Barnes G: BarnesG[z] |
102 | 'replace' => static function ( array $m ) { |
103 | return 'BarnesG[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
104 | } |
105 | ], |
106 | [ |
107 | # BesselJ: \BesselJ{n}@{z} - default?? for BesselJ{nu}/Cheby w/ no z??? |
108 | 'search' => "~\\\\Bessel([A-Z])" . $this->par . "@?(" . $this->par . ")?~i", |
109 | # BesselJ: BesselJ[n,z] |
110 | 'replace' => static function ( array $m ) { |
111 | return 'Bessel' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . |
112 | ( strlen( $m[3] ) > 0 ? ',' . LaTeXTranslator::brackR( $m[3] ) : ',0' ) . ']'; |
113 | } |
114 | ], |
115 | [ |
116 | # Binomial Coefficient: \binomial{m}{n} |
117 | 'search' => "~\\\\binom(?>ial)?@{0,2}" . $this->par . $this->par . "~i", |
118 | # Binomial Coefficient: Binomial[n,m] |
119 | 'replace' => static function ( array $m ) { |
120 | return 'Binomial[' . LaTeXTranslator::brackR( $m[2] ) . ',' . LaTeXTranslator::brackR( $m[1] ) . |
121 | ']'; |
122 | } |
123 | ], |
124 | [ |
125 | # Catalan Number: \CatalanNumber@{n} |
126 | 'search' => "~\\\\CatalanNumber@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
127 | # Catalan Number: CatalanNumber[n] |
128 | 'replace' => static function ( array $m ) { |
129 | return 'CatalanNumber[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
130 | } |
131 | ], |
132 | [ |
133 | # Ceiling: \ceiling{x} |
134 | 'search' => "~\\\\ceiling@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
135 | # Ceiling: Ceiling[x] |
136 | 'replace' => static function ( array $m ) { |
137 | return 'Ceiling[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
138 | } |
139 | ], |
140 | [ |
141 | # Chebyshev: \ChebyT{x}@{n} |
142 | 'search' => "~\\\Cheby([A-Z])" . $this->par . "@?(" . $this->par . ")?~i", |
143 | # Chebyshev: ChebyshevT[n,x] |
144 | 'replace' => static function ( array $m ) { |
145 | return 'Chebyshev' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . |
146 | ( strlen( $m[3] ) > 0 ? ',' . LaTeXTranslator::brackR( $m[3] ) : ',0' ) . ']'; |
147 | } |
148 | ], |
149 | [ |
150 | # Complex Conjugate: \conj{z} |
151 | 'search' => "~\\\\conj@{0,2}" . $this->par . "~i", |
152 | # Complex Conjugate: Conjugate[z] |
153 | 'replace' => static function ( array $m ) { |
154 | return 'Conjugate[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
155 | } |
156 | ], |
157 | [ |
158 | # Cylinder: \Cylinder{\nu}@{z} |
159 | 'search' => |
160 | "~\\\\Cylinder" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
161 | ")~i", |
162 | # Cylinder: ParabolicCylinderD[\nu,z] |
163 | 'replace' => static function ( array $m ) { |
164 | return 'ParabolicCylinderD[' . LaTeXTranslator::brackR( $m[1] ) . ',' . |
165 | LaTeXTranslator::brackR( $m[2] ) . ']'; |
166 | } |
167 | ], |
168 | [ |
169 | # Dawson's Integral: \DawsonsInt@{z} |
170 | 'search' => "~\\\DawsonsInt@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
171 | # Dawsons Integral: DawsonF[z] |
172 | 'replace' => static function ( array $m ) { |
173 | return 'DawsonF[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
174 | } |
175 | ], |
176 | [ |
177 | # Dedekind's Eta: \DedekindModularEta@{\tau} |
178 | 'search' => "~\\\\DedekindModularEta@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
179 | # Dedekind's Eta: DedekindEta[\tau] |
180 | 'replace' => static function ( array $m ) { |
181 | return 'DedekindEta[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
182 | } |
183 | ], |
184 | [ |
185 | # Derivative: \deriv{f}{x} |
186 | 'search' => "~\\\\p?deriv@{0,2}" . $this->par . $this->par . "~i", |
187 | # Derivative: D[f,x] |
188 | 'replace' => static function ( array $m ) { |
189 | return 'D[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
190 | } |
191 | ], |
192 | [ |
193 | # Determinant: \det |
194 | 'search' => "~\\\\det@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
195 | # Determinant: Det[a] |
196 | 'replace' => static function ( array $m ) { |
197 | return 'Det[' . $m[1] . ']'; |
198 | } |
199 | ], |
200 | [ |
201 | # Divergence: \divergence |
202 | 'search' => "~\\\\divergence@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
203 | # Divergence: divergence |
204 | 'replace' => static function ( array $m ) { |
205 | return 'Div[' . $m[1] . ']'; |
206 | } |
207 | ], |
208 | [ |
209 | # Elliptic Integral: \CompEllIntC@{a} |
210 | 'search' => |
211 | "~\\\\(?>Comp)?EllInt[C]?([A-Z]|Pi)@{0,3}(" . $this->arg . "|" . $this->par . |
212 | ")(" . $this->arg . "|" . $this->par . ")?~i", |
213 | # Elliptic Integral: EllipticC[x, Sqrt[m]] |
214 | 'replace' => static function ( array $m ) { |
215 | return 'Elliptic' . $m[1] . '[' . ( count( $m ) > 5 ? |
216 | LaTeXTranslator::brackR( $m[2] ) . ', Sqrt[' . LaTeXTranslator::brackR( $m[4] ) . ']' |
217 | : 'Sqrt[' . LaTeXTranslator::brackR( $m[2] ) . ']' ) . ']'; |
218 | } |
219 | ], |
220 | [ |
221 | # Error: \erf@{z} |
222 | 'search' => "~\\\\erf[a-z]?@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
223 | # Error: Erf[z] |
224 | 'replace' => static function ( array $m ) { |
225 | return 'Erf[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
226 | } |
227 | ], |
228 | [ |
229 | # Euler Beta & Gamma: \EulerBeta@{a}{b} |
230 | 'search' => "~\\\\Euler(Beta|Gamma)@{0,2}(" . $this->arg . "|" . $this->par . ")(" . |
231 | $this->arg . "|" . $this->par . ")?~i", |
232 | # Euler Beta & Gamma: Beta[a,b] |
233 | 'replace' => static function ( array $m ) { |
234 | return $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . |
235 | ( strlen( $m[5] ) > 0 && strtolower( $m[1] ) == 'beta' ? |
236 | ',' . LaTeXTranslator::brackR( $m[5] ) : '' ) . ']'; |
237 | } |
238 | ], |
239 | [ |
240 | # Exponential: \exp@{x} |
241 | 'search' => "~\\\\exp@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
242 | # Exponential: Exp[x] |
243 | 'replace' => static function ( array $m ) { |
244 | return 'Exp[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
245 | } |
246 | ], |
247 | [ |
248 | # Exponential Integral: \ExpInti@{x} |
249 | 'search' => "~\\\\ExpInt([a-z])?" . $this->par . "?@{0,2}(" . $this->arg . "|" . |
250 | $this->par . ")~i", |
251 | # Exponential Integral: ExpIntegralEi[z] |
252 | 'replace' => static function ( array $m ) { |
253 | return 'ExpIntegralE' . ( $m[1] == 'i' ? 'i' : '' ) . '[' . |
254 | ( strlen( $m[2] ) > 0 ? LaTeXTranslator::brackR( $m[2] ) . ',' : '' ) . |
255 | LaTeXTranslator::brackR( $m[3] ) . ']'; |
256 | } |
257 | ], |
258 | [ |
259 | # Floor: \floor{x} |
260 | 'search' => "~\\\\floor(" . $this->arg . "|" . $this->par . ")~i", |
261 | # Floor: Floor[x] |
262 | 'replace' => static function ( array $m ) { |
263 | return 'Floor[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
264 | } |
265 | ], |
266 | [ |
267 | # Fraction: \frac{a}{b} |
268 | 'search' => "~\\\\frac(" . $this->arg . "|" . $this->par . ")(" . $this->arg . "|" . |
269 | $this->par . ")~i", |
270 | # Fraction: a/b |
271 | 'replace' => static function ( array $m ) { |
272 | return ( strlen( $m[3] ) > 0 ? '(' . LaTeXTranslator::brackR( $m[1] ) . ')' |
273 | : LaTeXTranslator::brackR( $m[1] ) ) . '/' . |
274 | ( count( $m ) > 6 ? '(' . LaTeXTranslator::brackR( $m[4] ) . ')' |
275 | : LaTeXTranslator::brackR( $m[4] ) ); |
276 | } |
277 | ], |
278 | [ |
279 | # Fresnel: \FresnelSin@{z} |
280 | 'search' => "~\\\\Fresnel([a-z]*)@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
281 | # Fresnel: FresnelS[z] |
282 | 'replace' => static function ( array $m ) { |
283 | return 'Fresnel' . ucfirst( $m[1][0] ) . '[' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
284 | } |
285 | ], |
286 | [ |
287 | # Greek Letter: \Alpha |
288 | 'search' => "~\\\\(alpha|beta|gamma|delta|epsilon|varepsilon|zeta|eta|theta|" |
289 | . "vartheta|gamma|kappa|lambda|mu|nu|xi|o[^mega]|pi|varpi|rho|varrho|sigma|" |
290 | . "varsigma|tau|upsilon|phi|varphi|chi|psi|omega)~i", |
291 | # Greek Letter: \[CapitalAlpha] |
292 | 'replace' => static function ( array $m ) { |
293 | return '\\[' . ( strtolower( $m[1] ) != $m[1] ? 'Capital' : '' ) . |
294 | ucfirst( $m[1] ) . ']'; |
295 | } |
296 | ], |
297 | [ |
298 | # Gamma: \GammaP@{a}{z} |
299 | 'search' => |
300 | "~\\\\Gamma(?>[PQ])@?(" . $this->arg . "|" . $this->par . ")(" . $this->arg . |
301 | "|" . $this->par . ")~i", |
302 | # Gamma (Incomplete): |
303 | 'replace' => static function ( array $m ) { |
304 | return 'Gamma[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[4] ) . ']'; |
305 | } |
306 | ], |
307 | [ |
308 | # Gudermannian: \Gudermannian@{x} |
309 | 'search' => "~\\\\(arc)?Gudermannian@{0,2}(" . $this->arg . "|" . $this->par . |
310 | ")~i", |
311 | # Gudermannian: Gudermannian[z] |
312 | 'replace' => static function ( array $m ) { |
313 | return ( strlen( $m[1] ) > 0 ? 'Inverse' : '' ) . 'Gudermannian[' . |
314 | LaTeXTranslator::brackR( $m[2] ) . ']'; |
315 | } |
316 | ], |
317 | [ |
318 | # Generalized Hermite: \GenHermiteH{n}@{x} |
319 | 'search' => |
320 | "~\\\\GenHermiteH" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
321 | ")~i", |
322 | # Hermite: HermiteH[n,x] |
323 | 'replace' => static function ( array $m ) { |
324 | return 'HermiteH[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[2] ) . |
325 | ']'; |
326 | } |
327 | ], |
328 | [ |
329 | # HurwitzZeta: \HurwitzZeta@{s}{a} |
330 | 'search' => |
331 | "~\\\\HurwitzZeta@?(" . $this->arg . "|" . $this->par . ")(" . $this->arg . |
332 | "|" . $this->par . ")~i", |
333 | # HurwitzZeta: HurwitzZeta[s,a] |
334 | 'replace' => static function ( array $m ) { |
335 | return 'HurwitzZeta[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[4] ) . |
336 | ']'; |
337 | } |
338 | ], |
339 | [ |
340 | # Hypergeometric: \HypergeoF@{a}{b}{c}{d} |
341 | 'search' => |
342 | "~\\\\HypergeoF(@{0,3})" . $this->par . $this->par . $this->par . $this->par . |
343 | "~i", |
344 | # Hypergeometric: Hypergeometric2F1[a,b,c,d] |
345 | 'replace' => static function ( array $m ) { |
346 | return 'Hypergeometric2F1[' . $m[2] . ',' . $m[3] . ',' . $m[4] . ',' . $m[5] . |
347 | ']'; |
348 | } |
349 | ], |
350 | [ |
351 | # Hypergeometric (Generalized): \HyperpFq{p}{q}@{{\bf a}}{{\bf b}}{z} |
352 | 'search' => |
353 | "~\\\\HyperpFq(" . $this->arg . "|" . $this->par . ")(" . $this->arg . "|" . |
354 | $this->par . ")@{0,3}(" . $this->arg . "|" . $this->par . ")(" . $this->arg . |
355 | "|" . $this->par . ")(" . $this->arg . "|" . $this->par . ")~i", |
356 | # Hypergeometric (Generalized): HypergeometricPFQ[a,b,c] |
357 | 'replace' => static function ( array $m ) { |
358 | return 'HypergeometricPFQ[' . $m[7] . ',' . $m[10] . ',' . |
359 | LaTeXTranslator::brackR( $m[13] ) . ']'; |
360 | } |
361 | ], |
362 | [ |
363 | # Incomplete Beta & Gamma: \IncBeta{x}@{a}{b}, \IncGamma@{a}{z} |
364 | 'search' => "~\\\\Inc(Beta|Gamma)" . $this->par . "?@{0,2}(" . $this->arg . "|" . |
365 | $this->par . ")(" . $this->arg . "|" . $this->par . ")~i", |
366 | # Incomplete Beta & Gamma: Beta[z,a,b], Gamma[a,z] |
367 | 'replace' => static function ( array $m ) { |
368 | return $m[1] . '[' . |
369 | ( strlen( $m[2] ) > 0 ? LaTeXTranslator::brackR( $m[2] ) . ',' : '' ) . |
370 | LaTeXTranslator::brackR( $m[3] ) . ',' . |
371 | LaTeXTranslator::brackR( $m[6] ) . ']'; |
372 | } |
373 | ], |
374 | [ |
375 | # Inverse Error (including complementary): \inverfc@{x} |
376 | 'search' => "~\\\\inverf(c)?@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
377 | # Inverse Error (including complementary): InverseErfc[x] |
378 | 'replace' => static function ( array $m ) { |
379 | return 'InverseErf' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
380 | } |
381 | ], |
382 | [ |
383 | # Imaginary Unit: \iunit |
384 | 'search' => "~\\\\iunit~i", |
385 | # Imaginary Unit: I return 'I';} |
386 | 'replace' => static function () { |
387 | return 'I'; |
388 | } |
389 | ], |
390 | [ |
391 | # Jacobi Elliptics: \Jacobisd@{z}{k} |
392 | 'search' => |
393 | "~\\\\(arc)?Jacobi(Zeta|[a-z]{2})@{0,2}(" . $this->arg . "|" . $this->par . |
394 | ")(" . $this->arg . "|" . $this->par . ")~i", |
395 | # Jacobi Elliptics: JacobiSD[u,m] |
396 | 'replace' => static function ( array $m ) { |
397 | return ( strlen( $m[1] ) > 0 ? 'Inverse' : '' ) . 'Jacobi' . |
398 | ( strlen( $m[2] ) == 2 ? strtoupper( $m[2] ) : 'Zeta' ) . '[' . |
399 | LaTeXTranslator::brackR( $m[3] ) . ', Sqrt[' . LaTeXTranslator::brackR( $m[6] ) . ']]'; |
400 | } |
401 | ], |
402 | [ |
403 | # Jacobi Polynomials: \JacobiP{\alpha}{\beta}{n}@{x} |
404 | 'search' => |
405 | "~\\\\JacobiP" . $this->par . $this->par . $this->par . "@{0,2}(" . $this->arg . |
406 | "|" . $this->par . ")~i", |
407 | # Jacobi Polynomial: JacobiP[n,a,b,x] |
408 | 'replace' => static function ( array $m ) { |
409 | return 'JacobiP[' . |
410 | LaTeXTranslator::brackR( $m[2] ) . ',' . |
411 | LaTeXTranslator::brackR( $m[1] ) . ',' . |
412 | LaTeXTranslator::brackR( $m[3] ) . ',' . |
413 | LaTeXTranslator::brackR( $m[4] ) . ']'; |
414 | } |
415 | ], |
416 | [ |
417 | # Kelvin: \Kelvinber{\nu}@{x} |
418 | 'search' => "~\\\\Kelvin([bk]e[ri])(" . $this->par . ")@{0,2}(" . $this->arg . "|" . |
419 | $this->par . ")?~i", |
420 | # Kelvin: KelvinBer[n,z] |
421 | 'replace' => static function ( array $m ) { |
422 | return 'Kelvin' . ucfirst( $m[1] ) . '[' . LaTeXTranslator::brackR( $m[2] ) . |
423 | ( strlen( LaTeXTranslator::brackR( $m[4] ) ) > 0 ? ',' . LaTeXTranslator::brackR( $m[4] ) |
424 | : '' ) . ']'; |
425 | } |
426 | ], |
427 | [ |
428 | # Klein Invariant: \ModularJ@{\tau} |
429 | 'search' => "~\\\\ModularJ" . $this->par . "~i", |
430 | # Klein Invariant: KleinInvariantJ[\tau] |
431 | 'replace' => static function ( array $m ) { |
432 | return 'KleinInvariantJ[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
433 | } |
434 | ], |
435 | [ |
436 | # Kronecker: \Kronecker{j}{k} |
437 | 'search' => "~\\\\Kronecker" . $this->par . $this->par . "~i", |
438 | # Kronecker: Kronecker[j,k] |
439 | 'replace' => static function ( array $m ) { |
440 | return 'KroneckerDelta[' . |
441 | LaTeXTranslator::brackR( $m[1] ) . ',' . |
442 | LaTeXTranslator::brackR( $m[2] ) . ']'; |
443 | } |
444 | ], |
445 | [ |
446 | # LaguerreL[\a]{n}@{x} |
447 | 'search' => |
448 | "~\\\\LaguerreL(\\[.*\\])?" . $this->par . "@?(" . $this->arg . "|" . $this->par . |
449 | ")~i", |
450 | # LaguerreL: LaguerreL[n,a,x] |
451 | 'replace' => static function ( array $m ) { |
452 | return 'LaguerreL[' . LaTeXTranslator::brackR( $m[2] ) . ',' . |
453 | ( strlen( LaTeXTranslator::brackR( $m[1] ) ) > 0 ? LaTeXTranslator::brackR( $m[1] ) . ',' |
454 | : '' ) . LaTeXTranslator::brackR( $m[3] ) . ']'; |
455 | } |
456 | ], |
457 | [ |
458 | # Legendre/Ferrers: \LegendreP[\mu]{\nu}@{x} | \FerrersP[\mu]{\nu}@{x} |
459 | 'search' => |
460 | "~\\\\(?>Legendre|Ferrers)([PQ]|Poly)(\\[(?>[^{}]|(?-1))*\\])?" . $this->par . |
461 | "@?(" . $this->arg . "|" . $this->par . ")?~i", |
462 | # Legendre/Ferrers: LegendreP[\nu,x] | LegendreP[\nu,\mu,x] |
463 | 'replace' => static function ( array $m ) { |
464 | return 'Legendre' . $m[1] . '[' . LaTeXTranslator::brackR( $m[3] ) . ',' . |
465 | ( strlen( LaTeXTranslator::brackR( $m[2] ) ) > 0 ? LaTeXTranslator::brackR( $m[2] ) . ',' |
466 | : '' ) . LaTeXTranslator::brackR( $m[5] ) . ']'; |
467 | } |
468 | ], |
469 | [ |
470 | # LerchPhi: \LerchPhi@{z}{s}{a} |
471 | 'search' => |
472 | "~\\\\LerchPhi@{0,2}(" . $this->arg . "|" . $this->par . ")(" . $this->arg . |
473 | "|" . $this->par . ")(" . $this->arg . "|" . $this->par . ")~i", |
474 | # LerchPhi: LerchPhi[z,s,a] |
475 | 'replace' => static function ( array $m ) { |
476 | return 'LerchPhi[' . |
477 | LaTeXTranslator::brackR( $m[1] ) . ',' . |
478 | LaTeXTranslator::brackR( $m[4] ) . ',' . |
479 | LaTeXTranslator::brackR( $m[7] ) . ']'; |
480 | } |
481 | ], |
482 | [ |
483 | # Log Integral: \LogInt@{x} |
484 | 'search' => "~\\\\LogInt@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
485 | # Log Integral: LogIntegral[x] |
486 | 'replace' => static function ( array $m ) { |
487 | return 'LogIntegral[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
488 | } |
489 | ], |
490 | [ |
491 | # Mittag-Leffler: \MittagLeffler{a}{b}@{z} |
492 | 'search' => |
493 | "~\\\\MittagLeffler" . $this->par . $this->par . "@{0,2}(" . $this->arg . "|" . |
494 | $this->par . ")~i", |
495 | # Mittag-Leffler: MittagLefflerE[\alpha,\beta,z] |
496 | 'replace' => static function ( array $m ) { |
497 | return 'MittagLefflerE[' . |
498 | LaTeXTranslator::brackR( $m[1] ) . ',' . |
499 | LaTeXTranslator::brackR( $m[2] ) . ',' . |
500 | LaTeXTranslator::brackR( $m[3] ) . ']'; |
501 | } |
502 | ], |
503 | [ |
504 | # Modulus: n \mod m |
505 | 'search' => |
506 | "~(" . $this->arg . "|" . $this->par . ")\\\\mod@{0,2}(" . $this->arg . "|" . |
507 | $this->par . ")~i", |
508 | # Modulus: Mod[m,n] |
509 | 'replace' => static function ( array $m ) { |
510 | return 'Mod[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[4] ) . ']'; |
511 | } |
512 | ], |
513 | [ |
514 | # Permutations: \Permutations{n} |
515 | 'search' => "~\\\\Permutations@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
516 | # Permutations: Permutations[n] |
517 | 'replace' => static function ( array $m ) { |
518 | return 'Permutations[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
519 | } |
520 | ], |
521 | [ |
522 | # Pochhammer: \pochammer{a}{n} |
523 | 'search' => "~\\\\pochhammer@{0,2}" . $this->par . $this->par . "~i", |
524 | # Pochhammer: Pochhammer[a,n] |
525 | 'replace' => static function ( array $m ) { |
526 | return 'Pochhammer[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[2] ) . |
527 | ']'; |
528 | } |
529 | ], |
530 | [ |
531 | # PolyGamma: \polygamma{n}@{z} |
532 | 'search' => |
533 | "~\\\\Polygamma" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
534 | ")~i", |
535 | # PolyGamma: PolyGamma[n,z] |
536 | 'replace' => static function ( array $m ) { |
537 | return 'PolyLog[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
538 | } |
539 | ], |
540 | [ |
541 | # PolyLog: \Polylogarithms{x}@{z} |
542 | 'search' => |
543 | "~\\\\Polylogarithm" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
544 | ")~i", |
545 | # PolyLog: PolyLog[x,z] |
546 | 'replace' => static function ( array $m ) { |
547 | return 'PolyLog[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
548 | } |
549 | ], |
550 | [ |
551 | # Q Factorial: \qFactorial{a}{q}{n} |
552 | 'search' => "~\\\\qFactorial@{0,2}" . $this->par . $this->par . $this->par . "~i", |
553 | # Q Factorial: QFactorial[a,q,n] |
554 | 'replace' => static function ( array $m ) { |
555 | return 'QFactorial[' . LaTeXTranslator::brackR( $m[2] ) . ',' . LaTeXTranslator::brackR( $m[3] ) . |
556 | ']'; |
557 | } |
558 | ], |
559 | [ |
560 | # Q Gamma: \qGamma{q}@{z} |
561 | 'search' => "~\\\\qGamma" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
562 | ")~i", |
563 | # Q Gamma: QGamma[z,q] |
564 | 'replace' => static function ( array $m ) { |
565 | return 'QGamma[' . LaTeXTranslator::brackR( $m[2] ) . ',' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
566 | } |
567 | ], |
568 | [ |
569 | # Ramanujan Tau: \RamanujanTau@{k} |
570 | 'search' => "~\\\\RamanujanTau@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
571 | # Ramanujan Tau: RamanujanTau[k] |
572 | 'replace' => static function ( array $m ) { |
573 | return 'RamanujanTau[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
574 | } |
575 | ], |
576 | [ |
577 | # Real Part: \realpart{z} |
578 | 'search' => "~\\\\realpart@{0,2}" . $this->par . "~i", |
579 | # Real Part: Re[z] |
580 | 'replace' => static function ( array $m ) { |
581 | return 'Re[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
582 | } |
583 | ], |
584 | [ |
585 | # Riemann: \RiemannXi@{s} |
586 | 'search' => "~\\\\Riemann(Xi)@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
587 | # Riemann: RiemannXi[s] |
588 | 'replace' => static function ( array $m ) { |
589 | return 'Riemann' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
590 | } |
591 | ], |
592 | [ |
593 | # Scorer: \ScorerHi@{z} |
594 | 'search' => "~\\\\Scorer([G|H]i)@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
595 | # Scorer: ScorerHi[z] |
596 | 'replace' => static function ( array $m ) { |
597 | return 'Scorer' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
598 | } |
599 | ], |
600 | [ |
601 | # Sign: \sign@{x} |
602 | 'search' => "~\\\\sign@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
603 | # Sign: Sign[z] |
604 | 'replace' => static function ( array $m ) { |
605 | return 'Sign[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
606 | } |
607 | ], |
608 | [ |
609 | # Sin Integral: \SinInt@{x} |
610 | 'search' => "~\\\\Sin(h?)Int@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
611 | # Sin Integral: SinInt[z] |
612 | 'replace' => static function ( array $m ) { |
613 | return 'Sin' . $m[1] . 'Integral[' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
614 | } |
615 | ], |
616 | [ |
617 | # Spherical BesselJ/Y | HankelH1/H2: \SphBesselJ{n}@{z} |
618 | 'search' => |
619 | "~\\\\Sph(Bessel|Hankel)(J|Y|Hii?)" . $this->par . "@{0,2}(" . $this->arg . |
620 | "|" . $this->par . ")~i", |
621 | # Spherical BesselJ/Y | HankelH1/H2: SphericalBesselJ[n,z] |
622 | 'replace' => static function ( array $m ) { |
623 | return 'Spherical' . $m[1] . '' . ( substr( $m[2], 0, 2 ) !== 'Hi' |
624 | ? $m[2] : 'H' . ( strlen( $m[2] ) - 1 ) ) . '[' . LaTeXTranslator::brackR( $m[3] ) . |
625 | ',' . LaTeXTranslator::brackR( $m[4] ) . ']'; |
626 | } |
627 | ], |
628 | [ |
629 | # Spherical Harmonic: \SphericalHarmonicY{l}{m}@{\theta}{\phi} |
630 | 'search' => |
631 | "~\\\\SphericalHarmonicY" . $this->par . $this->par . "@?(" . $this->arg . "|" . |
632 | $this->par . ")?(" . $this->arg . "|" . $this->par . ")?~i", |
633 | # Spherical Harmonic: SphericalHarmonicY[l,m,\theta,\phi] |
634 | 'replace' => static function ( array $m ) { |
635 | return 'SphericalHarmonicY[' . LaTeXTranslator::brackR( $m[1] ) . ',' . |
636 | LaTeXTranslator::brackR( $m[2] ) . ',' . LaTeXTranslator::brackR( $m[3] ) . ',' . |
637 | LaTeXTranslator::brackR( $m[6] ) . ']'; |
638 | } |
639 | ], |
640 | [ |
641 | # Spheroidal Eigenvalue: \SpheroidalEigenvalueLambda{m}{n}@{\gamma} |
642 | 'search' => "~\\\\SpheroidalEigenvalueLambda" . $this->par . $this->par . "@?(" . |
643 | $this->arg . "|" . $this->par . ")?~i", |
644 | # Spheroidal Eigenvalue: SpheroidalEigenvalue[n,m,\gamma] |
645 | 'replace' => static function ( array $m ) { |
646 | return 'SpheroidalEigenvalue[' . LaTeXTranslator::brackR( $m[1] ) . ',' . |
647 | LaTeXTranslator::brackR( $m[2] ) . ',' . LaTeXTranslator::brackR( $m[3] ) . ']'; |
648 | } |
649 | ], |
650 | [ |
651 | # Spheroidal Ps: \SpheroidalPs{m}{n}@{z}{\gamma^2} |
652 | 'search' => |
653 | "~\\\\Spheroidal(P|Q)s" . $this->par . $this->par . "@?(" . $this->arg . "|" . |
654 | $this->par . ")?(" . $this->arg . "|" . $this->par . ")?~i", |
655 | # Spheroidal Ps: SpheroidalPs[n,m,\gamma,z] |
656 | 'replace' => static function ( array $m ) { |
657 | return 'Spheroidal' . $m[1] . 'S[' . LaTeXTranslator::brackR( $m[2] ) . ',' . |
658 | LaTeXTranslator::brackR( $m[3] ) . ',Sqrt[' . LaTeXTranslator::brackR( $m[7] ) . '],' . |
659 | LaTeXTranslator::brackR( $m[4] ) . ']'; |
660 | } |
661 | ], |
662 | [ |
663 | # Sqrt: \sqrt@{x} |
664 | 'search' => "~\\\\sqrt@{0,2}(" . $this->arg . "|" . $this->par . ")~i", |
665 | # Sqrt: Sqrt[x] |
666 | 'replace' => static function ( array $m ) { |
667 | return 'Sqrt[' . LaTeXTranslator::brackR( $m[1] ) . ']'; |
668 | } |
669 | ], |
670 | [ |
671 | # StruveH: \StruveH{\nu}@{z} |
672 | 'search' => |
673 | "~\\\\Struve(H|L)" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
674 | ")~i", |
675 | # StruveH: StruveH[n,z] |
676 | 'replace' => static function ( array $m ) { |
677 | return 'Struve' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . ',' . |
678 | LaTeXTranslator::brackR( $m[3] ) . ']'; |
679 | } |
680 | ], |
681 | [ |
682 | # WeberE: \WeberE{\nu}@{z} |
683 | 'search' => "~\\\\WeberE" . $this->par . "@{0,2}(" . $this->arg . "|" . $this->par . |
684 | ")~i", |
685 | # WeberE: WeberE[\nu,z] |
686 | 'replace' => static function ( array $m ) { |
687 | return 'WeberE[' . LaTeXTranslator::brackR( $m[1] ) . ',' . LaTeXTranslator::brackR( $m[2] ) . ']'; |
688 | } |
689 | ], |
690 | [ |
691 | # Whittaker: \WhittakerM{\kappa}{\mu}@{z} |
692 | 'search' => |
693 | "~\\\\Whit(M|W)" . $this->par . $this->par . "@{0,2}(" . $this->arg . "|" . |
694 | $this->par . ")~i", |
695 | # Whittaker: WhittakerW[k,m,z] |
696 | 'replace' => static function ( array $m ) { |
697 | return 'Whittaker' . $m[1] . '[' . LaTeXTranslator::brackR( $m[2] ) . ',' . |
698 | LaTeXTranslator::brackR( $m[3] ) . ',' . LaTeXTranslator::brackR( $m[4] ) . ']'; |
699 | } |
700 | ] |
701 | ]; |
702 | } |
703 | |
704 | /** |
705 | * @var string contains data in Wiki html input form |
706 | */ |
707 | |
708 | /** |
709 | * Returns LaTeX arguments without curly brackets |
710 | * @param string $arg |
711 | * @return string |
712 | */ |
713 | public static function brackR( $arg ) { |
714 | $arg = trim( $arg, " " ); |
715 | if ( substr( $arg, 0, 1 ) == "{" && substr( $arg, -1 ) == "}" ) { |
716 | $arg = substr( $arg, 1, strlen( $arg ) - 2 ); |
717 | } |
718 | return $arg; |
719 | } |
720 | |
721 | /** |
722 | * Processes the submitted Form input |
723 | * @param string $data |
724 | * @return string |
725 | */ |
726 | public function processInput( $data ) { |
727 | foreach ( $this->replacements as $set ) { |
728 | $data = |
729 | preg_replace_callback( $set['search'], |
730 | // select the correct replacement callback depending on $allowimgcode |
731 | $set['replace'], $data ); |
732 | } |
733 | return $data; |
734 | } |
735 | } |