plurimath 0.8.16 → 0.8.18

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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/gen_docs.yml +10 -8
  3. data/Gemfile +1 -1
  4. data/README.adoc +4 -0
  5. data/Rakefile +55 -8
  6. data/intent_supported_classes.adoc +82 -0
  7. data/lib/plurimath/asciimath/parse.rb +1 -0
  8. data/lib/plurimath/asciimath/transform.rb +12 -0
  9. data/lib/plurimath/formatter/number_formatter.rb +6 -6
  10. data/lib/plurimath/formatter/numeric_formatter.rb +5 -2
  11. data/lib/plurimath/formatter/standard.rb +2 -0
  12. data/lib/plurimath/math/core.rb +65 -6
  13. data/lib/plurimath/math/formula/mrow.rb +193 -0
  14. data/lib/plurimath/math/formula/mstyle.rb +17 -0
  15. data/lib/plurimath/math/formula.rb +317 -7
  16. data/lib/plurimath/math/function/abs.rb +5 -1
  17. data/lib/plurimath/math/function/base.rb +4 -0
  18. data/lib/plurimath/math/function/color.rb +17 -4
  19. data/lib/plurimath/math/function/fenced.rb +238 -7
  20. data/lib/plurimath/math/function/frac.rb +12 -1
  21. data/lib/plurimath/math/function/inf.rb +5 -1
  22. data/lib/plurimath/math/function/int.rb +5 -1
  23. data/lib/plurimath/math/function/intent.rb +6 -2
  24. data/lib/plurimath/math/function/lim.rb +5 -1
  25. data/lib/plurimath/math/function/linebreak.rb +2 -2
  26. data/lib/plurimath/math/function/longdiv.rb +3 -0
  27. data/lib/plurimath/math/function/menclose.rb +3 -0
  28. data/lib/plurimath/math/function/merror.rb +5 -2
  29. data/lib/plurimath/math/function/mglyph.rb +27 -0
  30. data/lib/plurimath/math/function/mlabeledtr.rb +19 -0
  31. data/lib/plurimath/math/function/mpadded.rb +28 -1
  32. data/lib/plurimath/math/function/ms.rb +80 -0
  33. data/lib/plurimath/math/function/msgroup.rb +15 -0
  34. data/lib/plurimath/math/function/msline.rb +5 -2
  35. data/lib/plurimath/math/function/multiscript.rb +14 -0
  36. data/lib/plurimath/math/function/nary.rb +13 -1
  37. data/lib/plurimath/math/function/oint.rb +5 -1
  38. data/lib/plurimath/math/function/over.rb +3 -0
  39. data/lib/plurimath/math/function/overset.rb +11 -0
  40. data/lib/plurimath/math/function/phantom.rb +3 -0
  41. data/lib/plurimath/math/function/power.rb +3 -0
  42. data/lib/plurimath/math/function/power_base.rb +3 -0
  43. data/lib/plurimath/math/function/prod.rb +5 -1
  44. data/lib/plurimath/math/function/root.rb +3 -0
  45. data/lib/plurimath/math/function/scarries.rb +3 -0
  46. data/lib/plurimath/math/function/semantics.rb +14 -0
  47. data/lib/plurimath/math/function/sqrt.rb +3 -0
  48. data/lib/plurimath/math/function/stackrel.rb +3 -0
  49. data/lib/plurimath/math/function/sum.rb +5 -1
  50. data/lib/plurimath/math/function/table/array.rb +1 -1
  51. data/lib/plurimath/math/function/table/bmatrix.rb +1 -1
  52. data/lib/plurimath/math/function/table/cases.rb +2 -2
  53. data/lib/plurimath/math/function/table/eqarray.rb +2 -2
  54. data/lib/plurimath/math/function/table/pmatrix.rb +1 -1
  55. data/lib/plurimath/math/function/table/vmatrix.rb +1 -1
  56. data/lib/plurimath/math/function/table.rb +65 -0
  57. data/lib/plurimath/math/function/td.rb +4 -1
  58. data/lib/plurimath/math/function/text.rb +22 -2
  59. data/lib/plurimath/math/function/tr.rb +13 -0
  60. data/lib/plurimath/math/function/unary_function.rb +5 -1
  61. data/lib/plurimath/math/function/underover.rb +3 -0
  62. data/lib/plurimath/math/function/underset.rb +44 -0
  63. data/lib/plurimath/math/number.rb +10 -1
  64. data/lib/plurimath/math/symbols/bigwedge.rb +4 -0
  65. data/lib/plurimath/math/symbols/cap.rb +0 -4
  66. data/lib/plurimath/math/symbols/clockoint.rb +1 -1
  67. data/lib/plurimath/math/symbols/cntclockoint.rb +1 -1
  68. data/lib/plurimath/math/symbols/coprod.rb +1 -1
  69. data/lib/plurimath/math/symbols/dd.rb +4 -0
  70. data/lib/plurimath/math/symbols/dint.rb +4 -0
  71. data/lib/plurimath/math/symbols/duni.rb +4 -0
  72. data/lib/plurimath/math/symbols/gg.rb +4 -4
  73. data/lib/plurimath/math/symbols/ii.rb +4 -0
  74. data/lib/plurimath/math/symbols/iiiint.rb +1 -1
  75. data/lib/plurimath/math/symbols/iiint.rb +4 -0
  76. data/lib/plurimath/math/symbols/iint.rb +1 -1
  77. data/lib/plurimath/math/symbols/intclockwise.rb +1 -1
  78. data/lib/plurimath/math/symbols/intercal.rb +4 -0
  79. data/lib/plurimath/math/symbols/jj.rb +4 -0
  80. data/lib/plurimath/math/symbols/ll.rb +4 -4
  81. data/lib/plurimath/math/symbols/minus.rb +1 -1
  82. data/lib/plurimath/math/symbols/oiiint.rb +1 -1
  83. data/lib/plurimath/math/symbols/oiint.rb +1 -1
  84. data/lib/plurimath/math/symbols/oint.rb +1 -1
  85. data/lib/plurimath/math/symbols/symbol.rb +12 -4
  86. data/lib/plurimath/math/symbols/upcase_dd.rb +4 -0
  87. data/lib/plurimath/math.rb +2 -0
  88. data/lib/plurimath/mathml/parser.rb +45 -86
  89. data/lib/plurimath/mathml/utility/empty_defined_methods.rb +477 -0
  90. data/lib/plurimath/mathml/utility/formula_transformation.rb +472 -0
  91. data/lib/plurimath/mathml/utility.rb +363 -0
  92. data/lib/plurimath/mathml.rb +1 -0
  93. data/lib/plurimath/unicode_math/transform.rb +2 -2
  94. data/lib/plurimath/utility/intent_encoding.rb +21 -21
  95. data/lib/plurimath/utility.rb +5 -23
  96. data/lib/plurimath/version.rb +1 -1
  97. data/lib/plurimath.rb +9 -0
  98. data/plurimath.gemspec +4 -2
  99. metadata +38 -5
  100. data/lib/plurimath/mathml/transform.rb +0 -411
