plurimath 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +8 -11
  3. data/.gitignore +1 -0
  4. data/AsciiMath-Supported-Data.adoc +280 -0
  5. data/Gemfile +1 -0
  6. data/Latex-Supported-Data.adoc +1872 -0
  7. data/MathML-Supported-Data.adoc +270 -0
  8. data/README.adoc +94 -0
  9. data/lib/plurimath/asciimath/constants.rb +215 -222
  10. data/lib/plurimath/asciimath/parse.rb +45 -11
  11. data/lib/plurimath/asciimath/parser.rb +4 -3
  12. data/lib/plurimath/asciimath/transform.rb +222 -131
  13. data/lib/plurimath/asciimath.rb +1 -1
  14. data/lib/plurimath/html/constants.rb +50 -0
  15. data/lib/plurimath/html/parse.rb +149 -0
  16. data/lib/plurimath/html/parser.rb +26 -0
  17. data/lib/plurimath/html/transform.rb +363 -0
  18. data/lib/plurimath/html.rb +1 -1
  19. data/lib/plurimath/latex/constants.rb +1885 -1858
  20. data/lib/plurimath/latex/parse.rb +127 -34
  21. data/lib/plurimath/latex/parser.rb +5 -4
  22. data/lib/plurimath/latex/transform.rb +324 -164
  23. data/lib/plurimath/math/formula.rb +9 -1
  24. data/lib/plurimath/math/function/bar.rb +1 -1
  25. data/lib/plurimath/math/function/base.rb +7 -1
  26. data/lib/plurimath/math/function/binary_function.rb +10 -5
  27. data/lib/plurimath/math/function/color.rb +4 -4
  28. data/lib/plurimath/math/function/fenced.rb +7 -2
  29. data/lib/plurimath/math/function/font_style/bold.rb +18 -0
  30. data/lib/plurimath/math/function/font_style/double_struck.rb +18 -0
  31. data/lib/plurimath/math/function/font_style/fraktur.rb +18 -0
  32. data/lib/plurimath/math/function/font_style/monospace.rb +18 -0
  33. data/lib/plurimath/math/function/font_style/sans-serif.rb +18 -0
  34. data/lib/plurimath/math/function/font_style/script.rb +18 -0
  35. data/lib/plurimath/math/function/font_style.rb +2 -22
  36. data/lib/plurimath/math/function/frac.rb +4 -4
  37. data/lib/plurimath/math/function/inf.rb +0 -1
  38. data/lib/plurimath/math/function/left.rb +3 -6
  39. data/lib/plurimath/math/function/limits.rb +0 -1
  40. data/lib/plurimath/math/function/log.rb +6 -0
  41. data/lib/plurimath/math/function/mod.rb +6 -0
  42. data/lib/plurimath/math/function/multiscript.rb +11 -0
  43. data/lib/plurimath/math/function/norm.rb +2 -1
  44. data/lib/plurimath/math/function/over.rb +29 -0
  45. data/lib/plurimath/math/function/overset.rb +2 -2
  46. data/lib/plurimath/math/function/power.rb +7 -1
  47. data/lib/plurimath/math/function/power_base.rb +14 -7
  48. data/lib/plurimath/math/function/prod.rb +6 -0
  49. data/lib/plurimath/math/function/right.rb +24 -0
  50. data/lib/plurimath/math/function/root.rb +5 -4
  51. data/lib/plurimath/math/function/sqrt.rb +1 -1
  52. data/lib/plurimath/math/function/substack.rb +0 -1
  53. data/lib/plurimath/math/function/sum.rb +6 -0
  54. data/lib/plurimath/math/function/table/align.rb +24 -0
  55. data/lib/plurimath/math/function/table/array.rb +25 -0
  56. data/lib/plurimath/math/function/table/bmatrix.rb +26 -0
  57. data/lib/plurimath/math/function/table/matrix.rb +24 -0
  58. data/lib/plurimath/math/function/table/multline.rb +24 -0
  59. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  60. data/lib/plurimath/math/function/table/split.rb +24 -0
  61. data/lib/plurimath/math/function/table/vmatrix.rb +25 -0
  62. data/lib/plurimath/math/function/table.rb +17 -5
  63. data/lib/plurimath/math/function/td.rb +6 -1
  64. data/lib/plurimath/math/function/ternary_function.rb +16 -6
  65. data/lib/plurimath/math/function/text.rb +19 -7
  66. data/lib/plurimath/math/function/tr.rb +6 -1
  67. data/lib/plurimath/math/function/unary_function.rb +5 -0
  68. data/lib/plurimath/math/function/vec.rb +4 -0
  69. data/lib/plurimath/math/function.rb +13 -2
  70. data/lib/plurimath/math/number.rb +8 -0
  71. data/lib/plurimath/math/symbol.rb +12 -3
  72. data/lib/plurimath/math.rb +9 -4
  73. data/lib/plurimath/mathml/constants.rb +2 -34
  74. data/lib/plurimath/mathml/parse.rb +7 -2
  75. data/lib/plurimath/mathml/parser.rb +2 -1
  76. data/lib/plurimath/mathml/transform.rb +73 -68
  77. data/lib/plurimath/mathml.rb +1 -1
  78. data/lib/plurimath/omml/constants.rb +154 -0
  79. data/lib/plurimath/omml/parser.rb +22 -0
  80. data/lib/plurimath/omml/transform.rb +216 -0
  81. data/lib/plurimath/omml.rb +1 -1
  82. data/lib/plurimath/unitsml.rb +4 -0
  83. data/lib/plurimath/utility.rb +73 -0
  84. data/lib/plurimath/version.rb +1 -1
  85. data/plurimath.gemspec +1 -0
  86. metadata +49 -7
  87. data/README.md +0 -40
