plurimath 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +13 -0
  3. data/.github/workflows/release.yml +22 -0
  4. data/.hound.yml +5 -0
  5. data/.rubocop.yml +8 -0
  6. data/AsciiMath-Supported-Data.adoc +1994 -274
  7. data/Gemfile +2 -0
  8. data/Latex-Supported-Data.adoc +1875 -1868
  9. data/MathML-Supported-Data.adoc +280 -263
  10. data/README.adoc +22 -20
  11. data/lib/plurimath/asciimath/constants.rb +186 -141
  12. data/lib/plurimath/asciimath/parse.rb +104 -39
  13. data/lib/plurimath/asciimath/parser.rb +3 -1
  14. data/lib/plurimath/asciimath/transform.rb +1074 -238
  15. data/lib/plurimath/html/parse.rb +1 -1
  16. data/lib/plurimath/latex/constants.rb +3228 -1432
  17. data/lib/plurimath/latex/parse.rb +106 -83
  18. data/lib/plurimath/latex/parser.rb +11 -4
  19. data/lib/plurimath/latex/transform.rb +354 -99
  20. data/lib/plurimath/math/base.rb +15 -0
  21. data/lib/plurimath/math/formula.rb +90 -13
  22. data/lib/plurimath/math/function/bar.rb +35 -1
  23. data/lib/plurimath/math/function/base.rb +25 -4
  24. data/lib/plurimath/math/function/binary_function.rb +101 -19
  25. data/lib/plurimath/math/function/cancel.rb +8 -0
  26. data/lib/plurimath/math/function/ceil.rb +3 -0
  27. data/lib/plurimath/math/function/color.rb +15 -5
  28. data/lib/plurimath/math/function/f.rb +8 -0
  29. data/lib/plurimath/math/function/fenced.rb +95 -8
  30. data/lib/plurimath/math/function/floor.rb +15 -0
  31. data/lib/plurimath/math/function/font_style/bold.rb +19 -0
  32. data/lib/plurimath/math/function/font_style/double_struck.rb +19 -0
  33. data/lib/plurimath/math/function/font_style/fraktur.rb +19 -0
  34. data/lib/plurimath/math/function/font_style/italic.rb +37 -0
  35. data/lib/plurimath/math/function/font_style/monospace.rb +19 -0
  36. data/lib/plurimath/math/function/font_style/normal.rb +37 -0
  37. data/lib/plurimath/math/function/font_style/sans-serif.rb +19 -0
  38. data/lib/plurimath/math/function/font_style/script.rb +19 -0
  39. data/lib/plurimath/math/function/font_style.rb +18 -5
  40. data/lib/plurimath/math/function/frac.rb +33 -3
  41. data/lib/plurimath/math/function/g.rb +7 -0
  42. data/lib/plurimath/math/function/hat.rb +12 -0
  43. data/lib/plurimath/math/function/inf.rb +21 -0
  44. data/lib/plurimath/math/function/int.rb +23 -2
  45. data/lib/plurimath/math/function/left.rb +25 -1
  46. data/lib/plurimath/math/function/lim.rb +40 -2
  47. data/lib/plurimath/math/function/limits.rb +9 -0
  48. data/lib/plurimath/math/function/log.rb +55 -4
  49. data/lib/plurimath/math/function/longdiv.rb +12 -0
  50. data/lib/plurimath/math/function/mbox.rb +31 -0
  51. data/lib/plurimath/math/function/menclose.rb +46 -0
  52. data/lib/plurimath/math/function/merror.rb +12 -0
  53. data/lib/plurimath/math/function/mod.rb +19 -4
  54. data/lib/plurimath/math/function/msgroup.rb +37 -0
  55. data/lib/plurimath/math/function/msline.rb +12 -0
  56. data/lib/plurimath/math/function/multiscript.rb +19 -0
  57. data/lib/plurimath/math/function/norm.rb +17 -1
  58. data/lib/plurimath/math/function/obrace.rb +17 -0
  59. data/lib/plurimath/math/function/oint.rb +2 -2
  60. data/lib/plurimath/math/function/over.rb +12 -5
  61. data/lib/plurimath/math/function/overset.rb +34 -5
  62. data/lib/plurimath/math/function/phantom.rb +28 -0
  63. data/lib/plurimath/math/function/power.rb +27 -9
  64. data/lib/plurimath/math/function/power_base.rb +109 -11
  65. data/lib/plurimath/math/function/prod.rb +25 -4
  66. data/lib/plurimath/math/function/right.rb +22 -2
  67. data/lib/plurimath/math/function/root.rb +23 -1
  68. data/lib/plurimath/math/function/rule.rb +33 -0
  69. data/lib/plurimath/math/function/scarries.rb +12 -0
  70. data/lib/plurimath/math/function/scarry.rb +12 -0
  71. data/lib/plurimath/math/function/sqrt.rb +23 -1
  72. data/lib/plurimath/math/function/stackrel.rb +27 -0
  73. data/lib/plurimath/math/function/substack.rb +7 -0
  74. data/lib/plurimath/math/function/sum.rb +50 -2
  75. data/lib/plurimath/math/function/sup.rb +3 -0
  76. data/lib/plurimath/math/function/table/align.rb +5 -5
  77. data/lib/plurimath/math/function/table/array.rb +25 -6
  78. data/lib/plurimath/math/function/table/bmatrix.rb +18 -7
  79. data/lib/plurimath/math/function/table/matrix.rb +13 -5
  80. data/lib/plurimath/math/function/table/multline.rb +5 -5
  81. data/lib/plurimath/math/function/table/pmatrix.rb +5 -5
  82. data/lib/plurimath/math/function/table/split.rb +5 -5
  83. data/lib/plurimath/math/function/table/vmatrix.rb +5 -6
  84. data/lib/plurimath/math/function/table.rb +185 -27
  85. data/lib/plurimath/math/function/td.rb +22 -9
  86. data/lib/plurimath/math/function/ternary_function.rb +74 -9
  87. data/lib/plurimath/math/function/text.rb +36 -11
  88. data/lib/plurimath/math/function/tr.rb +23 -4
  89. data/lib/plurimath/math/function/ubrace.rb +17 -0
  90. data/lib/plurimath/math/function/ul.rb +29 -0
  91. data/lib/plurimath/math/function/unary_function.rb +81 -8
  92. data/lib/plurimath/math/function/underline.rb +12 -0
  93. data/lib/plurimath/math/function/underover.rb +107 -0
  94. data/lib/plurimath/math/function/underset.rb +39 -0
  95. data/lib/plurimath/math/function/vec.rb +7 -1
  96. data/lib/plurimath/math/number.rb +5 -5
  97. data/lib/plurimath/math/symbol.rb +51 -12
  98. data/lib/plurimath/math/unicode.rb +11 -0
  99. data/lib/plurimath/math.rb +7 -3
  100. data/lib/plurimath/mathml/constants.rb +224 -147
  101. data/lib/plurimath/mathml/parser.rb +24 -8
  102. data/lib/plurimath/mathml/transform.rb +249 -153
  103. data/lib/plurimath/omml/parser.rb +24 -4
  104. data/lib/plurimath/omml/transform.rb +219 -157
  105. data/lib/plurimath/utility.rb +342 -20
  106. data/lib/plurimath/version.rb +1 -1
  107. metadata +21 -6
  108. data/.github/workflows/test.yml +0 -33
  109. data/lib/plurimath/mathml/parse.rb +0 -68
  110. data/lib/plurimath/omml/constants.rb +0 -154