@@ -1,106 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "constants"
4
- require_relative "transform"
4
+
5
5
  module Plurimath
6
6
  class Mathml
7
7
  class Parser
8
8
  attr_accessor :text
9
9
 
10
- SUPPORTED_ATTRS = %w[
11
- linebreakstyle
12
- linethickness
13
- columnlines
14
- mathvariant
15
- accentunder
16
- separators
17
- linebreak
18
- mathcolor
19
- notation
20
- bevelled
21
- rowlines
22
- intent
23
- accent
24
- height
25
- frame
26
- depth
27
- height
28
- width
29
- index
30
- close
31
- alt
32
- src
33
- open
34
- ].freeze
35
-
36
10
  def initialize(text)
11
+ mml_config
37
12
  @text = text
38
13
  end
39
14
 
40
15
  def parse
41
- ox_nodes = Plurimath.xml_engine.load(text)
42
- display_style = ox_nodes&.locate("mstyle/@displaystyle")&.first
43
- nodes = parse_nodes(Array(ox_nodes))
44
- Math::Formula.new(
45
- Transform.new.apply(nodes).flatten.compact,
46
- display_style: (display_style || true),
47
- )
16
+ namespace_exist = text.split(">").first.include?(" xmlns=")
17
+ ::Mml.parse(text, namespace_exist: namespace_exist)
48
18
  end