@@ -3,176 +3,372 @@
3
3
  module Plurimath
4
4
  class Latex
5
5
  class Transform < Parslet::Transform
6
- rule(base: simple(:base)) { base }
7
- rule(text: simple(:text)) { Math::Function::Text.new(text.to_s) }
8
- rule(number: simple(:num)) { Math::Number.new(num.to_s) }
9
- rule(power: simple(:power)) { power }
10
- rule(symbols: simple(:sym)) { Math::Symbol.new(sym.to_s) }
11
- rule(operant: simple(:oper)) { Math::Symbol.new(oper.to_s) }
12
- rule(ending: simple(:ending)) { nil }
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(operant: simple(:oper)) { Math::Symbol.new(oper) }
12
+ rule("\\\\": simple(:slash)) { Math::Symbol.new(slash) }
13
+ rule(limits: simple(:limits)) { limits }
14
+
15
+ rule(unary_functions: simple(:unary)) { unary }
16
+ rule(left_right: simple(:left_right)) { left_right }
17
+ rule(under_over: simple(:under_over)) { under_over }
18
+ rule(power_base: simple(:power_base)) { power_base }
19
+ rule(table_data: simple(:table_data)) { table_data }
20
+
21
+ rule(environment: simple(:environment)) { environment }
22
+
23
+ rule(text: simple(:text)) do
24
+ Math::Function::Text.new(text)
25
+ end
26
+
14
27
  rule(binary: simple(:binary)) do
15
- binary.is_a?(Slice) ? Transform.get_class(binary == "over" ? "overset" : binary).new : binary
28
+ binary.is_a?(String) ? Math::Function::Text.new(binary) : binary
16
29
  end
17
- rule("\\\\" => simple(:slash)) { Math::Symbol.new(slash.to_s) }
18
30
 
19
- rule(unary_functions: simple(:unary)) { unary }
20
- rule(under_over: simple(:under_over)) { under_over }
21
- rule(power_base: simple(:power_base)) { power_base }
22
- rule(table_data: simple(:table_data)) { table_data }
23
- rule(environment: simple(:environment)) { environment }
24
- rule(intermediate_exp: simple(:int_exp)) { int_exp }
25
- rule(lparen: simple(:lparen), rparen: simple(:rparen)) { nil }
31
+ rule(symbols: simple(:sym)) do
32
+ Math::Symbol.new(
33
+ Constants::SYMBOLS[sym.to_sym] || sym,
34
+ )
35
+ end
36
+
37
+ rule(lparen: simple(:lparen),
38
+ rparen: simple(:rparen)) do
39
+ Math::Formula.new
40
+ end
26
41
 
