plurimath 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) 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/.gitignore +1 -0
  5. data/.hound.yml +5 -0
  6. data/.rubocop.yml +8 -0
  7. data/AsciiMath-Supported-Data.adoc +2000 -0
  8. data/Gemfile +3 -0
  9. data/Latex-Supported-Data.adoc +1879 -0
  10. data/MathML-Supported-Data.adoc +287 -0
  11. data/README.adoc +96 -0
  12. data/lib/plurimath/asciimath/constants.rb +267 -229
  13. data/lib/plurimath/asciimath/parse.rb +125 -26
  14. data/lib/plurimath/asciimath/parser.rb +6 -3
  15. data/lib/plurimath/asciimath/transform.rb +1135 -208
  16. data/lib/plurimath/asciimath.rb +1 -1
  17. data/lib/plurimath/html/constants.rb +50 -0
  18. data/lib/plurimath/html/parse.rb +149 -0
  19. data/lib/plurimath/html/parser.rb +26 -0
  20. data/lib/plurimath/html/transform.rb +363 -0
  21. data/lib/plurimath/html.rb +1 -1
  22. data/lib/plurimath/latex/constants.rb +3729 -1906
  23. data/lib/plurimath/latex/parse.rb +167 -51
  24. data/lib/plurimath/latex/parser.rb +12 -4
  25. data/lib/plurimath/latex/transform.rb +598 -183
  26. data/lib/plurimath/math/base.rb +15 -0
  27. data/lib/plurimath/math/formula.rb +96 -11
  28. data/lib/plurimath/math/function/bar.rb +34 -0
  29. data/lib/plurimath/math/function/base.rb +32 -5
  30. data/lib/plurimath/math/function/binary_function.rb +104 -17
  31. data/lib/plurimath/math/function/cancel.rb +8 -0
  32. data/lib/plurimath/math/function/ceil.rb +3 -0
  33. data/lib/plurimath/math/function/color.rb +16 -6
  34. data/lib/plurimath/math/function/f.rb +8 -0
  35. data/lib/plurimath/math/function/fenced.rb +95 -3
  36. data/lib/plurimath/math/function/floor.rb +15 -0
  37. data/lib/plurimath/math/function/font_style/bold.rb +37 -0
  38. data/lib/plurimath/math/function/font_style/double_struck.rb +37 -0
  39. data/lib/plurimath/math/function/font_style/fraktur.rb +37 -0
  40. data/lib/plurimath/math/function/font_style/italic.rb +37 -0
  41. data/lib/plurimath/math/function/font_style/monospace.rb +37 -0
  42. data/lib/plurimath/math/function/font_style/normal.rb +37 -0
  43. data/lib/plurimath/math/function/font_style/sans-serif.rb +37 -0
  44. data/lib/plurimath/math/function/font_style/script.rb +37 -0
  45. data/lib/plurimath/math/function/font_style.rb +18 -25
  46. data/lib/plurimath/math/function/frac.rb +35 -5
  47. data/lib/plurimath/math/function/g.rb +7 -0
  48. data/lib/plurimath/math/function/hat.rb +12 -0
  49. data/lib/plurimath/math/function/inf.rb +21 -1
  50. data/lib/plurimath/math/function/int.rb +23 -2
  51. data/lib/plurimath/math/function/left.rb +25 -4
  52. data/lib/plurimath/math/function/lim.rb +40 -2
  53. data/lib/plurimath/math/function/limits.rb +8 -0
  54. data/lib/plurimath/math/function/log.rb +61 -4
  55. data/lib/plurimath/math/function/longdiv.rb +12 -0
  56. data/lib/plurimath/math/function/mbox.rb +31 -0
  57. data/lib/plurimath/math/function/menclose.rb +46 -0
  58. data/lib/plurimath/math/function/merror.rb +12 -0
  59. data/lib/plurimath/math/function/mod.rb +25 -4
  60. data/lib/plurimath/math/function/msgroup.rb +37 -0
  61. data/lib/plurimath/math/function/msline.rb +12 -0
  62. data/lib/plurimath/math/function/multiscript.rb +30 -0
  63. data/lib/plurimath/math/function/norm.rb +18 -1
  64. data/lib/plurimath/math/function/obrace.rb +17 -0
  65. data/lib/plurimath/math/function/oint.rb +2 -2
  66. data/lib/plurimath/math/function/over.rb +36 -0
  67. data/lib/plurimath/math/function/overset.rb +36 -7
  68. data/lib/plurimath/math/function/phantom.rb +28 -0
  69. data/lib/plurimath/math/function/power.rb +33 -9
  70. data/lib/plurimath/math/function/power_base.rb +110 -5
  71. data/lib/plurimath/math/function/prod.rb +29 -2
  72. data/lib/plurimath/math/function/right.rb +44 -0
  73. data/lib/plurimath/math/function/root.rb +27 -4
  74. data/lib/plurimath/math/function/rule.rb +33 -0
  75. data/lib/plurimath/math/function/scarries.rb +12 -0
  76. data/lib/plurimath/math/function/scarry.rb +12 -0
  77. data/lib/plurimath/math/function/sqrt.rb +24 -2
  78. data/lib/plurimath/math/function/stackrel.rb +27 -0
  79. data/lib/plurimath/math/function/substack.rb +7 -1
  80. data/lib/plurimath/math/function/sum.rb +56 -2
  81. data/lib/plurimath/math/function/sup.rb +3 -0
  82. data/lib/plurimath/math/function/table/align.rb +24 -0
  83. data/lib/plurimath/math/function/table/array.rb +44 -0
  84. data/lib/plurimath/math/function/table/bmatrix.rb +37 -0
  85. data/lib/plurimath/math/function/table/matrix.rb +32 -0
  86. data/lib/plurimath/math/function/table/multline.rb +24 -0
  87. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  88. data/lib/plurimath/math/function/table/split.rb +24 -0
  89. data/lib/plurimath/math/function/table/vmatrix.rb +24 -0
  90. data/lib/plurimath/math/function/table.rb +190 -20
  91. data/lib/plurimath/math/function/td.rb +27 -9
  92. data/lib/plurimath/math/function/ternary_function.rb +83 -8
  93. data/lib/plurimath/math/function/text.rb +45 -8
  94. data/lib/plurimath/math/function/tr.rb +28 -4
  95. data/lib/plurimath/math/function/ubrace.rb +17 -0
  96. data/lib/plurimath/math/function/ul.rb +29 -0
  97. data/lib/plurimath/math/function/unary_function.rb +85 -7
  98. data/lib/plurimath/math/function/underline.rb +12 -0
  99. data/lib/plurimath/math/function/underover.rb +107 -0
  100. data/lib/plurimath/math/function/underset.rb +39 -0
  101. data/lib/plurimath/math/function/vec.rb +10 -0
  102. data/lib/plurimath/math/function.rb +13 -2
  103. data/lib/plurimath/math/number.rb +11 -3
  104. data/lib/plurimath/math/symbol.rb +57 -9
  105. data/lib/plurimath/math/unicode.rb +11 -0
  106. data/lib/plurimath/math.rb +15 -6
  107. data/lib/plurimath/mathml/constants.rb +224 -179
  108. data/lib/plurimath/mathml/parser.rb +24 -7
  109. data/lib/plurimath/mathml/transform.rb +249 -148
  110. data/lib/plurimath/mathml.rb +1 -1
  111. data/lib/plurimath/omml/parser.rb +42 -0
  112. data/lib/plurimath/omml/transform.rb +278 -0
  113. data/lib/plurimath/omml.rb +1 -1
  114. data/lib/plurimath/unitsml.rb +4 -0
  115. data/lib/plurimath/utility.rb +395 -0
  116. data/lib/plurimath/version.rb +1 -1
  117. data/plurimath.gemspec +1 -0
  118. metadata +66 -9
  119. data/.github/workflows/test.yml +0 -36
  120. data/README.md +0 -40
  121. data/lib/plurimath/mathml/parse.rb +0 -63