49
19
 
50
- protected
51
-
52
- def parse_nodes(nodes)
53
- nodes.map do |node|
54
- next if Plurimath.xml_engine.is_xml_comment?(node)
55
-
56
- if node.is_a?(String)
57
- node
58
- elsif !node.attributes.empty?
59
- attrs_hash(node)
60
- else
61
- manage_tags(node)
62
- end
63
- end
64
- end
65
-
66
- def validate_attributes(attributes)
67
- attributes&.select! { |key, _| SUPPORTED_ATTRS.include?(key.to_s) }
68
- attributes&.transform_keys(&:to_sym) if attributes&.any?
69
- end
20
+ private
70
21
 
71
- def attrs_hash(node)
72
- {
73
- node.name.to_sym => {
74
- attributes: validate_attributes(node.attributes),
75
- value: parse_nodes(node.nodes),
76
- },
22
+ def mml_config
23
+ ::Mml::Configuration.config = {
24
+ mmultiscripts: Plurimath::Math::Function::Multiscript,
25
+ mlabeledtr: Plurimath::Math::Function::Mlabeledtr,
26
+ munderover: Plurimath::Math::Function::Underover,
27
+ semantics: Plurimath::Math::Function::Semantics,
28
+ mscarries: Plurimath::Math::Function::Scarries,
29
+ mfraction: Plurimath::Math::Function::Frac,
30
+ menclose: Plurimath::Math::Function::Menclose,
31
+ mlongdiv: Plurimath::Math::Function::Longdiv,
32
+ mphantom: Plurimath::Math::Function::Phantom,
33
+ msubsup: Plurimath::Math::Function::PowerBase,
34
+ msgroup: Plurimath::Math::Function::Msgroup,
35
+ mpadded: Plurimath::Math::Function::Mpadded,
36
+ mfenced: Plurimath::Math::Function::Fenced,
37
+ mstack: Plurimath::Math::Function::Stackrel,
38
+ munder: Plurimath::Math::Function::Underset,
39
+ msline: Plurimath::Math::Function::Msline,
40
+ merror: Plurimath::Math::Function::Merror,
41
+ mtable: Plurimath::Math::Function::Table,
42
+ mstyle: Plurimath::Math::Formula::Mstyle,
43
+ mglyph: Plurimath::Math::Function::Mglyph,
44
+ mover: Plurimath::Math::Function::Overset,
45
+ msqrt: Plurimath::Math::Function::Sqrt,
46
+ mroot: Plurimath::Math::Function::Root,
47
+ mtext: Plurimath::Math::Function::Text,
48
+ mfrac: Plurimath::Math::Function::Frac,
49
+ msrow: Plurimath::Math::Formula,
50
+ msup: Plurimath::Math::Function::Power,
51
+ msub: Plurimath::Math::Function::Base,
52
+ none: Plurimath::Math::Function::None,
53
+ mrow: Plurimath::Math::Formula::Mrow,
54
+ math: Plurimath::Math::Formula,
55
+ mtd: Plurimath::Math::Function::Td,
56
+ mtr: Plurimath::Math::Function::Tr,
57
+ mi: Plurimath::Math::Symbols::Symbol,
58
+ mo: Plurimath::Math::Symbols::Symbol,
59
+ ms: Plurimath::Math::Function::Ms,
60
+ mn: Plurimath::Math::Number,
77
61
  }
78
- end
79
-
80
- def manage_tags(node)
81
- if node.name == "ms"
82
- Plurimath::xml_engine.replace_nodes(
83
- node,
84
- ms_tag(comment_remove(node.nodes)).join(" "),
85
- )
86
- end
87
- { node.name.to_sym => parse_nodes(node.nodes) }
88
- end
89
-
90
- def ms_tag(nodes)
91
- return nodes if nodes.any?(String)
92
-
93
- nodes.map do |node|
94
- if node.nodes.any?(String)
95
- node.nodes
96
- else
97
- ms_tag(node.nodes)
98
- end
99
- end
100
- end
101
-
102
- def comment_remove(nodes)
103
- nodes.delete_if { |node| Plurimath.xml_engine.is_xml_comment?(node) }
62
+ require "mml" unless ::Mml.respond_to?(:config)
104
63
  end
105
64
  end
106
65
  end
@@ -0,0 +1,477 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Mathml
5
+ module Utility
6
+ module EmptyDefinedMethods
7
+ def mi_value; end
8
+
9
+ def mo_value; end
10
+
11
+ def mn_value; end
12
+
13
+ def ms_value; end
14
+
15
+ def mtd_value; end
16
+
17
+ def mtr_value; end
18
+
19
+ def msub_value; end
20
+
21
+ def none_value; end
22
+
23
+ def msup_value; end
24
+
25
+ def mrow_value; end
26
+
27
+ def mroot_value; end
28
+
29
+ def mover_value; end
30
+
31
+ def mtext_value; end
32
+
33
+ def mfrac_value; end
34
+
35
+ def msrow_value; end
36
+
37
+ def msqrt_value; end
38
+
39
+ def mstack_value; end
40
+
41
+ def mspace_value; end
42
+
43
+ def mtable_value; end
44
+
45
+ def msline_value; end
46
+
47
+ def mstyle_value; end
48
+
49
+ def munder_value; end
50
+
51
+ def merror_value; end
52
+
53
+ def msubsup_value; end
54
+
55
+ def msgroup_value; end
56
+
57
+ def mfenced_value; end
58
+
59
+ def mpadded_value; end
60
+
61
+ def mphantom_value; end
62
+
63
+ def mlongdiv_value; end
64
+
65
+ def menclose_value; end
66
+
67
+ def mscarries_value; end
68
+
69
+ def semantics_value; end
70
+
71
+ def mlabeledtr_value; end
72
+
73
+ def munderover_value; end
74
+
75
+ def malignmark_value; end
76
+
77
+ def maligngroup_value; end
78
+
79
+ def mmultiscripts_value; end
80
+
81
+ def id; end
82
+
83
+ def dir; end
84
+
85
+ def color; end
86
+
87
+ def mathsize; end
88
+
89
+ def fontsize; end
90
+
91
+ def mathcolor; end
92
+
93
+ def fontstyle; end
94
+
95
+ def fontweight; end
96
+
97
+ def malignmark; end
98
+
99
+ def fontfamily; end
100
+
101
+ def background; end
102
+
103
+ def mathvariant; end
104
+
105
+ def scriptlevel; end
106
+
107
+ def decimalpoint; end
108
+
109
+ def displaystyle; end
110
+
111
+ def scriptminsize; end
112
+
113
+ def mathbackground; end
114
+
115
+ def mathbackgroundcolor; end
116
+
117
+ def infixlinebreakstyle; end
118
+
119
+ def scriptsizemultiplier; end
120
+
121
+ def accent; end
122
+
123
+ def annotation; end
124
+
125
+ def accentunder; end
126
+
127
+ def align; end
128
+
129
+ def alignmentscope; end
130
+
131
+ def bevelled; end
132
+
133
+ def charalign; end
134
+
135
+ def charspacing; end
136
+
137
+ def close; end
138
+
139
+ def columnalign; end
140
+
141
+ def columnlines; end
142
+
143
+ def columnspacing; end
144
+
145
+ def columnspan; end
146
+
147
+ def columnwidth; end
148
+
149
+ def crossout; end
150
+
151
+ def denomalign; end
152
+
153
+ def depth; end
154
+
155
+ def edge; end
156
+
157
+ def equalcolumns; end
158
+
159
+ def equalrows; end
160
+
161
+ def fence; end
162
+
163
+ def form; end
164
+
165
+ def frame; end
166
+
167
+ def framespacing; end
168
+
169
+ def groupalign; end
170
+
171
+ def height; end
172
+
173
+ def indentalign; end
174
+
175
+ def indentalignfirst; end
176
+
177
+ def indentalignlast; end
178
+
179
+ def indentshift; end
180
+
181
+ def indentshiftfirst; end
182
+
183
+ def indentshiftlast; end
184
+
185
+ def indenttarget; end
186
+
187
+ def largeop; end
188
+
189
+ def intent; end
190
+
191
+ def leftoverhang; end
192
+
193
+ def length; end
194
+
195
+ def linebreak; end
196
+
197
+ def linebreakmultchar; end
198
+
199
+ def linebreakstyle; end
200
+
201
+ def lineleading; end
202
+
203
+ def linethickness; end
204
+
205
+ def location; end
206
+
207
+ def longdivstyle; end
208
+
209
+ def lquote; end
210
+
211
+ def lspace; end
212
+
213
+ def maxsize; end
214
+
215
+ def minlabelspacing; end
216
+
217
+ def minsize; end
218
+
219
+ def movablelimits; end
220
+
221
+ def mslinethickness; end
222
+
223
+ def notation; end
224
+
225
+ def numalign; end
226
+
227
+ def open; end
228
+
229
+ def position; end
230
+
231
+ def rightoverhang; end
232
+
233
+ def rowalign; end
234
+
235
+ def rowlines; end
236
+
237
+ def rowspacing; end
238
+
239
+ def rowspan; end
240
+
241
+ def rquote; end
242
+
243
+ def rspace; end
244
+
245
+ def selection; end
246
+
247
+ def separator; end
248
+
249
+ def separators; end
250
+
251
+ def shift; end
252
+
253
+ def side; end
254
+
255
+ def stackalign; end
256
+
257
+ def stretchy; end
258
+
259
+ def subscriptshift; end
260
+
261
+ def superscriptshift; end
262
+
263
+ def symmetric; end
264
+
265
+ def valign; end
266
+
267
+ def width; end
268
+
269
+ def veryverythinmathspace; end
270
+
271
+ def verythinmathspace; end
272
+
273
+ def thinmathspace; end
274
+
275
+ def mediummathspace; end
276
+
277
+ def thickmathspace; end
278
+
279
+ def verythickmathspace; end
280
+
281
+ def veryverythickmathspace; end
282
+
283
+ def mscarry_value; end
284
+
285
+ def mfraction_value; end
286
+
287
+ def mprescripts_value; end
288
+
289
+ def mglyph_value; end
290
+
291
+ def malignmark=(_); end
292
+
293
+ def mathcolor=(_); end
294
+
295
+ def mathbackground=(_); end
296
+
297
+ def mathsize=(_); end
298
+
299
+ def dir=(_); end
300
+
301
+ def fontfamily=(_); end
302
+
303
+ def fontweight=(_); end
304
+
305
+ def fontstyle=(_); end
306
+
307
+ def fontsize=(_); end
308
+
309
+ def color=(_); end
310
+
311
+ def mathbackgroundcolor=(_); end
312
+
313
+ def background=(_); end
314
+
315
+ def scriptlevel=(_); end
316
+
317
+ def displaystyle=(_); end
318
+
319
+ def scriptsizemultiplier=(_); end
320
+
321
+ def scriptminsize=(_); end
322
+
323
+ def infixlinebreakstyle=(_); end
324
+
325
+ def decimalpoint=(_); end
326
+
327
+ def align=(_); end
328
+
329
+ def alignmentscope=(_); end
330
+
331
+ def charalign=(_); end
332
+
333
+ def charspacing=(_); end
334
+
335
+ def close=(_); end
336
+
337
+ def columnalign=(_); end
338
+
339
+ def columnlines=(_); end
340
+
341
+ def columnspacing=(_); end
342
+
343
+ def columnspan=(_); end
344
+
345
+ def columnwidth=(_); end
346
+
347
+ def crossout=(_); end
348
+
349
+ def denomalign=(_); end
350
+
351
+ def depth=(_); end
352
+
353
+ def edge=(_); end
354
+
355
+ def equalcolumns=(_); end
356
+
357
+ def equalrows=(_); end
358
+
359
+ def fence=(_); end
360
+
361
+ def form=(_); end
362
+
363
+ def frame=(_); end
364
+
365
+ def framespacing=(_); end
366
+
367
+ def groupalign=(_); end
368
+
369
+ def height=(_); end
370
+
371
+ def indentalign=(_); end
372
+
373
+ def indentalignfirst=(_); end
374
+
375
+ def indentalignlast=(_); end
376
+
377
+ def indentshift=(_); end
378
+
379
+ def indentshiftfirst=(_); end
380
+
381
+ def indentshiftlast=(_); end
382
+
383
+ def indenttarget=(_); end
384
+
385
+ def intent=(_); end
386
+
387
+ def largeop=(_); end
388
+
389
+ def leftoverhang=(_); end
390
+
391
+ def length=(_); end
392
+
393
+ def linebreakmultchar=(_); end
394
+
395
+ def lineleading=(_); end
396
+
397
+ def location=(_); end
398
+
399
+ def longdivstyle=(_); end
400
+
401
+ def lquote=(_); end
402
+
403
+ def lspace=(_); end
404
+
405
+ def maxsize=(_); end
406
+
407
+ def minlabelspacing=(_); end
408
+
409
+ def minsize=(_); end
410
+
411
+ def movablelimits=(_); end
412
+
413
+ def mslinethickness=(_); end
414
+
415
+ def numalign=(_); end
416
+
417
+ def open=(_); end
418
+
419
+ def position=(_); end
420
+
421
+ def rightoverhang=(_); end
422
+
423
+ def rowalign=(_); end
424
+
425
+ def rowlines=(_); end
426
+
427
+ def rowspacing=(_); end
428
+
429
+ def rowspan=(_); end
430
+
431
+ def rquote=(_); end
432
+
433
+ def rspace=(_); end
434
+
435
+ def selection=(_); end
436
+
437
+ def separator=(_); end
438
+
439
+ def separators=(_); end
440
+
441
+ def shift=(_); end
442
+
443
+ def side=(_); end
444
+
445
+ def stackalign=(_); end
446
+
447
+ def stretchy=(_); end
448
+
449
+ def subscriptshift=(_); end
450
+
451
+ def superscriptshift=(_); end
452
+
453
+ def symmetric=(_); end
454
+
455
+ def valign=(_); end
456
+
457
+ def width=(_); end
458
+
459
+ def veryverythinmathspace=(_); end
460
+
461
+ def verythinmathspace=(_); end
462
+
463
+ def thinmathspace=(_); end
464
+
465
+ def mediummathspace=(_); end
466
+
467
+ def thickmathspace=(_); end
468
+
469
+ def verythickmathspace=(_); end
470
+
471
+ def veryverythickmathspace=(_); end
472
+
473
+ def mprescripts_value=(_); end
474
+ end
475
+ end
476
+ end
477
+ end