27
- rule(left_right: simple(:left_right)) do
28
- Math::Function::Left.new(left_right)
42
+ rule(left_right: simple(:left_right),
43
+ subscript: simple(:subscript)) do
44
+ Math::Function::Base.new(
45
+ left_right,
46
+ subscript,
47
+ )
29
48
  end
30
49
 
31
- rule(fonts: simple(:fonts), intermediate_exp: simple(:int_exp)) do
32
- Math::Function::FontStyle.new(int_exp, fonts.to_s)
50
+ rule(left_right: simple(:left_right),
51
+ supscript: simple(:supscript)) do
52
+ Math::Function::Power.new(
53
+ left_right,
54
+ supscript,
55
+ )
33
56
  end
34
57
 
35
- rule(number: simple(:number), subscript: simple(:subscript)) do
36
- number_object = Math::Number.new(number.to_s)
37
- Math::Function::Base.new(number_object, subscript)
58
+ rule(left: simple(:left),
59
+ lparen: simple(:lparen),
60
+ expression: sequence(:expr),
61
+ right: simple(:right),
62
+ rparen: simple(:rparen)) do
63
+ Math::Formula.new(
64
+ [
65
+ Math::Function::Left.new(lparen),
66
+ Math::Formula.new(expr),
67
+ Math::Function::Right.new(rparen),
68
+ ],
69
+ )
38
70
  end
39
71
 
40
- rule(symbols: simple(:symbol), subscript: simple(:subscript)) do
41
- symbol_object = Math::Symbol.new(symbol.to_s)
42
- Math::Function::Base.new(symbol_object, subscript)
72
+ rule(left: simple(:left),
73
+ lparen: simple(:lparen),
74
+ expression: simple(:expr),
75
+ right: simple(:right),
76
+ rparen: simple(:rparen)) do
77
+ Math::Formula.new(
78
+ [
79
+ Math::Function::Left.new(lparen),
80
+ expr,
81
+ Math::Function::Right.new(rparen),
82
+ ],
83
+ )
43
84
  end
44
85
 
45
- rule(text: simple(:text), subscript: simple(:subscript)) do
46
- text_object = Math::Function::Text.new(text.to_s)
47
- Math::Function::Base.new(text_object, subscript)
86
+ rule(power: simple(:power),
87
+ number: simple(:number)) do
88
+ Math::Function::Power.new(
89
+ power,
90
+ Math::Number.new(number),
91
+ )
48
92
  end
49
93
 
50
- rule(text: simple(:text), supscript: simple(:supscript)) do
51
- text_object = Math::Function::Text.new(text.to_s)
52
- Math::Function::Power.new(text_object, supscript)
94
+ rule(left: simple(:left),
95
+ lparen: simple(:lparen),
96
+ dividend: subtree(:dividend),
97
+ divisor: sequence(:divisor),
98
+ right: simple(:right),
99
+ rparen: simple(:rparen)) do
100
+ Math::Formula.new(
101
+ [
102
+ Math::Function::Left.new(lparen),
103
+ Math::Function::Over.new(
104
+ Math::Formula.new(dividend.flatten),
105
+ Math::Formula.new(divisor),
106
+ ),
107
+ Math::Function::Right.new(rparen),
108
+ ],
109
+ )
53
110
  end
54
111
 
55
- rule(unary: simple(:unary), first_value: simple(:first_value)) do
56
- class_name = unary == "overline" ? "bar" : unary
57
- Transform.get_class(class_name).new(first_value)
112
+ rule(dividend: subtree(:dividend),
113
+ divisor: subtree(:divisor)) do
114
+ Math::Function::Over.new(
115
+ Math::Formula.new(dividend.flatten),
116
+ Math::Formula.new(divisor.flatten),
117
+ )
58
118
  end
59
119
 
60
- rule(sqrt: simple(:sqrt), intermediate_exp: simple(:int_exp)) do
61
- Math::Function::Sqrt.new(int_exp)
120
+ rule(over: simple(:over),
121
+ subscript: simple(:subscript)) do
122
+ Math::Function::Base.new(
123
+ over,
124
+ subscript,
125
+ )
62
126
  end
63
127
 