@@ -4,77 +4,76 @@ module Plurimath
4
4
  class Mathml
5
5
  class Constants
6
6
  UNICODE_SYMBOLS = {
7
- "α": "alpha",
8
- "β": "beta",
9
- "γ": "gamma",
7
+ "α": "alpha",
8
+ "β": "beta",
9
+ "γ": "gamma",
10
10
  "Γ": "Gamma",
11
- "δ": "delta",
11
+ "δ": "delta",
12
12
  "Δ": "Delta",
13
13
  "∆": "Delta",
14
- "ε": "epsilon",
14
+ "ε": "epsilon",
15
15
  "ɛ": "varepsilon",
16
- "ζ": "zeta",
17
- "η": "eta",
18
- "θ": "theta",
16
+ "ζ": "zeta",
17
+ "η": "eta",
18
+ "θ": "theta",
19
19
  "Θ": "Theta",
20
- "ϑ": "vartheta",
21
- "ι": "iota",
22
- "κ": "kappa",
23
- "λ": "lambda",
24
- "Λ": "Lambda",
25
- "μ": "mu",
26
- "ν": "nu",
27
- "ξ": "xi",
28
- "Ξ": "Xi",
20
+ "ϑ": "vartheta",
21
+ "ι": "iota",
22
+ "κ": "kappa",
23
+ "λ": "lambda",
24
+ "Λ": "Lambda",
25
+ "μ": "mu",
26
+ "ν": "nu",
27
+ "ξ": "xi",
28
+ "Ξ": "Xi",
29
29
  "π": "pi",
30
- "Π": "Pi",
31
- "ρ": "rho",
32
- "ς": "beta",
33
- "σ": "sigma",
34
- "Σ": "Sigma",
35
- "τ": "tau",
36
- "υ": "upsilon",
37
- "φ": "phi",
38
- "Φ": "Phi",
39
- "ϕ": "varphi",
40
- "χ": "chi",
41
- "ψ": "psi",
42
- "Ψ": "Psi",
43
- "ω": "omega",
44
- "Ω": "omega",
45
- "⋅": "dot",
30
+ "Π": "Pi",
31
+ "ρ": "rho",
32
+ "ς": "beta",
33
+ "σ": "sigma",
34
+ "Σ": "Sigma",
35
+ "τ": "tau",
36
+ "υ": "upsilon",
37
+ "φ": "phi",
38
+ "Φ": "Phi",
39
+ "ϕ": "varphi",
40
+ "χ": "chi",
41
+ "ψ": "psi",
42
+ "Ψ": "Psi",
43
+ "ω": "omega",
44
+ "Ω": "omega",
45
+ "⋅": "dot",
46
46
  "∙": "*",
47
- "·": ".",
47
+ "·": ".",
48
48
  "∗": "**",
49
- "⋆": "***",
50
- "×": "xx",
51
- "&#x22C9;": "|><",
52
- "&#x22CA;": "><|",
53
- "&#x22C8;": "|><|",
54
- "&#xF7;": "-:",
49
+ "&#x22c6;": "***",
50
+ "&#xd7;": "xx",
51
+ "&#x22c9;": "|><",
52
+ "&#x22ca;": "><|",
53
+ "&#x22c8;": "|><|",
54
+ "&#xf7;": "-:",
55
55
  "&#x2218;": "@",
56
56
  "&#x2295;": "o+",
57
- "&#x2A01;": "o+",
57
+ "&#x2a01;": "o+",
58
58
  "&#x2297;": "ox",
59
59
  "&#x2299;": " ",
60
60
  "&#x2211;": "sum",
61
- "&#x220F;": "prod",
62
61
  "&#x220f;": "prod",
63
62
  "&#x2227;": "^^",
64
- "&#x22C0;": "^^^",
63
+ "&#x22c0;": "^^^",
65
64
  "&#x2228;": "vv",
66
65
  "&#x22c1;": "vvv",
67
66
  "&#x2229;": "nn",
68
- "&#x22C2;": "nnn",
69
- "&#x222A;": "cup",
70
- "&#x22C3;": "uuu",
67
+ "&#x22c2;": "nnn",
68
+ "&#x222a;": "cup",
69
+ "&#x22c3;": "uuu",
71
70
  "&#x2260;": "!=",
72
71
  "&#x2264;": "<=",
73
72
  "&#x2265;": ">=",
74
- "&#x227A;": "-<",
75
- "&#x227B;": ">-",
76
- "&#x2AAF;": "-<=",
77
- "&#x2AB0;": " >-=",
73
+ "&#x227a;": "-<",
74
+ "&#x227b;": ">-",
75
+ "&#x2aaf;": "-<=",
76
+ "&#x2ab0;": " >-=",
78
77
  "&#x2208;": "in",
79
78
  "&#x2209;": "!in",
80
79
  "&#x2282;": "sub",
@@ -84,65 +83,68 @@ module Plurimath
84
83
  "&#x2261;": "-=",
85
84
  "&#x2245;": "~=",
86
85
  "&#x2248;": "~~",
87
- "&#x221D;": "prop",
88
- "&#xAC;": "not",
86
+ "&#x221d;": "prop",
87
+ "&#xac;": "not",
89
88
  "&#x2200;": "AA",
90
89
  "&#x2203;": "EE",
91
- "&#x22A5;": "_|_",
92
- "&#x22A4;": "TT",
93
- "&#x22A2;": "|--",
94
- "&#x22A8;": "|==",
90
+ "&#x22a5;": "_|_",
91
+ "&#x22a4;": "TT",
92
+ "&#x22a2;": "|--",
93
+ "&#x22a8;": "|==",
95
94
  "&#x2329;": "(:",
96
- "&#x232A;": ":)",
97
- "&#x27E8;": "<<",
98
- "&#x27E9;": ">>",
99
- "&#x222B;": "int",
100
- "&#x222E;": "oint",
95
+ "&#x232a;": ":)",
96
+ "&#x27e8;": "<<",
97
+ "&#x27e9;": ">>",
98
+ "&#x222b;": "int",
99
+ "&#x222e;": "oint",
101
100
  "&#x2202;": "del",
102
101
  "&#x2207;": "grad",
103
- "&#xB1;": "+-",
102
+ "&#xb1;": "+-",
104
103
  "&#x2205;": "O/",
105
- "&#x221E;": "oo",
104
+ "&#x221e;": "oo",
106
105
  "&#x2135;": "aleph",
107
106
  "&#x2234;": ":.",
108
107
  "&#x2235;": ":'",
109
108
  "&#x2220;": "/_",
110
- "&#x25B3;": "/_\\",
109
+ "&#x25b3;": "/_\\",
111
110
  "&#x2032;": "'",
112
- "&#xA0;&#xA0;": "quad",
113
- "&#xA0;&#xA0;&#xA0;&#xA0;": "qquad",
111
+ "&#xa0;&#xa0;": "quad",
112
+ "&#xa0;&#xa0;&#xa0;&#xa0;": "qquad",
114
113
  "&#x2322;": "frown",
115
- "&#x22EF;": "cdots",
116
- "&#x22EE;": "vdots",
117
- "&#x22F1;": "ddots",
118
- "&#x22C4;": "diamond",
119
- "&#x25A1;": "square",
120
- "&#x230A;": "|__",
121
- "&#x230B;": "__|",
114
+ "&#x22ef;": "cdots",
115
+ "&#x22ee;": "vdots",
116
+ "&#x22f1;": "ddots",
117
+ "&#x22c4;": "diamond",
118
+ "&#x25a1;": "square",
119
+ "&#x230a;": "|__",
120
+ "&#x230b;": "__|",
122
121
  "&#x2308;": "|~",
123
122
  "&#x2309;": "~|",
124
123
  "&#x2102;": "CC",
125
124
  "&#x2115;": "NN",
126
- "&#x211A;": "QQ",
127
- "&#x211D;": "RR",
125
+ "&#x211a;": "QQ",
126
+ "&#x211d;": "RR",
128
127
  "&#x2124;": "ZZ",
129
128
  "&#x2191;": "uarr",
130
129
  "&#x2193;": "darr",
131
130
  "&#x2190;": "larr",
132
131
  "&#x2194;": "harr",
133
- "&#x21D2;": "rArr",
134
- "&#x21D0;": "lArr",
135
- "&#x21D4;": "hArr",
132
+ "&#x21d2;": "rArr",
133
+ "&#x21d0;": "lArr",
134
+ "&#x21d4;": "hArr",
136
135
  "&#x2192;": "->",
137
- "&#x21A3;": ">->",
138
- "&#x21A0;": "->>",
136
+ "&#x21a3;": ">->",
137
+ "&#x21a0;": "->>",
139
138
  "&#x2916;": ">->>",
140
- "&#x21A6;": "|->",
139
+ "&#x21a6;": "|->",
141
140
  "&#x2026;": "...",
142
141
  "&#x2212;": "-",
143
- "&#x2061;": "",
144
- "&#x23DE;": "obrace",
145
- "&#x23DF;": "ubrace",
142
+ "&#x23de;": "obrace",
143
+ "&#x23df;": "ubrace",
144
+ "&#x26;": "&",
145
+ "&#x3e;": ">",
146
+ "&#x3c;": "<",
147
+ "&amp;": "&",
146
148
  }.freeze
