-
Notifications
You must be signed in to change notification settings - Fork 59
/
EvaluationTests.cs
677 lines (676 loc) · 49 KB
/
EvaluationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
using System.Linq;
using System.Text.RegularExpressions;
using Xunit;
using AngouriMath;
namespace CSharpMath.EvaluationTests {
using Atom;
public class EvaluationTests {
internal static MathList ParseLaTeX(string latex) =>
LaTeXParser.MathListFromLaTeX(latex).Match(list => list, e => throw new Xunit.Sdk.XunitException(e));
static Evaluation.MathItem ParseMath(string latex) =>
Evaluation.Evaluate(ParseLaTeX(latex)).Match(entity => entity, e => throw new Xunit.Sdk.XunitException(e));
void Test(string input, string converted, string? result) {
void Test(string input) {
var math = ParseMath(input);
Assert.NotNull(math);
Assert.Equal(converted, LaTeXParser.MathListToLaTeX(Evaluation.Visualize(math)).ToString());
// Ensure that the converted entity is valid by simplifying it
if (result != null)
Assert.Equal(result,
LaTeXParser.MathListToLaTeX(Evaluation.Visualize(Assert.IsType<Evaluation.MathItem.Entity>(math).Content.Simplify())).ToString());
else Assert.IsNotType<Evaluation.MathItem.Entity>(result);
}
Test(input);
// This regex balances (, [ and \{ with ), ] and \} into one group, then inserts \left and \right
// But does not do this for \sqrt's [ and ]
Test(Regex.Replace(input, @"(?<!\\sqrt)(\(|\[|\\\{)((?:(?!\(|\[|\\\\{|\)|\]|\\\\}).|(?<open>\(|\[|\\\\{)|(?<-open>\)|\]|\\\\}))+(?(open)(?!)))(\)|\]|\\\\})", @"\left$1$2\right$3"));
}
[Theory]
[InlineData("1", "1", "1")]
[InlineData("01", "1", "1")]
[InlineData("10", "10", "10")]
[InlineData("010", "10", "10")]
[InlineData("1.", "1", "1")]
[InlineData("01.", "1", "1")]
[InlineData("1.0", "1", "1")]
[InlineData("01.0", "1", "1")]
[InlineData(".1", @"\frac{1}{10}", @"\frac{1}{10}")]
[InlineData(".10", @"\frac{1}{10}", @"\frac{1}{10}")]
[InlineData("1.1", @"\frac{11}{10}", @"\frac{11}{10}")]
[InlineData("01.1", @"\frac{11}{10}", @"\frac{11}{10}")]
[InlineData("1.10", @"\frac{11}{10}", @"\frac{11}{10}")]
[InlineData("01.10", @"\frac{11}{10}", @"\frac{11}{10}")]
[InlineData("0.1", @"\frac{1}{10}", @"\frac{1}{10}")]
[InlineData("00.1", @"\frac{1}{10}", @"\frac{1}{10}")]
[InlineData("0.10", @"\frac{1}{10}", @"\frac{1}{10}")]
[InlineData("00.10", @"\frac{1}{10}", @"\frac{1}{10}")]
[InlineData("1234", "1234", "1234")]
[InlineData("0123456789", "123456789", "123456789")]
[InlineData("1234.", "1234", "1234")]
[InlineData(".5678", @"\frac{2839}{5000}", @"\frac{2839}{5000}")]
[InlineData(".9876543210", "0.9876543210", "0.9876543210")]
[InlineData("1234.5678", @"\frac{6172839}{5000}", @"\frac{6172839}{5000}")]
[InlineData(@"\infty", @"\infty ", @"\infty ")]
public void Numbers(string input, string converted, string output) =>
Test(input, converted, output);
[Theory]
[InlineData("a", "a", "a")]
[InlineData("ab", @"a\times b", @"a\times b")]
[InlineData("abc", @"a\times b\times c", @"a\times b\times c")]
[InlineData("3a", @"3\times a", @"3\times a")]
[InlineData("3ab", @"3\times a\times b", @"3\times a\times b")]
[InlineData("3a3", @"3\times a\times 3", @"9\times a")]
[InlineData("3aa", @"3\times a\times a", @"3\times a^2")]
[InlineData(@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
@"a\times b\times c\times d\times e\times f\times g\times h\times i\times j\times k\times l\times m\times " +
@"n\times o\times p\times q\times r\times s\times t\times u\times v\times w\times x\times y\times z\times " +
@"A\times B\times C\times D\times E\times F\times G\times H\times I\times J\times K\times L\times M\times " +
@"N\times O\times P\times Q\times R\times S\times T\times U\times V\times W\times X\times Y\times Z",
// i is considered as a number instead of a variable like other alphabets, so it is sorted to the front
@"i\times a\times A\times b\times B\times c\times C\times d\times D\times e\times E\times f\times F\times " +
@"g\times G\times h\times H\times I\times j\times J\times k\times K\times l\times L\times m\times M\times " +
@"n\times N\times o\times O\times p\times P\times q\times Q\times r\times R\times s\times S\times t\times " +
@"T\times u\times U\times v\times V\times w\times W\times x\times X\times y\times Y\times z\times Z")]
[InlineData(@"\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\iota\kappa\varkappa" +
@"\lambda\mu\nu\xi\omicron\pi\varpi\rho\varrho\sigma\varsigma\tau\upsilon\phi\varphi\chi" +
@"\psi\omega\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega",
@"\alpha \times \beta \times \gamma \times \delta \times \epsilon \times \varepsilon \times \zeta " +
@"\times \eta \times \theta \times \iota \times \kappa \times \varkappa \times \lambda \times \mu " +
@"\times \nu \times \xi \times \omicron \times \pi \times \varpi \times \rho \times \varrho " +
@"\times \sigma \times \varsigma \times \tau \times \upsilon \times \phi \times \varphi \times \chi " +
@"\times \psi \times \omega \times \Gamma \times \Delta \times \Theta \times \Lambda \times \Xi " +
@"\times \Pi \times \Sigma \times \Upsilon \times \Phi \times \Psi \times \Omega ",
@"\alpha \times \beta \times \chi \times \delta \times \Delta \times \epsilon \times \eta " +
@"\times \gamma \times \Gamma \times \iota \times \kappa \times \lambda \times \Lambda \times \mu " +
@"\times \nu \times \omega \times \Omega \times \omicron \times \phi \times \Phi \times \Pi " +
@"\times \psi \times \Psi \times \rho \times \sigma \times \Sigma \times \tau \times \theta " +
@"\times \Theta \times \upsilon \times \Upsilon \times \varepsilon \times \varkappa \times \varphi " +
@"\times \varpi \times \varrho \times \varsigma \times \xi \times \Xi \times \zeta \times \pi ")]
[InlineData(@"a_2", @"a_2", @"a_2")]
[InlineData(@"a_2+a_2", @"a_2+a_2", @"2\times a_2")]
[InlineData(@"a_{23}", @"a_{23}", @"a_{23}")]
[InlineData(@"\pi_a", @"\pi _a", @"\pi _a")]
[InlineData(@"ii", @"i\times i", @"-1")]
[InlineData(@"i\infty", @"i\times \infty ", @"\infty i")]
[InlineData(@"\infty\infty", @"\infty \times \infty ", @"\infty ")]
public void Variables(string input, string converted, string result) => Test(input, converted, result);
[Theory]
[InlineData("a + b", @"a+b", "a+b")]
[InlineData("a - b", @"a-b", "a-b")]
[InlineData("a * b", @"a\times b", @"a\times b")]
[InlineData(@"a\times b", @"a\times b", @"a\times b")]
[InlineData(@"a\cdot b", @"a\times b", @"a\times b")]
[InlineData(@"a / b", @"\frac{a}{b}", @"\frac{a}{b}")]
[InlineData(@"a\div b", @"\frac{a}{b}", @"\frac{a}{b}")]
[InlineData(@"\frac ab", @"\frac{a}{b}", @"\frac{a}{b}")]
[InlineData("a + b + c", @"a+b+c", "a+b+c")]
[InlineData("a + b - c", @"a+b-c", "a+b-c")]
[InlineData("a + b * c", @"a+b\times c", @"a+b\times c")]
[InlineData("a + b / c", @"a+\frac{b}{c}", @"a+\frac{b}{c}")]
[InlineData("a - b + c", @"a-b+c", "a-b+c")]
[InlineData("a - b - c", @"a-b-c", @"a-b-c")]
[InlineData("a - b * c", @"a-b\times c", @"a-b\times c")]
[InlineData("a - b / c", @"a-\frac{b}{c}", @"a-\frac{b}{c}")]
[InlineData("a * b + c", @"a\times b+c", @"a\times b+c")]
[InlineData("a * b - c", @"a\times b-c", @"a\times b-c")]
[InlineData("a * b * c", @"a\times b\times c", @"a\times b\times c")]
[InlineData("a * b / c", @"\frac{a\times b}{c}", @"\frac{a\times b}{c}")]
[InlineData("a / b + c", @"\frac{a}{b}+c", @"\frac{a}{b}+c")]
[InlineData("a / b - c", @"\frac{a}{b}-c", @"\frac{a}{b}-c")]
[InlineData("a / b * c", @"\frac{a}{b}\times c", @"\frac{a}{b}\times c")]
[InlineData("a / b / c", @"\frac{\frac{a}{b}}{c}", @"\frac{a}{b\times c}")]
[InlineData(@"2+\frac ab", @"2+\frac{a}{b}", @"2+\frac{a}{b}")]
[InlineData(@"\frac ab+2", @"\frac{a}{b}+2", @"\frac{a}{b}+2")]
[InlineData(@"2-\frac ab", @"2-\frac{a}{b}", @"2-\frac{a}{b}")]
[InlineData(@"\frac ab-2", @"\frac{a}{b}-2", @"\frac{a}{b}-2")]
[InlineData(@"2*\frac ab", @"2\times \frac{a}{b}", @"2\times \frac{a}{b}")]
[InlineData(@"\frac ab*2", @"\frac{a}{b}\times 2", @"\frac{a}{b}\times 2")]
[InlineData(@"2/\frac ab", @"\frac{2}{\frac{a}{b}}", @"2\times \frac{b}{a}")]
[InlineData(@"\frac ab/2", @"\frac{\frac{a}{b}}{2}", @"\frac{\frac{1}{2}\times a}{b}")]
[InlineData(@"1+i", @"1+i", @"1+i")]
[InlineData(@"1-i", @"1-i", @"1-i")]
[InlineData(@"i+1", @"i+1", @"1+i")]
[InlineData(@"i-1", @"i-1", @"-1+i")]
[InlineData(@"\infty+1", @"\infty +1", @"\infty ")]
[InlineData(@"\infty+i", @"\infty +i", @"\infty +i")]
[InlineData(@"\infty+\infty", @"\infty +\infty ", @"\infty ")]
[InlineData(@"\infty\times \infty", @"\infty \times \infty ", @"\infty ")]
[InlineData(@"i\times \infty", @"i\times \infty ", @"\infty i")]
[InlineData(@"\infty\times i", @"\infty \times i", @"\infty i")]
[InlineData(@"i\times i", @"i\times i", @"-1")]
[InlineData(@"\frac00", @"\frac{0}{0}", @"\mathrm{undefined}")]
[InlineData(@"\frac0\infty", @"\frac{0}{\infty }", @"0")]
[InlineData(@"\frac2\infty", @"\frac{2}{\infty }", @"0")]
[InlineData(@"\frac{-2}\infty", @"\frac{-2}{\infty }", @"0")]
[InlineData(@"\frac20", @"\frac{2}{0}", @"\mathrm{undefined}")]
[InlineData(@"\frac{-2}0", @"\frac{-2}{0}", @"\mathrm{undefined}")]
[InlineData(@"\frac\infty0", @"\frac{\infty }{0}", @"\mathrm{undefined}")]
[InlineData(@"\frac{-\infty}0", @"\frac{-\infty }{0}", @"\mathrm{undefined}")]
[InlineData(@"\frac\infty\infty", @"\frac{\infty }{\infty }", @"\mathrm{undefined}")]
[InlineData(@"\frac{-\infty}{\infty}", @"\frac{-\infty }{\infty }", @"\mathrm{undefined}")]
public void BinaryOperators(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData("+i", "i", "i")]
[InlineData("-i", "-i", "-i")]
[InlineData("+a", "a", "a")]
[InlineData("-a", "-a", "-a")]
[InlineData("++a", "a", "a")]
[InlineData("+-a", "-a", "-a")]
[InlineData("-+a", "-a", "-a")]
[InlineData("--a", "--a", "a")]
[InlineData("+++a", "a", "a")]
[InlineData("---a", "---a", "-a")]
[InlineData("a++a", "a+a", @"2\times a")]
[InlineData("a+-a", "a-a", "0")]
[InlineData("a-+a", "a-a", "0")]
[InlineData("a--a", "a--a", @"2\times a")]
[InlineData("a+++a", "a+a", @"2\times a")]
[InlineData("a---a", "a---a", "0")]
[InlineData("a*+a", @"a\times a", "a^2")]
[InlineData("a*-a", @"a\times -a", "-a^2")]
[InlineData("+a*+a", @"a\times a", "a^2")]
[InlineData("-a*-a", @"-a\times -a", "a^2")]
[InlineData("a/+a", @"\frac{a}{a}", "1")]
[InlineData("a/-a", @"\frac{a}{-a}", "-1")]
[InlineData("+a/+a", @"\frac{a}{a}", "1")]
[InlineData("-a/-a", @"\frac{-a}{-a}", "1")]
[InlineData("-2+-2+-2", @"-2-2-2", "-6")]
[InlineData("-2--2--2", @"-2--2--2", "2")]
[InlineData("-2*-2*-2", @"-2\times -2\times -2", "-8")]
[InlineData("-2/-2/-2", @"\frac{\frac{-2}{-2}}{-2}", @"\frac{-1}{2}")]
public void UnaryOperators(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData(@"9\%", @"\frac{9}{100}", @"\frac{9}{100}")]
[InlineData(@"a\%", @"\frac{a}{100}", @"\frac{1}{100}\times a")]
[InlineData(@"\pi\%", @"\frac{\pi }{100}", @"\frac{1}{100}\times \pi ")]
[InlineData(@"a\%\%", @"\frac{\frac{a}{100}}{100}", @"\frac{1}{10000}\times a")]
[InlineData(@"9\%+3", @"\frac{9}{100}+3", @"\frac{309}{100}")]
[InlineData(@"-9\%+3", @"-\frac{9}{100}+3", @"\frac{291}{100}")]
[InlineData(@"2^2\%", @"\frac{2^2}{100}", @"\frac{1}{25}")]
[InlineData(@"2\%^2", @"\left( \frac{2}{100}\right) ^2", @"\frac{1}{2500}")]
[InlineData(@"2\%2", @"\frac{2}{100}\times 2", @"\frac{1}{25}")]
[InlineData(@"1+2\%^2", @"1+\left( \frac{2}{100}\right) ^2", @"\frac{2501}{2500}")]
[InlineData(@"9\degree", @"\frac{9\times \pi }{180}", @"\frac{1}{20}\times \pi ")]
[InlineData(@"a\degree", @"\frac{a\times \pi }{180}", @"\frac{1}{180}\times a\times \pi ")]
[InlineData(@"\pi\degree", @"\frac{\pi \times \pi }{180}", @"\frac{1}{180}\times \pi ^2")]
[InlineData(@"a\%\degree", @"\frac{\frac{a}{100}\times \pi }{180}", @"\frac{1}{18000}\times a\times \pi ")]
[InlineData(@"a\degree\degree", @"\frac{\frac{a\times \pi }{180}\times \pi }{180}", @"\frac{1}{32400}\times a\times \pi ^2")]
[InlineData(@"9\degree+3", @"\frac{9\times \pi }{180}+3", @"3+\frac{1}{20}\times \pi ")]
[InlineData(@"-9\degree+3", @"-\frac{9\times \pi }{180}+3", @"3+\frac{-1}{20}\times \pi ")]
[InlineData(@"2^2\degree", @"\frac{2^2\times \pi }{180}", @"\frac{1}{45}\times \pi ")]
[InlineData(@"2\degree^2", @"\left( \frac{2\times \pi }{180}\right) ^2", @"\left( \frac{1}{90}\times \pi \right) ^2")]
[InlineData(@"2\degree2", @"\frac{2\times \pi }{180}\times 2", @"\frac{1}{45}\times \pi ")]
[InlineData(@"1+2\degree^2", @"1+\left( \frac{2\times \pi }{180}\right) ^2", @"1+\left( \frac{1}{90}\times \pi \right) ^2")]
public void PostfixOperators(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData("2^2", "2^2", "4")]
[InlineData(".2^2", @"\left( \frac{1}{5}\right) ^2", @"\frac{1}{25}")]
[InlineData("2.^2", "2^2", "4")]
[InlineData("2.1^2", @"\left( \frac{21}{10}\right) ^2", @"\frac{441}{100}")]
[InlineData("a^a", "a^a", "a^a")]
[InlineData("a^{a+b}", "a^{a+b}", "a^{a+b}")]
[InlineData("a^{-2}", "a^{-2}", "a^{-2}")]
[InlineData("2^{3^4}", "2^{3^4}", "2417851639229258349412352")]
[InlineData("4^{3^2}", "4^{3^2}", "262144")]
[InlineData("4^3+2", "4^3+2", "66")]
[InlineData("2+3^4", "2+3^4", "83")]
[InlineData("4^3*2", @"4^3\times 2", "128")]
[InlineData("2*3^4", @"2\times 3^4", "162")]
[InlineData("1/x", @"\frac{1}{x}", @"\frac{1}{x}")]
[InlineData("2/x", @"\frac{2}{x}", @"\frac{2}{x}")]
[InlineData("0^x", @"0^x", @"0")]
[InlineData("1^x", @"1^x", @"1")]
[InlineData("x^0", @"x^0", @"1")]
[InlineData("x^{-1}", @"x^{-1}", @"\frac{1}{x}")]
[InlineData("-i^{-1}", @"-i^{-1}", @"i")]
[InlineData("i^{-2}", @"i^{-2}", @"-1")]
[InlineData("i^{-1}", @"i^{-1}", @"-i")]
[InlineData("i^0", @"i^0", @"1")]
[InlineData("i^1", @"i^1", @"i")]
[InlineData("i^2", @"i^2", @"-1")]
[InlineData("i^3", @"i^3", @"-i")]
[InlineData("i^4", @"i^4", @"1")]
[InlineData("i^5", @"i^5", @"i")]
[InlineData("10^2", @"10^2", @"100")]
[InlineData(".1^2", @"\left( \frac{1}{10}\right) ^2", @"\frac{1}{100}")]
[InlineData("10^x", @"10^x", @"10^x")]
[InlineData(@"{\frac 12}^4", @"\left( \frac{1}{2}\right) ^4", @"\frac{1}{16}")]
[InlineData(@"\sqrt2", @"\sqrt{2}", @"\sqrt{2}")]
[InlineData(@"\sqrt2^2", @"\left( \sqrt{2}\right) ^2", "2")]
[InlineData(@"\sqrt[3]2", @"2^{\frac{1}{3}}", @"\sqrt[3]{2}")]
[InlineData(@"\sqrt[3/2]2", @"2^{\frac{1}{\frac{3}{2}}}", @"\sqrt[3]{2}^2")]
[InlineData(@"\sqrt[3]2^3", @"\left( 2^{\frac{1}{3}}\right) ^3", "2")]
[InlineData(@"\sqrt[3]2^{1+1+1}", @"\left( 2^{\frac{1}{3}}\right) ^{1+1+1}", "2")]
[InlineData(@"\sqrt[1+1+1]2^{1+1+1}", @"\left( 2^{\frac{1}{1+1+1}}\right) ^{1+1+1}", "2")]
public void Exponents(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData(@"\sin x", @"\sin \left( x\right) ", @"\sin \left( x\right) ")]
[InlineData(@"\cos x", @"\cos \left( x\right) ", @"\cos \left( x\right) ")]
[InlineData(@"\tan x", @"\tan \left( x\right) ", @"\tan \left( x\right) ")]
[InlineData(@"\cot x", @"\cot \left( x\right) ", @"\cot \left( x\right) ")]
[InlineData(@"\sec x", @"\frac{1}{\cos \left( x\right) }", @"\frac{1}{\cos \left( x\right) }")]
[InlineData(@"\csc x", @"\frac{1}{\sin \left( x\right) }", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\arcsin x", @"\arcsin \left( x\right) ", @"\arcsin \left( x\right) ")]
[InlineData(@"\arccos x", @"\arccos \left( x\right) ", @"\arccos \left( x\right) ")]
[InlineData(@"\arctan x", @"\arctan \left( x\right) ", @"\arctan \left( x\right) ")]
[InlineData(@"\arccot x", @"\arccot \left( x\right) ", @"\arccot \left( x\right) ")]
[InlineData(@"\arcsec x", @"\arccos \left( \frac{1}{x}\right) ", @"\arccos \left( \frac{1}{x}\right) ")]
[InlineData(@"\arccsc x", @"\arcsin \left( \frac{1}{x}\right) ", @"\arcsin \left( \frac{1}{x}\right) ")]
[InlineData(@"\ln x", @"\ln \left( x\right) ", @"\ln \left( x\right) ")]
[InlineData(@"\log x", @"\log \left( x\right) ", @"\log \left( x\right) ")]
[InlineData(@"\log_3 x", @"\log _3\left( x\right) ", @"\log _3\left( x\right) ")]
[InlineData(@"\log_{10} x", @"\log \left( x\right) ", @"\log \left( x\right) ")]
[InlineData(@"\log_e x", @"\ln \left( x\right) ", @"\ln \left( x\right) ")]
[InlineData(@"\ln x^2", @"\ln \left( x^2\right) ", @"\ln \left( x^2\right) ")]
[InlineData(@"\log x^2", @"\log \left( x^2\right) ", @"\log \left( x^2\right) ")]
[InlineData(@"\log_{10} x^2", @"\log \left( x^2\right) ", @"\log \left( x^2\right) ")]
[InlineData(@"\log_3 x^2", @"\log _3\left( x^2\right) ", @"\log _3\left( x^2\right) ")]
[InlineData(@"\log_e x^2", @"\ln \left( x^2\right) ", @"\ln \left( x^2\right) ")]
[InlineData(@"\ln x^{-1}", @"\ln \left( x^{-1}\right) ", @"\ln \left( \frac{1}{x}\right) ")]
[InlineData(@"\log x^{-1}", @"\log \left( x^{-1}\right) ", @"\log \left( \frac{1}{x}\right) ")]
[InlineData(@"\log_{10} x^{-1}", @"\log \left( x^{-1}\right) ", @"\log \left( \frac{1}{x}\right) ")]
[InlineData(@"\log_3 x^{-1}", @"\log _3\left( x^{-1}\right) ", @"\log _3\left( \frac{1}{x}\right) ")]
[InlineData(@"\log_e x^{-1}", @"\ln \left( x^{-1}\right) ", @"\ln \left( \frac{1}{x}\right) ")]
[InlineData(@"2\sin x", @"2\times \sin \left( x\right) ", @"2\times \sin \left( x\right) ")]
[InlineData(@"\sin 2x", @"\sin \left( 2\times x\right) ", @"\sin \left( 2\times x\right) ")]
[InlineData(@"\sin xy", @"\sin \left( x\times y\right) ", @"\sin \left( x\times y\right) ")]
[InlineData(@"\sin \frac\pi2", @"\sin \left( \frac{\pi }{2}\right) ", @"1")]
[InlineData(@"\sin \frac\pi2+1", @"\sin \left( \frac{\pi }{2}\right) +1", @"2")]
[InlineData(@"\cos +x", @"\cos \left( x\right) ", @"\cos \left( x\right) ")]
[InlineData(@"\cos -x", @"\cos \left( -x\right) ", @"\cos \left( -x\right) ")]
[InlineData(@"\tan x\%", @"\tan \left( \frac{x}{100}\right) ", @"\tan \left( \frac{1}{100}\times x\right) ")]
[InlineData(@"\tan x\%^2", @"\tan \left( \left( \frac{x}{100}\right) ^2\right) ", @"\tan \left( \left( \frac{1}{100}\times x\right) ^2\right) ")]
[InlineData(@"\cot x*y", @"\cot \left( x\right) \times y", @"\cot \left( x\right) \times y")]
[InlineData(@"\cot x/y", @"\frac{\cot \left( x\right) }{y}", @"\frac{\cot \left( x\right) }{y}")]
[InlineData(@"\cos \arccos x", @"\cos \left( \arccos \left( x\right) \right) ", @"x")]
[InlineData(@"\sin^2 x", @"\sin \left( x\right) ^2", @"\sin \left( x\right) ^2")]
[InlineData(@"\sin^2 xy+\cos^2 yx", @"\sin \left( x\times y\right) ^2+\cos \left( y\times x\right) ^2", @"1")]
[InlineData(@"\log^2 x", @"\log \left( x\right) ^2", @"\log \left( x\right) ^2")]
[InlineData(@"\ln^2 x", @"\ln \left( x\right) ^2", @"\ln \left( x\right) ^2")]
[InlineData(@"\log_{10}^2 x", @"\log \left( x\right) ^2", @"\log \left( x\right) ^2")]
[InlineData(@"\log_3^2 x", @"\log _3\left( x\right) ^2", @"\log _3\left( x\right) ^2")]
public void Functions(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData(@"\sin^{-1} x", @"\arcsin \left( x\right) ", @"\arcsin \left( x\right) ")]
[InlineData(@"\cos^{-1} x", @"\arccos \left( x\right) ", @"\arccos \left( x\right) ")]
[InlineData(@"\tan^{-1} x", @"\arctan \left( x\right) ", @"\arctan \left( x\right) ")]
[InlineData(@"\cot^{-1} x", @"\arccot \left( x\right) ", @"\arccot \left( x\right) ")]
[InlineData(@"\sec^{-1} x", @"\arccos \left( \frac{1}{x}\right) ", @"\arccos \left( \frac{1}{x}\right) ")]
[InlineData(@"\csc^{-1} x", @"\arcsin \left( \frac{1}{x}\right) ", @"\arcsin \left( \frac{1}{x}\right) ")]
[InlineData(@"\arcsin^{-1} x", @"\sin \left( x\right) ", @"\sin \left( x\right) ")]
[InlineData(@"\arccos^{-1} x", @"\cos \left( x\right) ", @"\cos \left( x\right) ")]
[InlineData(@"\arctan^{-1} x", @"\tan \left( x\right) ", @"\tan \left( x\right) ")]
[InlineData(@"\arccot^{-1} x", @"\cot \left( x\right) ", @"\cot \left( x\right) ")]
[InlineData(@"\arcsec^{-1} x", @"\frac{1}{\cos \left( x\right) }", @"\frac{1}{\cos \left( x\right) }")]
[InlineData(@"\arccsc^{-1} x", @"\frac{1}{\sin \left( x\right) }", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\ln^{-1} x", @"e^x", @"e^x")]
[InlineData(@"\log^{-1} x", @"10^x", @"10^x")]
[InlineData(@"\log_3^{-1} x", @"3^x", @"3^x")]
[InlineData(@"\log^{-1}_{10} x", @"10^x", @"10^x")]
[InlineData(@"\log_e^{-1} x", @"e^x", @"e^x")]
[InlineData(@"\ln^{-1} x^2", @"e^{x^2}", @"e^{x^2}")]
[InlineData(@"\log^{-1} x^2", @"10^{x^2}", @"10^{x^2}")]
[InlineData(@"\log_{10}^{-1} x^2", @"10^{x^2}", @"10^{x^2}")]
[InlineData(@"\log_3^{-1} x^2", @"3^{x^2}", @"3^{x^2}")]
[InlineData(@"\log_e^{-1} x^2", @"e^{x^2}", @"e^{x^2}")]
[InlineData(@"\ln^{-1} x^{-1}", @"e^{x^{-1}}", @"e^{\frac{1}{x}}")]
[InlineData(@"\log^{-1} x^{-1}", @"10^{x^{-1}}", @"10^{\frac{1}{x}}")]
[InlineData(@"\log_{10}^{-1} x^{-1}", @"10^{x^{-1}}", @"10^{\frac{1}{x}}")]
[InlineData(@"\log_3^{-1} x^{-1}", @"3^{x^{-1}}", @"3^{\frac{1}{x}}")]
[InlineData(@"\log_e^{-1} x^{-1}", @"e^{x^{-1}}", @"e^{\frac{1}{x}}")]
[InlineData(@"2\sin^{-1} x", @"2\times \arcsin \left( x\right) ", @"2\times \arcsin \left( x\right) ")]
[InlineData(@"\sin^{-1} 2x", @"\arcsin \left( 2\times x\right) ", @"\arcsin \left( 2\times x\right) ")]
[InlineData(@"\sin^{-1} xy", @"\arcsin \left( x\times y\right) ", @"\arcsin \left( x\times y\right) ")]
[InlineData(@"\cos^{-1} +x", @"\arccos \left( x\right) ", @"\arccos \left( x\right) ")]
[InlineData(@"\cos^{-1} -x", @"\arccos \left( -x\right) ", @"\arccos \left( -x\right) ")]
[InlineData(@"\tan^{-1} x\%", @"\arctan \left( \frac{x}{100}\right) ", @"\arctan \left( \frac{1}{100}\times x\right) ")]
[InlineData(@"\tan^{-1} x\%^2", @"\arctan \left( \left( \frac{x}{100}\right) ^2\right) ", @"\arctan \left( \left( \frac{1}{100}\times x\right) ^2\right) ")]
[InlineData(@"\cot^{-1} x*y", @"\arccot \left( x\right) \times y", @"\arccot \left( x\right) \times y")]
[InlineData(@"\cot^{-1} x/y", @"\frac{\arccot \left( x\right) }{y}", @"\frac{\arccot \left( x\right) }{y}")]
[InlineData(@"\cos^{-1} \arccos^{-1} x", @"\arccos \left( \cos \left( x\right) \right) ", @"x")]
[InlineData(@"\sin^1 x", @"\sin \left( x\right) ^1", @"\sin \left( x\right) ")]
[InlineData(@"\sin^{+1} x", @"\sin \left( x\right) ^1", @"\sin \left( x\right) ")]
[InlineData(@"\sin^{+-1} x", @"\sin \left( x\right) ^{-1}", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\sin^{-+1} x", @"\sin \left( x\right) ^{-1}", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\sin^{--1} x", @"\sin \left( x\right) ^{--1}", @"\sin \left( x\right) ")]
[InlineData(@"\sin^{-1^2} x", @"\sin \left( x\right) ^{-1^2}", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\sin^{-1+3} xy+\cos^{-1+3} yx", @"\sin \left( x\times y\right) ^{-1+3}+\cos \left( y\times x\right) ^{-1+3}", @"1")]
[InlineData(@"\log^{-a_2} x", @"\log \left( x\right) ^{-a_2}", @"\log \left( x\right) ^{-a_2}")]
[InlineData(@"\ln^{3-1} x", @"\ln \left( x\right) ^{3-1}", @"\ln \left( x\right) ^2")]
public void FunctionInverses(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData(@"1+(2+3)", @"1+2+3", @"6")]
[InlineData(@"1+((2+3))", @"1+2+3", @"6")]
[InlineData(@"2*(3+4)", @"2\times \left( 3+4\right) ", @"14")]
[InlineData(@"(3+4)*2", @"\left( 3+4\right) \times 2", @"14")]
[InlineData(@"(5+6)^2", @"\left( 5+6\right) ^2", @"121")]
[InlineData(@"(5+6)", @"5+6", @"11")]
[InlineData(@"((5+6))", @"5+6", @"11")]
[InlineData(@"(5+6)2", @"\left( 5+6\right) \times 2", @"22")]
[InlineData(@"2(5+6)", @"2\times \left( 5+6\right) ", @"22")]
[InlineData(@"2(5+6)2", @"2\times \left( 5+6\right) \times 2", @"44")]
[InlineData(@"(5+6)x", @"\left( 5+6\right) \times x", @"11\times x")]
[InlineData(@"x(5+6)", @"x\times \left( 5+6\right) ", @"11\times x")]
[InlineData(@"x(5+6)x", @"x\times \left( 5+6\right) \times x", @"11\times x^2")]
[InlineData(@"(5+6).2", @"\left( 5+6\right) \times \frac{1}{5}", @"\frac{11}{5}")]
[InlineData(@".2(5+6)", @"\frac{1}{5}\times \left( 5+6\right) ", @"\frac{11}{5}")]
[InlineData(@".2(5+6).2", @"\frac{1}{5}\times \left( 5+6\right) \times \frac{1}{5}", @"\frac{11}{25}")]
[InlineData(@"(5+6)2.", @"\left( 5+6\right) \times 2", @"22")]
[InlineData(@"2.(5+6)", @"2\times \left( 5+6\right) ", @"22")]
[InlineData(@"2.(5+6)2.", @"2\times \left( 5+6\right) \times 2", @"44")]
[InlineData(@"(5+6)(2)", @"\left( 5+6\right) \times 2", @"22")]
[InlineData(@"(5+6)(1+1)", @"\left( 5+6\right) \times \left( 1+1\right) ", @"22")]
[InlineData(@"(5+6)(-(-2))", @"\left( 5+6\right) \times --2", @"22")]
[InlineData(@"(5+6)(--2)", @"\left( 5+6\right) \times --2", @"22")]
[InlineData(@"+(1)", @"1", @"1")]
[InlineData(@"+(1)\%", @"\frac{1}{100}", @"\frac{1}{100}")]
[InlineData(@"+(-1)", @"-1", @"-1")]
[InlineData(@"-(+1)", @"-1", @"-1")]
[InlineData(@"-(-1)", @"--1", @"1")]
[InlineData(@"--(--1)", @"----1", @"1")]
[InlineData(@"(2+3)^{(4+5)}", @"\left( 2+3\right) ^{4+5}", @"1953125")]
[InlineData(@"(2+3)^{((4)+5)}", @"\left( 2+3\right) ^{4+5}", @"1953125")]
[InlineData(@"(1+i)\infty", @"\left( 1+i\right) \times \infty ", @"\infty +\infty i")]
[InlineData(@"2\sin(x)", @"2\times \sin \left( x\right) ", @"2\times \sin \left( x\right) ")]
[InlineData(@"(2)\sin(x)", @"2\times \sin \left( x\right) ", @"2\times \sin \left( x\right) ")]
[InlineData(@"\sin(x+1)", @"\sin \left( x+1\right) ", @"\sin \left( 1+x\right) ")]
[InlineData(@"\sin((x+1))", @"\sin \left( x+1\right) ", @"\sin \left( 1+x\right) ")]
[InlineData(@"\sin(2(x+1))", @"\sin \left( 2\times \left( x+1\right) \right) ", @"\sin \left( 2\times \left( 1+x\right) \right) ")]
[InlineData(@"\sin((x+1)+2)", @"\sin \left( x+1+2\right) ", @"\sin \left( 3+x\right) ")]
[InlineData(@"\sin(x)2", @"\sin \left( x\right) \times 2", @"2\times \sin \left( x\right) ")]
[InlineData(@"\sin(x)(x+1)", @"\sin \left( x\right) \times \left( x+1\right) ", @"\sin \left( x\right) \times \left( 1+x\right) ")]
[InlineData(@"\sin(x)(x+1)(x)", @"\sin \left( x\right) \times \left( x+1\right) \times x", @"\sin \left( x\right) \times \left( 1+x\right) \times x")]
[InlineData(@"\sin(x^2)", @"\sin \left( x^2\right) ", @"\sin \left( x^2\right) ")]
[InlineData(@"\sin\ (x^2)", @"\sin \left( x^2\right) ", @"\sin \left( x^2\right) ")]
[InlineData(@"\sin\; (x^2)", @"\sin \left( x^2\right) ", @"\sin \left( x^2\right) ")]
[InlineData(@"\sin\ \; (x^2)", @"\sin \left( x^2\right) ", @"\sin \left( x^2\right) ")]
[InlineData(@"\sin^3(x)", @"\sin \left( x\right) ^3", @"\sin \left( x\right) ^3")]
[InlineData(@"\sin^3\ (x)", @"\sin \left( x\right) ^3", @"\sin \left( x\right) ^3")]
[InlineData(@"\sin^3\; (x)", @"\sin \left( x\right) ^3", @"\sin \left( x\right) ^3")]
[InlineData(@"\sin^3\ \; (x)", @"\sin \left( x\right) ^3", @"\sin \left( x\right) ^3")]
[InlineData(@"\sin^{-1}(x)", @"\arcsin \left( x\right) ", @"\arcsin \left( x\right) ")]
[InlineData(@"\sin^{-1}\ (x)", @"\arcsin \left( x\right) ", @"\arcsin \left( x\right) ")]
[InlineData(@"\sin^{-1}\; (x)", @"\arcsin \left( x\right) ", @"\arcsin \left( x\right) ")]
[InlineData(@"\sin^{-1}\ \; (x)", @"\arcsin \left( x\right) ", @"\arcsin \left( x\right) ")]
[InlineData(@"\sin(x)^2", @"\sin \left( x\right) ^2", @"\sin \left( x\right) ^2")]
[InlineData(@"\sin\ (x)^2", @"\sin \left( x\right) ^2", @"\sin \left( x\right) ^2")]
[InlineData(@"\sin\; (x)^2", @"\sin \left( x\right) ^2", @"\sin \left( x\right) ^2")]
[InlineData(@"\sin\ \; (x)^2", @"\sin \left( x\right) ^2", @"\sin \left( x\right) ^2")]
[InlineData(@"\sin(x)^{-1}", @"\sin \left( x\right) ^{-1}", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\sin\ (x)^{-1}", @"\sin \left( x\right) ^{-1}", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\sin\; (x)^{-1}", @"\sin \left( x\right) ^{-1}", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\sin\ \; (x)^{-1}", @"\sin \left( x\right) ^{-1}", @"\frac{1}{\sin \left( x\right) }")]
[InlineData(@"\sin^3(x)^{-1}", @"\sin \left( x\right) ^{3\times -1}", @"\sin \left( x\right) ^{-3}")]
[InlineData(@"\sin^3\ (x)^{-1}", @"\sin \left( x\right) ^{3\times -1}", @"\sin \left( x\right) ^{-3}")]
[InlineData(@"\sin^3\; (x)^{-1}", @"\sin \left( x\right) ^{3\times -1}", @"\sin \left( x\right) ^{-3}")]
[InlineData(@"\sin^3\ \; (x)^{-1}", @"\sin \left( x\right) ^{3\times -1}", @"\sin \left( x\right) ^{-3}")]
[InlineData(@"\sin^{-1}(x)^{-1}", @"\arcsin \left( x\right) ^{-1}", @"\frac{1}{\arcsin \left( x\right) }")]
[InlineData(@"\sin^{-1}\ (x)^{-1}", @"\arcsin \left( x\right) ^{-1}", @"\frac{1}{\arcsin \left( x\right) }")]
[InlineData(@"\sin^{-1}\; (x)^{-1}", @"\arcsin \left( x\right) ^{-1}", @"\frac{1}{\arcsin \left( x\right) }")]
[InlineData(@"\sin^{-1}\ \; (x)^{-1}", @"\arcsin \left( x\right) ^{-1}", @"\frac{1}{\arcsin \left( x\right) }")]
[InlineData(@"\sin^a(x)", @"\sin \left( x\right) ^a", @"\sin \left( x\right) ^a")]
[InlineData(@"\sin^a(x)^2", @"\sin \left( x\right) ^{a\times 2}", @"\sin \left( x\right) ^{2\times a}")]
[InlineData(@"\sin^a\ (x)^2", @"\sin \left( x\right) ^{a\times 2}", @"\sin \left( x\right) ^{2\times a}")]
[InlineData(@"\sin^a\; (x)^2", @"\sin \left( x\right) ^{a\times 2}", @"\sin \left( x\right) ^{2\times a}")]
[InlineData(@"\sin^a\ \; (x)^2", @"\sin \left( x\right) ^{a\times 2}", @"\sin \left( x\right) ^{2\times a}")]
[InlineData(@"\sin(x)^2(x)", @"\sin \left( x\right) ^2\times x", @"\sin \left( x\right) ^2\times x")]
[InlineData(@"\sin\ (x)^2(x)", @"\sin \left( x\right) ^2\times x", @"\sin \left( x\right) ^2\times x")]
[InlineData(@"\sin\; (x)^2(x)", @"\sin \left( x\right) ^2\times x", @"\sin \left( x\right) ^2\times x")]
[InlineData(@"\sin\ \; (x)^2(x)", @"\sin \left( x\right) ^2\times x", @"\sin \left( x\right) ^2\times x")]
[InlineData(@"\sin^a(x)^2(x)", @"\sin \left( x\right) ^{a\times 2}\times x", @"\sin \left( x\right) ^{2\times a}\times x")]
[InlineData(@"\sin^a\ (x)^2(x)", @"\sin \left( x\right) ^{a\times 2}\times x", @"\sin \left( x\right) ^{2\times a}\times x")]
[InlineData(@"\sin^a\; (x)^2(x)", @"\sin \left( x\right) ^{a\times 2}\times x", @"\sin \left( x\right) ^{2\times a}\times x")]
[InlineData(@"\sin^a\ \; (x)^2(x)", @"\sin \left( x\right) ^{a\times 2}\times x", @"\sin \left( x\right) ^{2\times a}\times x")]
[InlineData(@"\sin (\frac\pi2)", @"\sin \left( \frac{\pi }{2}\right) ", @"1")]
[InlineData(@"\sin (\frac\pi2)+1", @"\sin \left( \frac{\pi }{2}\right) +1", @"2")]
public void Parentheses(string latex, string converted, string result) {
Test(latex, converted, result);
Test(latex.Replace('(', '[').Replace(')', ']'), converted, result);
}
[Theory]
[InlineData(@"\begin{matrix}1\end{matrix}", @"\left( \begin{matrix}1\end{matrix}\right) ", @"\left( \begin{matrix}1\end{matrix}\right) ")]
[InlineData(@"\begin{pmatrix}1\end{pmatrix}", @"\left( \begin{matrix}1\end{matrix}\right) ", @"\left( \begin{matrix}1\end{matrix}\right) ")]
[InlineData(@"\begin{bmatrix}1\end{bmatrix}", @"\left( \begin{matrix}1\end{matrix}\right) ", @"\left( \begin{matrix}1\end{matrix}\right) ")]
[InlineData(@"\begin{pmatrix}1\end{pmatrix}^2", @"\left( \begin{matrix}1\end{matrix}\right) ^2", @"\left( \begin{matrix}1\end{matrix}\right) ^2")]
[InlineData(@"\begin{bmatrix}1\end{bmatrix}^2", @"\left( \begin{matrix}1\end{matrix}\right) ^2", @"\left( \begin{matrix}1\end{matrix}\right) ^2")]
public void Vectors(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData(@"\begin{matrix}1&2\\3&4\end{matrix}", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ")]
[InlineData(@"\begin{pmatrix}1&2\\3&4\end{pmatrix}", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ")]
[InlineData(@"\begin{bmatrix}1&2\\3&4\end{bmatrix}", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ")]
[InlineData(@"\begin{pmatrix}1&2\\3&4\end{pmatrix}^2", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ^2", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ^2")]
[InlineData(@"\begin{bmatrix}1&2\\3&4\end{bmatrix}^2", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ^2", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) ^2")]
[InlineData(@"\begin{matrix}1&2\\3&4\end{matrix}+\begin{bmatrix}1&2\\3&5\end{bmatrix}", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) +\left( \begin{matrix}1&2\\ 3&5\end{matrix}\right) ", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) +\left( \begin{matrix}1&2\\ 3&5\end{matrix}\right) ")]
[InlineData(@"\begin{pmatrix}1&2\\3&4\end{pmatrix}+\begin{matrix}1&2\\3&5\end{matrix}", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) +\left( \begin{matrix}1&2\\ 3&5\end{matrix}\right) ", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) +\left( \begin{matrix}1&2\\ 3&5\end{matrix}\right) ")]
[InlineData(@"\begin{bmatrix}1&2\\3&4\end{bmatrix}+\begin{pmatrix}1&2\\3&5\end{pmatrix}", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) +\left( \begin{matrix}1&2\\ 3&5\end{matrix}\right) ", @"\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) +\left( \begin{matrix}1&2\\ 3&5\end{matrix}\right) ")]
public void Matrices(string latex, string converted, string result) => Test(latex, converted, result);
[Theory]
[InlineData(@"1,2", @"1,2")]
[InlineData(@"1,2,3", @"1,2,3")]
[InlineData(@"a,b,c,d", @"a,b,c,d")]
[InlineData(@"\sqrt2,\sqrt[3]2,\frac34", @"\sqrt{2},2^{\frac{1}{3}},\frac{3}{4}")]
[InlineData(@"\sin a,\cos b^2,\tan c_3,\cot de,\sec 12f,\csc g+h",
@"\sin \left( a\right) ,\cos \left( b^2\right) ,\tan \left( c_3\right) ,\cot \left( d\times e\right) ,\frac{1}{\cos \left( 12\times f\right) },\frac{1}{\sin \left( g\right) }+h")]
public void Comma(string latex, string converted) => Test(latex, converted, null);
[Theory]
[InlineData(@"\emptyset", @"\emptyset ")]
[InlineData(@"\mathbb R", @"\left\{ \left( -\infty ,\infty \right) \right\} ")]
[InlineData(@"\mathbb C", @"\left\{ \left\{ z\in \mathbb{C}:\Re \left( z\right) \in \left( -\infty ,\infty \right) \wedge \Im \left( z\right) \in \left( -\infty ,\infty \right) \right\} \right\} ")]
[InlineData(@"\{\}", @"\emptyset ")]
[InlineData(@"\{1\}", @"\left\{ 1\right\} ")]
[InlineData(@"\{1,2\}", @"\left\{ 1,2\right\} ")]
[InlineData(@"\{x,y\}", @"\left\{ x,y\right\} ")]
[InlineData(@"\{\sqrt[3]2,\frac34,\sin^2x\}", @"\left\{ 2^{\frac{1}{3}},\frac{3}{4},\sin \left( x\right) ^2\right\} ")]
public void Sets(string latex, string converted) => Test(latex, converted, null);
[Theory]
[InlineData(@"\emptyset\cup\{2\}", @"\left\{ 2\right\} ")]
[InlineData(@"\{1\}\cup\{2\}", @"\left\{ 1,2\right\} ")]
[InlineData(@"\{3,4\}\cap\emptyset", @"\left( \left\{ 3,4\right\} \cap \right) \left( \emptyset \right) ")]
[InlineData(@"\{3,4\}\cap\{4,5\}", @"\left\{ 4\right\} ")]
[InlineData(@"\{2,3,4\}\setminus\{4\}", @"\left\{ 2,3\right\} ")]
[InlineData(@"\{3\}^\complement", @"\left\{ \left\{ z\in \mathbb{C}:\Re \left( z\right) \in \left( -\infty ,3\right] \wedge \Im \left( z\right) \in \left( -\infty ,0\right) \right\} ,\left\{ z\in \mathbb{C}:\Re \left( z\right) \in \left( -\infty ,3\right) \wedge \Im \left( z\right) \in \left[ 0,\infty \right) \right\} ,\left\{ z\in \mathbb{C}:\Re \left( z\right) \in \left[ 3,\infty \right) \wedge \Im \left( z\right) \in \left( 0,\infty \right) \right\} ,\left\{ z\in \mathbb{C}:\Re \left( z\right) \in \left( 3,\infty \right) \wedge \Im \left( z\right) \in \left( -\infty ,0\right] \right\} \right\} ")]
public void SetOperations(string latex, string converted) => Test(latex, converted, null);
[Theory]
[InlineData(@"(1,2)", @"\left\{ \left( 1,2\right) \right\} ")]
[InlineData(@"[1,2)", @"\left\{ \left[ 1,2\right) \right\} ")]
[InlineData(@"(1,2]", @"\left\{ \left( 1,2\right] \right\} ")]
[InlineData(@"[1,2]", @"\left\{ \left[ 1,2\right] \right\} ")]
[InlineData(@"(2,1)", @"\left\{ \left( 2,1\right) \right\} ")]
[InlineData(@"[2,1)", @"\left\{ \left[ 2,1\right) \right\} ")]
[InlineData(@"(2,1]", @"\left\{ \left( 2,1\right] \right\} ")]
[InlineData(@"[2,1]", @"\left\{ \left[ 2,1\right] \right\} ")]
[InlineData(@"[1,2]\setminus\{1\}", @"\left\{ \left( 1,2\right] \right\} ")]
[InlineData(@"[1,2]\setminus\{2\}", @"\left\{ \left[ 1,2\right) \right\} ")]
[InlineData(@"[1,2]\cup(2,3)", @"\left\{ \left[ 1,2\right] ,\left( 2,3\right) \right\} ")]
[InlineData(@"[1,2]\cap[1.5,1.6]", @"\left\{ \left[ \frac{3}{2},\frac{8}{5}\right] \right\} ")]
[InlineData(@"[1.5,1.5]", @"\left\{ \frac{3}{2}\right\} ")]
[InlineData(@"(1.5,1.5]", @"\emptyset ")]
[InlineData(@"[1.5,1.5)", @"\emptyset ")]
[InlineData(@"(1.5,1.5)", @"\emptyset ")]
[InlineData(@"[xy,xy]", @"\left\{ x\times y\right\} ")]
[InlineData(@"(xy,xy]", @"\emptyset ")]
[InlineData(@"[xy,xy)", @"\emptyset ")]
[InlineData(@"(xy,xy)", @"\emptyset ")]
public void Intervals(string latex, string converted) => Test(latex, converted, null);
[Theory]
[InlineData(@"\>\:\pi", @"\pi ", @"\pi ")]
[InlineData(@"3\quad 2", @"3\times 2", "6")]
[InlineData(@"a\textstyle b\displaystyle", @"a\times b", @"a\times b")]
[InlineData(@"a^6+2a^6 % should be 3a^6", @"a^6+2\times a^6", @"3\times a^6")]
[InlineData(@"4+\ \mkern1.5mu3", @"4+3", "7")]
public void SkipInvisible(string latex, string converted, string output) => Test(latex, converted, output);
[Theory]
[InlineData(@"", "There is nothing to evaluate")]
[InlineData(@"\ ", "There is nothing to evaluate")]
[InlineData(@"\;", "There is nothing to evaluate")]
[InlineData(@"\quad", "There is nothing to evaluate")]
[InlineData(@"+", "Missing right operand for +")]
[InlineData(@"-", "Missing right operand for \u2212")]
[InlineData(@"\times", "Unsupported Unary Operator ×")]
[InlineData(@"\div", "Unsupported Unary Operator ÷")]
[InlineData(@"\%", "Missing left operand for %")]
[InlineData(@"\degree", "Missing left operand for °")]
[InlineData(@"\dagger", "Unsupported Unary Operator †")]
[InlineData(@"\times x", "Unsupported Unary Operator ×")]
[InlineData(@"\div x", "Unsupported Unary Operator ÷")]
[InlineData(@"\% x", "Missing left operand for %")]
[InlineData(@"\degree x", "Missing left operand for °")]
[InlineData(@"x+", "Missing right operand for +")]
[InlineData(@"x-", "Missing right operand for \u2212")]
[InlineData(@"x\times", "Missing right operand for ×")]
[InlineData(@"x\div", "Missing right operand for ÷")]
[InlineData(@"x\dagger", "Unsupported Binary Operator †")]
[InlineData(@"1+_21", "Subscripts are unsupported for Binary Operator +")]
[InlineData(@"-_31", "Subscripts are unsupported for Unary Operator −")]
[InlineData(@"1\times_41", "Subscripts are unsupported for Binary Operator ×")]
[InlineData(@"\div_51", "Unsupported Unary Operator ÷")]
[InlineData(@"1\%_6", "Subscripts are unsupported for Ordinary %")]
[InlineData(@"1\degree_7", "Subscripts are unsupported for Ordinary °")]
[InlineData(@"\dagger_8", "Unsupported Unary Operator †")]
[InlineData(@".", "Invalid number: .")]
[InlineData(@"1._2", "Subscripts are unsupported for Number 1.")]
[InlineData(@"..", "Invalid number: ..")]
[InlineData(@"1..", "Invalid number: 1..")]
[InlineData(@"..1", "Invalid number: ..1")]
[InlineData(@"a_+", "Unsupported Unary Operator + in subscript")]
[InlineData(@"a_|", "Unsupported Ordinary | in subscript")]
[InlineData(@"a_{1+1}", "Unsupported Binary Operator + in subscript")]
[InlineData(@"a_{2^3}", "Unsupported exponentiation in subscript")]
[InlineData(@"a_{a2^3}", "Unsupported exponentiation in subscript")]
[InlineData(@"a_{a^32}", "Unsupported exponentiation in subscript")]
[InlineData(@"a_{2_3}", "Unsupported subscript in subscript")]
[InlineData(@"a_{a2_3}", "Unsupported subscript in subscript")]
[InlineData(@"a_{a_32}", "Unsupported subscript in subscript")]
[InlineData(@"\square", "Placeholders should be filled")]
[InlineData(@"x^\square", "Placeholders should be filled")]
[InlineData(@"\square^x", "Placeholders should be filled")]
[InlineData(@"a_\square", "Placeholders should be filled")]
[InlineData(@"\square_a", "Placeholders should be filled")]
[InlineData(@"(", "Missing )")]
[InlineData(@"(_21)", "Subscripts are unsupported for Open (")]
[InlineData(@"(x", "Missing )")]
[InlineData(@"((x)", "Missing )")]
[InlineData(@"(+", "Missing right operand for +")]
[InlineData(@")", "Missing (")]
[InlineData(@"(1)_2", "Subscripts are unsupported for Close )")]
[InlineData(@"x)", "Missing (")]
[InlineData(@"(x))", "Missing (")]
[InlineData(@"+)", "Missing right operand for +")]
[InlineData(@"\left(\right)", "Missing math inside ( )")]
[InlineData(@"\left(1+\right)", "Missing right operand for +")]
[InlineData(@"\left(2,3\right)^\square", "Placeholders should be filled")]
[InlineData(@"(2,3)^\square", "Placeholders should be filled")]
[InlineData(@"[", "Missing ]")]
[InlineData(@"[_21)", "Unrecognized bracket pair [ )")]
[InlineData(@"[x", "Missing ]")]
[InlineData(@"[x)", "Unrecognized bracket pair [ )")]
[InlineData(@"[[x)", "Unrecognized bracket pair [ )")]
[InlineData(@"[+", "Missing right operand for +")]
[InlineData(@"[x))", "Unrecognized bracket pair [ )")]
[InlineData(@"\left[\right)", "Unrecognized bracket pair [ )")]
[InlineData(@"\left[1+\right)", "Missing right operand for +")]
[InlineData(@"\left[2,3\right)^\square", "Placeholders should be filled")]
[InlineData(@"[2,3)^\square", "Placeholders should be filled")]
[InlineData(@"((x]", "Unrecognized bracket pair ( ]")]
[InlineData(@"(x]", "Unrecognized bracket pair ( ]")]
[InlineData(@"]", "Missing [")]
[InlineData(@"]_2", "Subscripts are unsupported for Close ]")]
[InlineData(@"x]", "Missing [")]
[InlineData(@"(x]]", "Unrecognized bracket pair ( ]")]
[InlineData(@"+]", "Missing right operand for +")]
[InlineData(@"\left(\right]", "Unrecognized bracket pair ( ]")]
[InlineData(@"\left(1+\right]", "Missing right operand for +")]
[InlineData(@"\left(2,3\right]^\square", "Placeholders should be filled")]
[InlineData(@"(2,3]^\square", "Placeholders should be filled")]
[InlineData(@"[]", "Missing math inside [ ]")]
[InlineData(@"[[x]", "Missing ]")]
[InlineData(@"[x]]", "Missing [")]
[InlineData(@"[_\square x]", "Subscripts are unsupported for Open [")]
[InlineData(@"[x]_\square", "Subscripts are unsupported for Close ]")]
[InlineData(@"\left[\right]", "Missing math inside [ ]")]
[InlineData(@"\left[1+\right]", "Missing right operand for +")]
[InlineData(@"\left[2,3\right]^\square", "Placeholders should be filled")]
[InlineData(@"[2,3]^\square", "Placeholders should be filled")]
[InlineData(@"\{", "Missing }")]
[InlineData(@"\{_2\}", "Subscripts are unsupported for Open {")]
[InlineData(@"\{x", "Missing }")]
[InlineData(@"\{\{x\}", "Missing }")]
[InlineData(@"\{+", "Missing right operand for +")]
[InlineData(@"\}", "Missing {")]
[InlineData(@"\}_2", "Subscripts are unsupported for Close }")]
[InlineData(@"x\}", "Missing {")]
[InlineData(@"\{x\}\}", "Missing {")]
[InlineData(@"+\}", "Missing right operand for +")]
[InlineData(@"\left\{1+\right\}", "Missing right operand for +")]
[InlineData(@"\{2,3\}^\square", "Placeholders should be filled")]
[InlineData(@"\left\{2,3\right\}^\square", "Placeholders should be filled")]
[InlineData(@"\frac{}{x}", "Missing numerator")]
[InlineData(@"\frac{x}{}", "Missing denominator")]
[InlineData(@"\sqrt{}", "Missing radicand")]
[InlineData(@"\sin", "Missing argument for sin")]
[InlineData(@"\cos-", "Missing right operand for \u2212")]
[InlineData(@"\tan\times", "Unsupported Unary Operator ×")]
[InlineData(@"\cot^(-1)", "Missing )")]
[InlineData(@"\sec\csc", "Missing argument for csc")]
[InlineData(@"\arcsin_2x", "Subscripts are unsupported for Large Operator arcsin")]
[InlineData(@"\operatorname{dab}", "Unsupported Large Operator dab")]
[InlineData(@"\begin{matrix}\end{matrix}", "Missing matrix element")]
[InlineData(@"\begin{matrix}2&3\end{matrix}_2", "Subscripts are unsupported for Ordinary")]
[InlineData(@"\begin{matrix}2&3\end{matrix}^2", "Exponentiation is unsupported for Ordinary")]
[InlineData(@"\begin{pmatrix}2&+\end{pmatrix}", "Missing right operand for +")]
[InlineData(@"\begin{pmatrix}2&3\end{pmatrix}_2", "Subscripts are unsupported for Inner ")]
[InlineData(@"\begin{Vmatrix}\end{Vmatrix}", "Missing matrix element")]
[InlineData(@"\begin{Vmatrix}2&3\end{Vmatrix}", "Unrecognized bracket pair ‖ ‖")]
[InlineData(@"\begin{eqnarray}&&\end{eqnarray}", "Unsupported table environment eqnarray")]
[InlineData(@",", "Missing left operand for comma")]
[InlineData(@"1,_22", "Subscripts are unsupported for Punctuation ,")]
[InlineData(@"1,", "Missing right operand for comma")]
[InlineData(@",1", "Missing left operand for comma")]
[InlineData(@",1,2", "Missing left operand for comma")]
[InlineData(@"1,,2", "Missing left operand for comma")]
[InlineData(@"1,2,", "Missing right operand for comma")]
[InlineData(@",,1,2", "Missing left operand for comma")]
[InlineData(@"1,,2,", "Missing left operand for comma")]
[InlineData(@"1,2,,", "Missing left operand for comma")]
[InlineData(@"\arcsin(1,2)", "Comma cannot be argument for arcsin")]
[InlineData(@"+(3,4]", "Set cannot be right operand for +")]
[InlineData(@"[5,6)\times", "Set cannot be left operand for ×")]
[InlineData(@"\frac{[7,8]}{9}", "Set cannot be numerator")]
[InlineData(@"\sqrt[{[)}]{}", "Unrecognized bracket pair [ )")]
[InlineData(@"\sqrt[{[a,b]}]{}", "Set cannot be degree")]
[InlineData(@"\{\{\}\}", "Set cannot be set element")]
[InlineData(@"\cap", "Unsupported Unary Operator ∩")]
[InlineData(@"\cap1", "Unsupported Unary Operator ∩")]
[InlineData(@"1\cap", "Entity cannot be left operand for ∩")]
[InlineData(@"\cup", "Unsupported Unary Operator ∪")]
[InlineData(@"\cup1", "Unsupported Unary Operator ∪")]
[InlineData(@"1\cup", "Entity cannot be left operand for ∪")]
[InlineData(@"\setminus", "Unsupported Unary Operator ∖")]
[InlineData(@"\setminus1", "Unsupported Unary Operator ∖")]
[InlineData(@"1\setminus", "Entity cannot be left operand for ∖")]
[InlineData(@"^\complement", "Exponentiation is unsupported for Ordinary")]
[InlineData(@"_\complement", "Subscripts are unsupported for Ordinary")]
[InlineData(@"1^\complement", "Entity cannot be target of set inversion")]
[InlineData(@"1_\complement", "Subscripts are unsupported for Number 1")]
[InlineData(@"x^\complement", "Entity cannot be target of set inversion")]
[InlineData(@"x_\complement", "Unsupported Ordinary ∁ in subscript")]
[InlineData(@"\sin^\complement x", "Entity cannot be target of set inversion")]
[InlineData(@"\sin_\complement x", "Subscripts are unsupported for Large Operator sin")]
public void Error(string badLaTeX, string error) =>
Evaluation.Evaluate(ParseLaTeX(badLaTeX))
.Match(entity => throw new Xunit.Sdk.XunitException(entity.Latexise()), e => Assert.Equal(error, e));
// https://github.com/ForNeVeR/wpf-math/issues/42
[Theory]
[InlineData("1 + 1 - 1", @"1+1-1")]
[InlineData("3 / 2", @"\frac{3}{2}")]
[InlineData("2 * 3 / 5", @"\frac{2\times 3}{5}")]
[InlineData("sin(x+pi)", @"\sin \left( x+\pi \right) ")]
[InlineData("log(3,alpha)", @"\log _3\left( \alpha \right) ")]
[InlineData("2e9", @"2000000000")]
[InlineData("-3e4^x", @"-30000^x")]
[InlineData("(-3e4)^x", @"\left( -30000\right) ^x")]
[InlineData("i+2i", @"i+2i")]
public void SimpleArithmeticSyntax(string simpleSyntax, string latex) =>
Assert.Equal(latex, LaTeXParser.MathListToLaTeX(Evaluation.Visualize((Entity)simpleSyntax)).ToString());
}
}