64
- rule(root: simple(:root),
65
- first_value: simple(:first_value),
66
- second_value: simple(:second_value)) do
67
- Math::Function::Root.new(first_value, second_value)
128
+ rule(over: simple(:over),
129
+ supscript: simple(:supscript)) do
130
+ Math::Function::Power.new(
131
+ over,
132
+ supscript,
133
+ )
134
+ end
135
+
136
+ rule(operant: simple(:operant),
137
+ subscript: simple(:subscript)) do
138
+ Math::Function::Base.new(
139
+ Math::Symbol.new(operant),
140
+ subscript,
141
+ )
68
142
  end
69
143
 
70
- rule(sequence: simple(:sequence), expression: simple(:expr)) do
144
+ rule(sequence: simple(:sequence),
145
+ expression: simple(:expr)) do
71
146
  [sequence, expr]
72
147
  end
73
148
 
74
- rule(sequence: simple(:sequence), expression: sequence(:expr)) do
149
+ rule(sequence: simple(:sequence),
150
+ expression: sequence(:expr)) do
75
151
  [sequence] + expr
76
152
  end
77
153
 
154
+ rule(unary_functions: simple(:unary),
155
+ subscript: simple(:subscript)) do
156
+ Math::Function::Base.new(
157
+ unary,
158
+ subscript,
159
+ )
160
+ end
161
+
162
+ rule(fonts: simple(:fonts),
163
+ intermediate_exp: simple(:int_exp)) do
164
+ if Utility::FONT_STYLES[fonts.to_sym]
165
+ Utility::FONT_STYLES[fonts.to_sym].new(
166
+ int_exp,
167
+ fonts,
168
+ )
169
+ else
170
+ Math::Function::FontStyle.new(
171
+ int_exp,
172
+ fonts,
173
+ )
174
+ end
175
+ end
176
+
177
+ rule(number: simple(:number),
178
+ subscript: simple(:subscript)) do
179
+ Math::Function::Base.new(
180
+ Math::Number.new(number),
181
+ subscript,
182
+ )
183
+ end
184
+
185
+ rule(symbols: simple(:sym),
186
+ subscript: simple(:subscript)) do
187
+ Math::Function::Base.new(
188
+ Math::Symbol.new(
189
+ Constants::SYMBOLS[sym.to_sym] || sym,
190
+ ),
191
+ subscript,
192
+ )
193
+ end
194
+
195
+ rule(symbols: simple(:sym),
196
+ supscript: simple(:supscript)) do
197
+ Math::Function::Power.new(
198
+ Math::Symbol.new(
199
+ Constants::SYMBOLS[sym.to_sym] || sym,
200
+ ),
201
+ supscript,
202
+ )
203
+ end
204
+
205
+ rule(text: simple(:text),
206
+ subscript: simple(:subscript)) do
207
+ Math::Function::Base.new(
208
+ Math::Function::Text.new(text),
209
+ subscript,
210
+ )
211
+ end
212
+
213
+ rule(text: simple(:text),
214
+ supscript: simple(:supscript)) do
215
+ Math::Function::Power.new(
216
+ Math::Function::Text.new(text),
217
+ supscript,
218
+ )
219
+ end
220
+
221
+ rule(unary: simple(:unary),
222
+ first_value: simple(:first_value)) do
223
+ Utility.get_class(
224
+ unary == "overline" ? "bar" : unary,
225
+ ).new(first_value)
226
+ end
227
+
228
+ rule(sqrt: simple(:sqrt),
229
+ intermediate_exp: simple(:int_exp)) do
230
+ Math::Function::Sqrt.new(int_exp)
231
+ end
232
+
233
+ rule(fonts: simple(:fonts),
234
+ intermediate_exp: simple(:int_exp),
235
+ supscript: simple(:supscript)) do
236
+ font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
237
+ Math::Function::FontStyle.new(
238
+ int_exp,
239
+ fonts,
240
+ )
241
+ else
242
+ Utility::FONT_STYLES[fonts.to_sym].new(
243
+ int_exp,
244
+ fonts,
245
+ )
246
+ end
247
+ Math::Function::Power.new(
248
+ font_style,
249
+ supscript,
250
+ )
251
+ end
252
+
253
+ rule(fonts: simple(:fonts),
254
+ intermediate_exp: simple(:int_exp),
255
+ subscript: simple(:subscript)) do
256
+ font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
257
+ Math::Function::FontStyle.new(
258
+ int_exp,
259
+ fonts,
260
+ )
261
+ else
262
+ Utility::FONT_STYLES[fonts.to_sym].new(
263
+ int_exp,
264
+ fonts,
265
+ )
266
+ end
267
+ Math::Function::Base.new(
268
+ font_style,
269
+ subscript,
270
+ )
271
+ end
272
+
273
+ rule(root: simple(:root),
274
+ first_value: simple(:first_value),
275
+ second_value: simple(:second_value)) do
276
+ Math::Function::Root.new(
277
+ first_value,
278
+ second_value,
279
+ )
280
+ end
281
+
78
282
  rule(unary_functions: simple(:unary),
79
283
  base: simple(:base),
80
284
  power: simple(:power)) do