@@ -3,14 +3,20 @@
3
3
  module Plurimath
4
4
  class Latex
5
5
  class Transform < Parslet::Transform
6
- rule(base: simple(:base)) { base }
7
- rule(over: simple(:over)) { over }
8
- rule(number: simple(:num)) { Math::Number.new(num) }
9
- rule(power: simple(:power)) { power }
10
- rule(unary: simple(:unary)) { Utility.get_class(unary).new }
11
- rule(operant: simple(:oper)) { Math::Symbol.new(oper) }
12
- rule("\\\\": simple(:slash)) { Math::Symbol.new(slash) }
13
- rule(limits: simple(:limits)) { limits }
6
+ rule(base: simple(:base)) { base }
7
+ rule(over: simple(:over)) { over }
8
+ rule(number: simple(:num)) { Math::Number.new(num) }
9
+ rule(power: simple(:power)) { power }
10
+ rule(unary: simple(:unary)) { Utility.get_class(unary).new }
11
+ rule(space: simple(:space)) { Math::Function::Text.new(" ") }
12
+ rule(operant: simple(:oper)) { Math::Symbol.new(oper) }
13
+ rule(symbol: simple(:symbol)) { Math::Symbol.new(symbol) }
14
+ rule(lparen: simple(:lparen)) { Math::Symbol.new(lparen) }
15
+ rule(rparen: simple(:rparen)) { Math::Symbol.new(rparen) }
16
+ rule(limits: simple(:limits)) { limits }
17
+ rule("\\\\" => simple(:slash)) { Math::Symbol.new(slash) }
18
+ rule(expression: simple(:expr)) { expr }
19
+ rule(environment: simple(:env)) { env }
14
20
 