147
149
  SYMBOLS = {
148
150
  "|": "|",
@@ -226,102 +228,145 @@ module Plurimath
226
228
  f
227
229
  g
228
230
  ].freeze
229
- TAGS = %i[
230
- annotation-xml
231
- annotation_xml
232
- mmultiscripts
233
- maligngroup
234
- malignmark
235
- annotation
236
- munderover
237
- mscarries
238
- semantics
239
- mphantom
240
- mlongdiv
241
- menclose
242
- mscarry
243
- msubsup
244
- mpadded
245
- maction
246
- msgroup
247
- mfenced
248
- merror
249
- munder
250
- mtable
251
- mstyle
252
- mstack
253
- mspace
254
- msline
255
- mfrac
256
- mover
257
- msrow
258
- mroot
259
- msqrt
260
- msup
261
- msub
262
- mrow
263
- math
264
- mtr
265
- mtd
266
- ms
267
- mi
268
- mo
269
- mn
231
+ OPERATORS = [
232
+ "&#x00a0;&#x00a0;&#x00a0;&#x00a0;",
233
+ "&#x00a0;&#x00a0;",
234
+ "&#x002a;",
235
+ "&#x003c;",
236
+ "&#x003e;",
237
+ "&#x00a0;",
238
+ "&#x00ac;",
239
+ "&#x00b1;",
240
+ "&#x00d7;",
241
+ "&#x00f7;",
242
+ "&#x0393;",
243
+ "&#x0394;",
244
+ "&#x0398;",
245
+ "&#x039b;",
246
+ "&#x039e;",
247
+ "&#x03a0;",
248
+ "&#x03a3;",
249
+ "&#x03a9;",
250
+ "&#x2026;",
251
+ "&#x2032;",
252
+ "&#x2102;",
253
+ "&#x2115;",
254
+ "&#x211a;",
255
+ "&#x211d;",
256
+ "&#x2124;",
257
+ "&#x2135;",
258
+ "&#x2190;",
259
+ "&#x2191;",
260
+ "&#x2192;",
261
+ "&#x2192;",
262
+ "&#x2193;",
263
+ "&#x2194;",
264
+ "&#x21a0;",
265
+ "&#x21a3;",
266
+ "&#x21a6;",
267
+ "&#x21d0;",
268
+ "&#x21d2;",
269
+ "&#x21d2;",
270
+ "&#x21d4;",
271
+ "&#x21d4;",
272
+ "&#x2200;",
273
+ "&#x2202;",
274
+ "&#x2203;",
275
+ "&#x2205;",
276
+ "&#x2207;",
277
+ "&#x2208;",
278
+ "&#x2209;",
279
+ "&#x220f;",
280
+ "&#x2211;",
281
+ "&#x2212;",
282
+ "&#x2213;",
283
+ "&#x221d;",
284
+ "&#x221e;",
285
+ "&#x2220;",
286
+ "&#x2227;",
287
+ "&#x2228;",
288
+ "&#x2229;",
289
+ "&#x222a;",
290
+ "&#x222b;",
291
+ "&#x222e;",
292
+ "&#x2234;",
293
+ "&#x2235;",
294
+ "&#x223c;",
295
+ "&#x2245;",
296
+ "&#x2248;",
297
+ "&#x2254;",
298
+ "&#x2260;",
299
+ "&#x2261;",
300
+ "&#x2264;",
301
+ "&#x2265;",
302
+ "&#x226a;",
303
+ "&#x226b;",
304
+ "&#x227a;",
305
+ "&#x227b;",
306
+ "&#x2282;",
307
+ "&#x2283;",
308
+ "&#x2286;",
309
+ "&#x2287;",
310
+ "&#x2295;",
311
+ "&#x2297;",
312
+ "&#x2299;",
313
+ "&#x22a2;",
314
+ "&#x22a4;",
315
+ "&#x22a5;",
316
+ "&#x22a8;",
317
+ "&#x22c0;",
318
+ "&#x22c1;",
319
+ "&#x22c2;",
320
+ "&#x22c3;",
321
+ "&#x22c4;",
322
+ "&#x22c5;",
323
+ "&#x22c6;",
324
+ "&#x22c8;",
325
+ "&#x22c9;",
326
+ "&#x22ca;",
327
+ "&#x22ee;",
328
+ "&#x22ef;",
329
+ "&#x22f1;",
330
+ "&#x2308;",
331
+ "&#x2309;",
332
+ "&#x230a;",
333
+ "&#x230b;",
334
+ "&#x2322;",
335
+ "&#x25a1;",
336
+ "&#x25b3;",
337
+ "&#x26ac;",
338
+ "&#x2916;",
339
+ "&#x2aaf;",
340
+ "&#x2ab0;",
341
+ "&#x2b;",
342
+ "&#x3d;",
343
+ "&#x3a;",
344
+ "&#x3c;",
345
+ "&#xd7;",
346
+ "&#xb1;",
347
+ "&#x26;",
348
+ "&#x3b;",
349
+ "&#x3e;",
350
+ "&#x7c;",
351
+ "lim",
352
+ "max",
353
+ "min",
354
+ "\\",
355
+ "//",
356
+ "/",
357
+ "if",
358
+ "^",
359
+ "_",
360
+ "+",
361
+ "/",
362
+ "=",
363
+ ":",
364
+ ",",
365
+ ")",
366
+ "(",
367
+ "[",
368
+ "]",
270
369
  ].freeze
271
- BINARY_CLASSES = %i[
272
- underset
273
- stackrel
274
- overset
275
- color
276
- prod
277
- frac
278
- root
279
- oint
280
- int
281
- sum
282
- mod
283
- log
284
- ].freeze
285
- FONT_CLASSES = %i[
286
- fraktur
287
- sans-serif
288
- monospace
289
- script
290
- double-struck
291
- bold
292
- ].freeze
293
- FONT_TYPES = {
294
- :bb=>"bold",
295
- :fr=>"fraktur",
296
- :cc=>"script",
297
- :sf=>"sans-serif",
298
- :tt=>"monospace",
299
- :mbf=>"bold",
300
- :mit=>"italic",
301
- :mtt=>"monospace",
302
- :Bbb=>"double-struck",
303
- :bbb=>"double-struck",
304
- :mscr=>"mathbb",
305
- :mfrak=>"fraktur",
306
- :msans=>"sans-serif",
307
- :mbfit=>"bold italic",
308
- :mathbf=>"bold",
309
- :mathit=>"italic",
310
- :mathds=>"mathbb",
311
- :mathrm=>"mathrm",
312
- :mathtt=>"monospace",
313
- :mathsf=>"sans-serif",
314
- :mathbb=>"double-struck",
315
- :mbfsans=>"bold sans-serif",
316
- :mathcal=>"script",
317
- :mathbold=>"bold",
318
- :mathfrak=>"fraktur",
319
- :mathbfit=>"bold italic",
320
- :mathsfbf=>"sans-serif bold",
321
- :mathsfit=>"sans-serif italic",
322
- :mbfitsans=>"bold italic sans-serif",
323
- :mathsfbfit=>"sans-serif bold italic",
324
- }.freeze
325
370
  end
326
371
  end
327
372
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "parse"
4
3
  require_relative "constants"
5
4
  require_relative "transform"
6
5
  module Plurimath
@@ -9,16 +8,34 @@ module Plurimath
9
8
  attr_accessor :text
10
9
 
11
10
  def initialize(text)
12
- @text = text.gsub("\n", "").gsub(" ", "")
11
+ @text = text
13
12
  end
14
13
 
15
14
  def parse
16
- tree_t = Plurimath::Mathml::Parse.new.parse(text)
17
- formula = Plurimath::Mathml::Transform.new.apply(tree_t)
18
- formula = [formula] unless formula.is_a?(Array) || formula.nil?
19
- return if formula.nil?
15
+ ox_nodes = Ox.load(text, strip_namespace: true).nodes
16
+ nodes = parse_nodes(ox_nodes)
17
+ Math::Formula.new(
18
+ Transform.new.apply(nodes).flatten.compact,
19
+ )
20
+ end
21
+
22
+ def parse_nodes(nodes)
23
+ nodes.map do |node|
24
+ next if node.is_a?(Ox::Comment)
20
25
 
21
- Plurimath::Math::Formula.new(formula)
26
+ if node.is_a?(String)
27
+ node
28
+ elsif !node.attributes.empty?
29
+ {
30
+ node.name.to_sym => {
31
+ attributes: node.attributes.transform_keys(&:to_sym),
32
+ value: parse_nodes(node.nodes),
33
+ },
34
+ }
35
+ else
36
+ { node.name.to_sym => parse_nodes(node.nodes) }
37
+ end
38
+ end
22
39
  end
23
40
  end
24
41
  end