81
- Plurimath::Math::Function::Limits.new(
82
- Transform.get_class(unary).new,
285
+ Math::Function::Limits.new(
286
+ Utility.get_class(unary).new,
83
287
  base,
84
288
  power,
85
289
  )
86
290
  end
87
291
 
88
292
  rule(lparen: simple(:lparen),
89
- text: simple(:text),
293
+ mbox: simple(:mbox),
90
294
  rparen: simple(:rparen)) do
91
- Math::Function::Text.new(text.to_s)
295
+ Math::Function::Text.new("\\mbox{#{mbox}}")
92
296
  end
93
297
 
94
298
  rule(lparen: simple(:lparen),
95
- symbols: simple(:symbol),
299
+ symbols: simple(:sym),
96
300
  rparen: simple(:rparen)) do
97
- Math::Symbol.new(symbol.to_s)
98
- end
99
-
100
- rule(substack: simple(:substack),
101
- lparen: simple(:lparen),
102
- substack_value: sequence(:value),
103
- rparen: simple(:rparen)) do
104
- first_value = []
105
- until value.nil?
106
- if value.first.is_a?(Plurimath::Math::Symbol) &&
107
- value.first.value == "\\\\"
108
- value.delete_at(0)
109
- break;
110
- else
111
- first_value << value.delete_at(0)
112
- end
113
- end
114
- Transform.get_class(substack).new(
115
- Math::Formula.new(first_value),
116
- Math::Formula.new(value)
301
+ Math::Symbol.new(
302
+ Constants::SYMBOLS[sym.to_sym] || sym,
117
303
  )
118
304
  end
119
305
 
120
306
  rule(lparen: simple(:lparen),
121
- sequence: simple(:sequence),
122
- expression: sequence(:expr),
307
+ expression: simple(:expr),
123
308
  rparen: simple(:rparen)) do
124
- Math::Formula.new([sequence] + expr)
309
+ expr
125
310
  end
126
311
 
127
312
  rule(lparen: simple(:lparen),
128
- sequence: simple(:sequence),
129
- expression: simple(:expr),
313
+ expression: sequence(:expr),
130
314
  rparen: simple(:rparen)) do
131
- Math::Formula.new([sequence, expr])
315
+ Math::Formula.new(expr)
132
316
  end
133
317
 
134
318
  rule(lparen: simple(:lparen),
135
319
  expression: simple(:expr),
136
- rparen: simple(:rparen)) do
137
- if expr.is_a?(Slice) && Constants::ENVIRONMENTS.key?(expr.to_s)
138
- open_paren = Constants::ENVIRONMENTS[expr.to_s]
139
- close_paren = if Constants::PARENTHESIS[open_paren]
140
- Constants::PARENTHESIS[open_paren]
141
- elsif open_paren == "|"
142
- "|"
143
- end
144
- Math::Function::Table.new(
145
- nil,
146
- open_paren,
147
- close_paren,
148
- )
149
- else
150
- expr
151
- end
320
+ rparen: simple(:rparen),
321
+ supscript: simple(:supscript)) do
322
+ Math::Function::Power.new(
323
+ Math::Formula.new(expr),
324
+ supscript,
325
+ )
152
326
  end
153
327
 
154
328
  rule(lparen: simple(:lparen),
155
- expression: sequence(:expr),
156
- rparen: simple(:rparen)) do
157
- Math::Formula.new(expr)
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,
335
+ )
158
336
  end