15
21
  rule(unary_functions: simple(:unary)) { unary }
16
22
  rule(left_right: simple(:left_right)) { left_right }
@@ -18,25 +24,35 @@ module Plurimath
18
24
  rule(power_base: simple(:power_base)) { power_base }
19
25
  rule(table_data: simple(:table_data)) { table_data }
20
26
 
21
- rule(environment: simple(:environment)) { environment }
27
+ rule(numeric_values: simple(:value)) do
28
+ Math::Symbol.new(value)
29
+ end
22
30
 
23
31
  rule(text: simple(:text)) do
24
32
  Math::Function::Text.new(text)
25
33
  end
26
34
 
35
+ rule(unicode_symbols: simple(:unicode)) do
36
+ Math::Unicode.new(unicode)
37
+ end
38
+
27
39
  rule(binary: simple(:binary)) do
28
- binary.is_a?(String) ? Math::Function::Text.new(binary) : binary
40
+ binary.is_a?(Parslet::Slice) ? Utility.get_class(binary).new : binary
29
41
  end
30
42
 
31
43
  rule(symbols: simple(:sym)) do
32
- Math::Symbol.new(
33
- Constants::SYMBOLS[sym.to_sym] || sym,
34
- )
44
+ if sym.is_a?(Parslet::Slice)
45
+ Math::Symbol.new(
46
+ Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
47
+ )
48
+ else
49
+ sym
50
+ end
35
51
  end
36
52
 
37
53
  rule(lparen: simple(:lparen),
38
54
  rparen: simple(:rparen)) do
39
- Math::Formula.new
55
+ []
40
56
  end
41
57
 
42
58
  rule(left_right: simple(:left_right),
@@ -69,6 +85,34 @@ module Plurimath
69
85
  )
70
86
  end
71
87
 
88
+ rule(left: simple(:left),
89
+ lparen: simple(:lparen),
90
+ right: simple(:right)) do
91
+ Math::Formula.new(
92
+ [
93
+ Math::Function::Left.new(lparen),
94
+ Math::Function::Right.new,
95
+ ],
96
+ )
97
+ end
98
+
99
+ rule(left: simple(:left),
100
+ lparen: simple(:lparen),
101
+ right: simple(:right),
102
+ rparen: simple(:rparen)) do
103
+ Math::Formula.new(
104
+ [
105
+ Math::Function::Left.new(lparen),
106
+ Math::Function::Right.new(rparen),
107
+ ],
108
+ )
109
+ end
110
+
111
+ rule(left: simple(:left),
112
+ lparen: simple(:lparen)) do
113
+ Math::Function::Left.new(lparen)
114
+ end
115
+
72
116
  rule(left: simple(:left),
73
117
  lparen: simple(:lparen),
74
118
  expression: simple(:expr),
@@ -91,18 +135,54 @@ module Plurimath
91
135
  )