159
337
 
160
338
  rule(binary: simple(:binary),
161
339
  subscript: simple(:subscript),
162
340
  supscript: simple(:supscript)) do
163
- Transform.get_class(binary).new(subscript, supscript)
341
+ Utility.get_class(binary).new(
342
+ subscript,
343
+ supscript,
344
+ )
164
345
  end
165
346
 
166
347
  rule(binary: simple(:binary),
167
348
  subscript: simple(:subscript)) do
168
- Transform.get_class(binary).new(subscript)
349
+ Utility.get_class(binary).new(subscript)
169
350
  end
170
351
 
171
352
  rule(text: simple(:text),
172
353
  subscript: simple(:subscript),
173
354
  supscript: simple(:supscript)) do
174
- text_object = Math::Function::Text.new(text.to_s)
175
- Math::Function::PowerBase.new(text_object, subscript, supscript)
355
+ Math::Function::PowerBase.new(
356
+ Math::Function::Text.new(text),
357
+ subscript,
358
+ supscript,
359
+ )
360
+ end
361
+
362
+ rule(symbols: simple(:sym),
363
+ subscript: simple(:subscript),
364
+ supscript: simple(:supscript)) do
365
+ Math::Function::PowerBase.new(
366
+ Math::Symbol.new(
367
+ Constants::SYMBOLS[sym.to_sym] || sym,
368
+ ),
369
+ subscript,
370
+ supscript,
371
+ )
176
372
  end
177
373
 
178
374
  rule(binary: simple(:binary),
@@ -180,74 +376,71 @@ module Plurimath
180
376
  second_value: simple(:second_value)) do
181
377
  if binary == "binom"
182
378
  Math::Function::Table.new(
183
- [Math::Function::Tr.new([first_value]),
184
- Math::Function::Tr.new([second_value])],
379
+ [
380
+ Math::Function::Tr.new([first_value]),
381
+ Math::Function::Tr.new([second_value]),
382
+ ],
185
383
  "(",
186
384
  ")",
187
385
  )
188
386
  else
189
- binary_class = if ["pmod", "bmod"].include?(binary)
190
- "mod"
191
- elsif binary == "over"
192
- "frac"
193
- else
194
- binary
195
- end
196
- Transform.get_class(binary_class).new(first_value, second_value)
387
+ Utility.get_class(
388
+ binary.include?("mod") ? "mod" : binary,
389
+ ).new(
390
+ first_value,
391
+ second_value,
392
+ )
197
393
  end
198
394
  end
199
395
 
200
396
  rule(begining: simple(:begining),
201
397
  table_data: sequence(:table_data),
202
398
  ending: simple(:ending)) do
203
- begining.parameter_one = Transform.organize_table(table_data)
204
- begining
205
- end
206
-
207
- rule(lparen: simple(:lparen),
208
- environment: simple(:env),
209
- rparen: simple(:rparen)) do
210
- env
399
+ Utility.get_table_class(begining).new(
400
+ Utility.organize_table(table_data),
401
+ )
211
402
  end
212
403
 
213
404
  rule(begining: simple(:begining),
214
405
  args: simple(:args),
215
406
  table_data: simple(:table_data),
216
407
  ending: simple(:ending)) do
217
- table_value = Transform.organize_table([table_data])
218
- begining.parameter_one = table_value
219
- begining.parameter_three = [args]
220
- begining
408
+ Utility.get_table_class(begining).new(
409
+ Utility.organize_table([table_data]),
410
+ nil,
411
+ [args],
412
+ )
221
413
  end
222
414
 
223
415
  rule(begining: simple(:begining),
224
416
  args: sequence(:args),
225
417
  table_data: sequence(:table_data),
226
418
  ending: simple(:ending)) do
227
- table_value = Transform.organize_table(table_data)
228
- begining.parameter_one = table_value
229
- begining.parameter_three = args
230
- begining
419
+ Utility.get_table_class(begining).new(
420
+ Utility.organize_table(table_data),
421
+ nil,
422
+ args,
423
+ )
231
424
  end
232
425
 
233
426
  rule(begining: simple(:begining),
234
427
  args: simple(:args),
235
428
  table_data: sequence(:table_data),
236
429
  ending: simple(:ending)) do