92
136
  end
93
137
 
138
+ rule(power: simple(:power),
139
+ expression: simple(:expr)) do
140
+ Math::Function::Power.new(
141
+ power,
142
+ expr,
143
+ )
144
+ end
145
+
146
+ rule(base: simple(:base),
147
+ expression: simple(:expr)) do
148
+ Math::Function::Base.new(
149
+ base,
150
+ expr,
151
+ )
152
+ end
153
+
154
+ rule(base: simple(:base),
155
+ expression: sequence(:expr)) do
156
+ Math::Function::Base.new(
157
+ base,
158
+ Utility.filter_values(expr),
159
+ )
160
+ end
161
+
162
+ rule(power: simple(:power),
163
+ expression: sequence(:expr)) do
164
+ Math::Function::Power.new(
165
+ power,
166
+ Utility.filter_values(expr),
167
+ )
168
+ end
169
+
94
170
  rule(left: simple(:left),
95
171
  lparen: simple(:lparen),
96
172
  dividend: subtree(:dividend),
97
- divisor: sequence(:divisor),
173
+ divisor: subtree(:divisor),
98
174
  right: simple(:right),
99
175
  rparen: simple(:rparen)) do
100
176
  Math::Formula.new(
101
177
  [
102
178
  Math::Function::Left.new(lparen),
103
179
  Math::Function::Over.new(
104
- Math::Formula.new(dividend.flatten),
105
- Math::Formula.new(divisor),
180
+ Math::Formula.new(
181
+ Array(dividend).flatten,
182
+ ),
183
+ Math::Formula.new(
184
+ Array(divisor).flatten,
185
+ ),
106
186
  ),
107
187
  Math::Function::Right.new(rparen),
108
188
  ],
@@ -112,8 +192,12 @@ module Plurimath
112
192
  rule(dividend: subtree(:dividend),
113
193
  divisor: subtree(:divisor)) do
114
194
  Math::Function::Over.new(
115
- Math::Formula.new(dividend.flatten),
116
- Math::Formula.new(divisor.flatten),
195
+ Math::Formula.new(
196
+ Array(dividend).flatten,
197
+ ),
198
+ Math::Formula.new(
199
+ Array(divisor).flatten,
200
+ ),
117
201
  )
118
202
  end
119
203
 
@@ -143,7 +227,7 @@ module Plurimath
143
227
 
144
228
  rule(sequence: simple(:sequence),
145
229
  expression: simple(:expr)) do
146
- [sequence, expr]
230
+ [sequence, expr].compact
147
231
  end
148
232
 
149
233
  rule(sequence: simple(:sequence),
@@ -153,9 +237,40 @@ module Plurimath
153
237
 
154
238
  rule(unary_functions: simple(:unary),
155
239
  subscript: simple(:subscript)) do
240
+ unary_function = if unary.is_a?(Parslet::Slice)
241
+ Utility.get_class(unary).new
242
+ else
243
+ unary
244
+ end
156
245
  Math::Function::Base.new(
246
+ unary_function,
247
+ subscript,
248
+ )
249
+ end
250
+
251
+ rule(binary_functions: simple(:binary),
252
+ supscript: simple(:supscript)) do
253
+ Math::Function::Power.new(
254
+ binary,
255
+ supscript,
256
+ )
257
+ end
258
+
259
+ rule(unary_functions: simple(:unary),
260
+ supscript: simple(:supscript)) do
261
+ Math::Function::Power.new(
262
+ unary,
263
+ supscript,
264
+ )
265
+ end
266
+
267
+ rule(unary_functions: simple(:unary),
268
+ subscript: simple(:subscript),
269
+ supscript: simple(:supscript)) do
270
+ Math::Function::PowerBase.new(
157
271
  unary,
158
272
  subscript,
273
+ supscript,
159
274
  )
160
275
  end
161
276
 
@@ -164,12 +279,12 @@ module Plurimath
164
279
  if Utility::FONT_STYLES[fonts.to_sym]
165
280
  Utility::FONT_STYLES[fonts.to_sym].new(
166
281
  int_exp,
167
- fonts,
282
+ fonts.to_s,
168
283
  )
169
284
  else
170
285
  Math::Function::FontStyle.new(
171
286
  int_exp,
172
- fonts,
287
+ fonts.to_s,
173
288
  )
174
289
  end
175
290
  end
@@ -182,38 +297,62 @@ module Plurimath
182
297
  )
183
298
  end
184
299
 
300
+ rule(number: simple(:number),
301
+ supscript: simple(:supscript)) do
302
+ Math::Function::Power.new(
303
+ Math::Number.new(number),
304
+ supscript,
305
+ )
306
+ end
307
+
185
308
  rule(symbols: simple(:sym),
186
309
  subscript: simple(:subscript)) do
187
310
  Math::Function::Base.new(
188
311
  Math::Symbol.new(
189
- Constants::SYMBOLS[sym.to_sym] || sym,
312
+ Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
190
313
  ),
191
314
  subscript,
192
315
  )
193
316
  end
194
317
 
318
+ rule(numeric_values: simple(:value),
319
+ subscript: simple(:subscript)) do
320
+ Math::Function::Base.new(
321
+ Math::Symbol.new(value),
322
+ subscript,
323
+ )
324
+ end
325
+
195
326
  rule(symbols: simple(:sym),
196
327
  supscript: simple(:supscript)) do
197
328
  Math::Function::Power.new(
198
329
  Math::Symbol.new(
199
- Constants::SYMBOLS[sym.to_sym] || sym,
330
+ Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
200
331
  ),
201
332
  supscript,
202
333
  )
203
334
  end
204
335
 
205
- rule(text: simple(:text),
336
+ rule(unicode_symbols: simple(:sym),
206
337
  subscript: simple(:subscript)) do
207
338
  Math::Function::Base.new(
208
- Math::Function::Text.new(text),
339
+ Math::Unicode.new(sym),
209
340
  subscript,
210
341
  )
211
342
  end
212
343
 
213
- rule(text: simple(:text),
344
+ rule(unicode_symbols: simple(:sym),
214
345
  supscript: simple(:supscript)) do
215
346
  Math::Function::Power.new(
216
- Math::Function::Text.new(text),
347
+ Math::Unicode.new(sym),
348
+ supscript,
349
+ )
350
+ end
351
+
352
+ rule(numeric_values: simple(:value),
353
+ supscript: simple(:supscript)) do
354
+ Math::Function::Power.new(
355
+ Math::Symbol.new(value),
217
356
  supscript,
218
357
  )
219
358
  end
@@ -236,12 +375,12 @@ module Plurimath
236
375
  font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
237
376
  Math::Function::FontStyle.new(
238
377
  int_exp,
239
- fonts,
378
+ fonts.to_s,
240
379
  )
241
380
  else
242
381
  Utility::FONT_STYLES[fonts.to_sym].new(
243
382
  int_exp,
244
- fonts,
383
+ fonts.to_s,
245
384
  )
246
385
  end
247
386
  Math::Function::Power.new(
@@ -256,12 +395,12 @@ module Plurimath
256
395
  font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
257
396
  Math::Function::FontStyle.new(
258
397
  int_exp,
259
- fonts,
398
+ fonts.to_s,
260
399
  )
261
400
  else
262
401
  Utility::FONT_STYLES[fonts.to_sym].new(
263
402
  int_exp,
264
- fonts,
403
+ fonts.to_s,
265
404
  )
266
405
  end
267
406
  Math::Function::Base.new(
@@ -273,65 +412,84 @@ module Plurimath
273
412
  rule(root: simple(:root),
274
413
  first_value: simple(:first_value),
275
414
  second_value: simple(:second_value)) do
415
+ second = second_value.nil? ? Math::Formula.new : second_value
276
416
  Math::Function::Root.new(
277
417
  first_value,
418
+ second,
419
+ )
420
+ end
421
+
422
+ rule(root: simple(:root),
423
+ first_value: sequence(:first_value),
424
+ second_value: simple(:second_value)) do
425
+ first = Utility.filter_values(first_value)
426
+ first = first.nil? ? Math::Formula.new : first
427
+ Math::Function::Root.new(
428
+ first,
278
429
  second_value,
279
430
  )
280
431
  end
281
432
 
282
- rule(unary_functions: simple(:unary),
433
+ rule(first_value: simple(:first_value),
283
434
  base: simple(:base),
284
435
  power: simple(:power)) do
285
436
  Math::Function::Limits.new(
286
- Utility.get_class(unary).new,
437
+ first_value,
287
438
  base,
288
439
  power,
289
440
  )
290
441
  end
291
442
 
292
443
  rule(lparen: simple(:lparen),
293
- mbox: simple(:mbox),
444
+ expression: sequence(:expr),
294
445
  rparen: simple(:rparen)) do
295
- Math::Function::Text.new("\\mbox{#{mbox}}")
446
+ Math::Formula.new(expr)
296
447
  end
297
448
 
298
- rule(lparen: simple(:lparen),
299
- symbols: simple(:sym),
300
- rparen: simple(:rparen)) do
301
- Math::Symbol.new(
302
- Constants::SYMBOLS[sym.to_sym] || sym,
449
+ rule(expression: sequence(:expr)) do
450
+ Math::Formula.new(expr)
451
+ end
452
+
453
+ rule(rule: simple(:rule),
454
+ first_value: simple(:first_value),
455
+ second_value: simple(:second_value),
456
+ third_value: simple(:third_value)) do
457
+ Math::Function::Rule.new(
458
+ first_value,
459
+ second_value,
460
+ third_value,
303
461
  )
304
462
  end
305
463
 
306
- rule(lparen: simple(:lparen),
307
- expression: simple(:expr),
308
- rparen: simple(:rparen)) do
309
- expr
464
+ rule(expression: simple(:expression),
465
+ subscript: simple(:subscript)) do
466
+ Math::Function::Base.new(
467
+ expression,
468
+ subscript,
469
+ )
310
470
  end
311
471
 
312
- rule(lparen: simple(:lparen),
313
- expression: sequence(:expr),
314
- rparen: simple(:rparen)) do
315
- Math::Formula.new(expr)
472
+ rule(rparen: simple(:rparen),
473
+ supscript: simple(:supscript)) do
474
+ Math::Function::Power.new(
475
+ Math::Symbol.new(rparen),
476
+ supscript,
477
+ )
316
478
  end
317
479
 
318
- rule(lparen: simple(:lparen),
319
- expression: simple(:expr),
320
- rparen: simple(:rparen),
480
+ rule(expression: simple(:expr),
321
481
  supscript: simple(:supscript)) do
322
482
  Math::Function::Power.new(
323
- Math::Formula.new(expr),
483
+ expr,
324
484
  supscript,
325
485
  )
326
486
  end
327
487
 
328
- rule(lparen: simple(:lparen),
329
- expression: simple(:expr),
330
- rparen: simple(:rparen),
331
- subscript: simple(:subscript)) do
332
- Math::Function::Base.new(
333
- Math::Formula.new(expr),
334
- subscript,
488
+ rule(expression: sequence(:expr),
489
+ supscript: simple(:supscript)) do
490
+ Math::Function::Power.new(
491
+ Utility.filter_values(expr),
492
+ supscript,
335
493
  )
336
494
  end
337
495
 
@@ -346,26 +504,33 @@ module Plurimath
346
504
 
347
505
  rule(binary: simple(:binary),
348
506
  subscript: simple(:subscript)) do
349
- Utility.get_class(binary).new(subscript)
507
+ if binary.is_a?(Parslet::Slice)
508
+ Utility.get_class(binary).new(subscript)
509
+ else
510
+ Math::Function::Base.new(
511
+ binary,
512
+ subscript,
513
+ )
514
+ end
350
515
  end
351
516
 
352
- rule(text: simple(:text),
517
+ rule(symbols: simple(:sym),
353
518
  subscript: simple(:subscript),
354
519
  supscript: simple(:supscript)) do
355
520
  Math::Function::PowerBase.new(
356
- Math::Function::Text.new(text),
521
+ Math::Symbol.new(
522
+ Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
523
+ ),
357
524
  subscript,
358
525
  supscript,
359
526
  )
360
527
  end
361
528
 
362
- rule(symbols: simple(:sym),
529
+ rule(unicode_symbols: simple(:sym),
363
530
  subscript: simple(:subscript),
364
531
  supscript: simple(:supscript)) do
365
532
  Math::Function::PowerBase.new(
366
- Math::Symbol.new(
367
- Constants::SYMBOLS[sym.to_sym] || sym,
368
- ),
533
+ Math::Unicode.new(sym),
369
534
  subscript,
370
535
  supscript,
371
536
  )
@@ -377,15 +542,19 @@ module Plurimath
377
542
  if binary == "binom"
378
543
  Math::Function::Table.new(
379
544
  [
380
- Math::Function::Tr.new([first_value]),
381
- Math::Function::Tr.new([second_value]),
545
+ Math::Function::Tr.new(
546
+ Utility.table_td(first_value),
547
+ ),
548
+ Math::Function::Tr.new(
549
+ Utility.table_td(second_value),
550
+ ),
382
551
  ],
383
552
  "(",
384
553
  ")",
385
554
  )
386
555
  else
387
556
  Utility.get_class(
388
- binary.include?("mod") ? "mod" : binary,
557
+ binary.to_s.include?("mod") ? "mod" : binary,
389
558
  ).new(
390
559
  first_value,
391
560
  second_value,
@@ -393,65 +562,151 @@ module Plurimath
393
562
  end
394
563
  end
395
564
 
396
- rule(begining: simple(:begining),
565
+ rule(underover: simple(:function),
566
+ first_value: simple(:first),
567
+ subscript: simple(:subscript),
568
+ supscript: simple(:supscript)) do
569
+ Math::Function::PowerBase.new(
570
+ Utility.get_class(function).new(first),
571
+ subscript,
572
+ supscript,
573
+ )
574
+ end
575
+
576
+ rule(environment: simple(:environment),
397
577
  table_data: sequence(:table_data),
398
578
  ending: simple(:ending)) do
399
- Utility.get_table_class(begining).new(
579
+ open_paren = Constants::MATRICES[environment.to_sym]
580
+ Utility.get_table_class(environment).new(
400
581
  Utility.organize_table(table_data),
582
+ open_paren,
583
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
584
+ {},
401
585
  )
402
586
  end
403
587
 
404
- rule(begining: simple(:begining),
588
+ rule(environment: simple(:environment),
405
589
  args: simple(:args),
406
590
  table_data: simple(:table_data),
407
591
  ending: simple(:ending)) do
408
- Utility.get_table_class(begining).new(
592
+ third_value = args ? [args] : []
593
+ open_paren = Constants::MATRICES[environment.to_sym]
594
+ table = Utility.organize_table(
595
+ [table_data],
596
+ column_align: third_value,
597
+ )
598
+ Utility.get_table_class(environment).new(
599
+ table,
600
+ open_paren,
601
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
602
+ Utility.table_options(table),
603
+ )
604
+ end
605
+
606
+ rule(environment: simple(:environment),
607
+ table_data: simple(:table_data),
608
+ ending: simple(:ending)) do
609
+ open_paren = Constants::MATRICES[environment.to_sym]
610
+ Utility.get_table_class(environment).new(
409
611
  Utility.organize_table([table_data]),
410
- nil,
411
- [args],
612
+ open_paren,
613
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
412
614
  )
413
615
  end
414
616
 
415
- rule(begining: simple(:begining),
617
+ rule(environment: simple(:environment),
416
618
  args: sequence(:args),
417
619
  table_data: sequence(:table_data),
418
620
  ending: simple(:ending)) do
419
- Utility.get_table_class(begining).new(
420
- Utility.organize_table(table_data),
421
- nil,
422
- args,
621
+ open_paren = Constants::MATRICES[environment.to_sym]
622
+ table = Utility.organize_table(table_data, column_align: args)
623
+ Utility.get_table_class(environment).new(
624
+ table,
625
+ open_paren,
626
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
627
+ Utility.table_options(table),
423
628
  )
424
629
  end
425
630
 
426
- rule(begining: simple(:begining),
631
+ rule(environment: simple(:environment),
427
632
  args: simple(:args),
428
633
  table_data: sequence(:table_data),
429
634
  ending: simple(:ending)) do
430
- Utility.get_table_class(begining).new(
635
+ third_value = args ? [args] : []
636
+ open_paren = Constants::MATRICES[environment.to_sym]
637
+ table = Utility.organize_table(table_data, column_align: third_value)
638
+ Utility.get_table_class(environment).new(
639
+ table,
640
+ open_paren,
641
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
642
+ Utility.table_options(table),
643
+ )
644
+ end
645
+
646
+ rule(environment: simple(:environment),
647
+ asterisk: simple(:asterisk),
648
+ options: simple(:options),
649
+ table_data: sequence(:table_data),
650
+ ending: simple(:ending)) do
651
+ third_value = options ? [options] : []
652
+ open_paren = Constants::MATRICES[environment.to_sym]
653
+ table = Utility.organize_table(
654
+ table_data,
655
+ column_align: third_value,
656
+ options: true,
657
+ )
658
+ Utility.get_table_class(environment).new(
659
+ table,
660
+ open_paren,
661
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
662
+ { asterisk: true },
663
+ )
664
+ end
665
+
666
+ rule(environment: simple(:environment),
667
+ asterisk: simple(:asterisk),
668
+ table_data: sequence(:table_data),
669
+ ending: simple(:ending)) do
670
+ open_paren = Constants::MATRICES[environment.to_sym]
671
+ Utility.get_table_class(environment).new(
431
672
  Utility.organize_table(table_data),
432
- nil,
433
- [args],
673
+ open_paren,
674
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
675
+ { asterisk: true },
434
676
  )
435
677
  end
436
678
 
437
679
  rule(environment: simple(:env),
438
- lparen: simple(:lparen),
439
- expression: sequence(:expr),
440
- rparen: simple(:rparen)) do
441
- left_paren = Constants::MATRICES[env.to_sym]
442
- Math::Function::Table.new(
443
- Utility.organize_table(expr),
444
- left_paren,
445
- Constants::PARENTHESIS[left_paren],
680
+ expression: simple(:expr)) do
681
+ open_paren = Constants::MATRICES[env.to_sym]
682
+ Utility.get_table_class(env).new(
683
+ Utility.organize_table(expr.nil? ? [] : [expr]),
684
+ open_paren,
685
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
686
+ {},
446
687
  )
447
688
  end
448
689
 
449
- rule(lparen: simple(:lparen),
450
- expression: sequence(:expr),
451
- rparen: simple(:rparen),
452
- supscript: simple(:supscript)) do
453
- formula = Math::Formula.new(expr)
454
- Math::Function::Power.new(formula, supscript)
690
+ rule(environment: simple(:env),
691
+ expression: sequence(:expr)) do
692
+ open_paren = Constants::MATRICES[env.to_sym]
693
+ Utility.get_table_class(env).new(
694
+ Utility.organize_table(expr.compact),
695
+ open_paren,
696
+ Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
697
+ {},
698
+ )
699
+ end
700
+
701
+ rule(substack: simple(:substack),
702
+ expression: sequence(:value)) do
703
+ tds = Utility.td_values(value, "\\\\")
704
+
705
+ substack_values = tds.map { |td| Math::Function::Tr.new([td]) }
706
+ Math::Function::Substack.new(
707
+ substack_values.shift,
708
+ substack_values.shift,
709
+ )
455
710
  end
456
711
  end
457
712
  end