237
- table_value = Transform.organize_table(table_data)
238
- begining.parameter_one = table_value
239
- begining.parameter_three = [args]
240
- begining
430
+ Utility.get_table_class(begining).new(
431
+ Utility.organize_table(table_data),
432
+ nil,
433
+ [args],
434
+ )
241
435
  end
242
436
 
243
437
  rule(environment: simple(:env),
244
438
  lparen: simple(:lparen),
245
439
  expression: sequence(:expr),
246
440
  rparen: simple(:rparen)) do
247
- table_value = Transform.organize_table(expr)
248
- left_paren = Constants::ENVIRONMENTS[env.to_s]
441
+ left_paren = Constants::MATRICES[env.to_sym]
249
442
  Math::Function::Table.new(
250
- table_value,
443
+ Utility.organize_table(expr),
251
444
  left_paren,
252
445
  Constants::PARENTHESIS[left_paren],
253
446
  )
@@ -260,39 +453,6 @@ module Plurimath
260
453
  formula = Math::Formula.new(expr)
261
454
  Math::Function::Power.new(formula, supscript)
262
455
  end
263
-
264
- rule(lparen: simple(:lparen),
265
- expression: simple(:expr),
266
- rparen: simple(:rparen),
267
- subscript: simple(:subscript)) do
268
- formula = Math::Formula.new(expr)
269
- Math::Function::Base.new(formula, subscript)
270
- end
271
-
272
- class << self
273
- def organize_table(array, table = [], table_data = [], table_row = [])
274
- array.each do |data|
275
- if data.is_a?(Math::Symbol) && data.value == "&"
276
- table_row << Math::Function::Td.new(table_data)
277
- table_data = []
278
- elsif data.is_a?(Math::Symbol) && data.value == "\\\\"
279
- table_row << Math::Function::Td.new(table_data)
280
- table << Math::Function::Tr.new(table_row.flatten)
281
- table_row = []
282
- table_data = []
283
- else
284
- table_data << data
285
- end
286
- end
287
- table_row << Math::Function::Td.new(table_data) if table_data
288
- table << Math::Function::Tr.new(table_row) unless table_row.empty?
289
- table
290
- end
291
-
292
- def get_class(text)
293
- Object.const_get("Plurimath::Math::Function::#{text.to_s.capitalize}")
294
- end
295
- end
296
456
  end
297
457
  end
298
458
  end
@@ -19,7 +19,7 @@ module Plurimath
19
19
 
20
20
  def to_mathml
21
21
  <<~MATHML
22
- <math xmlns='http://www.w3.org/1998/Math/MathML'>
22
+ <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'>
23
23
  <mstyle displaystyle='true'>
24
24
  #{mathml_content}
25
25
  </mstyle>
@@ -38,6 +38,14 @@ module Plurimath
38
38
  def to_latex
39
39
  value.map(&:to_latex).join
40
40
  end
41
+
42
+ def to_html
43
+ value.map(&:to_html).join
44
+ end
45
+
46
+ def class_name
47
+ "formula"
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -8,7 +8,7 @@ module Plurimath
8
8
  class Bar < UnaryFunction
9
9
  def to_latex
10
10
  first_value = "{#{parameter_one.to_latex}}" if parameter_one
11
- "\\overline#{first_value}"
11
+ "\\bar#{first_value}"
12
12
  end
13
13
  end
14
14
  end
@@ -20,10 +20,16 @@ module Plurimath
20
20
 
21
21
  def to_latex
22
22
  first_value = parameter_one.to_latex if parameter_one
23
- first_value = "{#{first_value}}" if parameter_one.is_a?(Math::Formula)
23
+ first_value = "{#{first_value}}" if parameter_one.is_a?(Formula)
24
24
  second_value = parameter_two.to_latex if parameter_two
25
25
  "#{first_value}_{#{second_value}}"
26
26
  end
27
+
28
+ def to_html
29
+ first_value = "<i>#{parameter_one.to_html}</i>" if parameter_one
30
+ second_value = "<sub>#{parameter_two.to_html}</sub>" if parameter_two
31
+ "#{first_value}#{second_value}"
32
+ end
27
33
  end
28
34
  end
29
35
  end