plurimath 0.10.0 → 0.10.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 (186) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec-opal +1 -1
  3. data/.rubocop.yml +9 -5
  4. data/.rubocop_todo.yml +0 -0
  5. data/Gemfile +7 -5
  6. data/README.adoc +57 -1
  7. data/Rakefile +11 -0
  8. data/lib/plurimath/asciimath/parse.rb +0 -1
  9. data/lib/plurimath/asciimath/parser.rb +0 -3
  10. data/lib/plurimath/asciimath.rb +5 -0
  11. data/lib/plurimath/cli.rb +28 -1
  12. data/lib/plurimath/errors.rb +0 -4
  13. data/lib/plurimath/formatter/numbers.rb +12 -0
  14. data/lib/plurimath/formatter/numeric_formatter.rb +4 -1
  15. data/lib/plurimath/formatter/standard.rb +0 -1
  16. data/lib/plurimath/formatter.rb +6 -9
  17. data/lib/plurimath/html/parse.rb +0 -1
  18. data/lib/plurimath/html/parser.rb +0 -3
  19. data/lib/plurimath/html.rb +5 -0
  20. data/lib/plurimath/latex/parse.rb +0 -1
  21. data/lib/plurimath/latex/parser.rb +2 -5
  22. data/lib/plurimath/latex.rb +5 -0
  23. data/lib/plurimath/math/core.rb +6 -2
  24. data/lib/plurimath/math/formula/mrow.rb +2 -41
  25. data/lib/plurimath/math/formula/mstyle.rb +6 -0
  26. data/lib/plurimath/math/formula.rb +59 -301
  27. data/lib/plurimath/math/function/abs.rb +0 -1
  28. data/lib/plurimath/math/function/arccos.rb +0 -1
  29. data/lib/plurimath/math/function/arcsin.rb +0 -1
  30. data/lib/plurimath/math/function/arctan.rb +0 -1
  31. data/lib/plurimath/math/function/arg.rb +0 -1
  32. data/lib/plurimath/math/function/bar.rb +0 -1
  33. data/lib/plurimath/math/function/base.rb +0 -3
  34. data/lib/plurimath/math/function/binary_function.rb +5 -3
  35. data/lib/plurimath/math/function/cancel.rb +0 -1
  36. data/lib/plurimath/math/function/ceil.rb +0 -1
  37. data/lib/plurimath/math/function/color.rb +0 -1
  38. data/lib/plurimath/math/function/cos.rb +0 -1
  39. data/lib/plurimath/math/function/cosh.rb +0 -1
  40. data/lib/plurimath/math/function/cot.rb +0 -1
  41. data/lib/plurimath/math/function/coth.rb +0 -1
  42. data/lib/plurimath/math/function/csc.rb +0 -1
  43. data/lib/plurimath/math/function/csch.rb +0 -1
  44. data/lib/plurimath/math/function/ddot.rb +0 -1
  45. data/lib/plurimath/math/function/deg.rb +0 -1
  46. data/lib/plurimath/math/function/det.rb +0 -1
  47. data/lib/plurimath/math/function/dim.rb +0 -1
  48. data/lib/plurimath/math/function/dot.rb +0 -1
  49. data/lib/plurimath/math/function/exp.rb +0 -1
  50. data/lib/plurimath/math/function/fenced.rb +1 -197
  51. data/lib/plurimath/math/function/floor.rb +0 -1
  52. data/lib/plurimath/math/function/font_style/bold-fraktur.rb +0 -1
  53. data/lib/plurimath/math/function/font_style/bold-italic.rb +0 -1
  54. data/lib/plurimath/math/function/font_style/bold-sans-serif.rb +0 -1
  55. data/lib/plurimath/math/function/font_style/bold-script.rb +0 -1
  56. data/lib/plurimath/math/function/font_style/bold.rb +0 -1
  57. data/lib/plurimath/math/function/font_style/double_struck.rb +0 -1
  58. data/lib/plurimath/math/function/font_style/fraktur.rb +0 -1
  59. data/lib/plurimath/math/function/font_style/italic.rb +0 -1
  60. data/lib/plurimath/math/function/font_style/monospace.rb +0 -1
  61. data/lib/plurimath/math/function/font_style/normal.rb +0 -1
  62. data/lib/plurimath/math/function/font_style/sans-serif-bold-italic.rb +0 -1
  63. data/lib/plurimath/math/function/font_style/sans-serif-italic.rb +0 -1
  64. data/lib/plurimath/math/function/font_style/sans-serif.rb +0 -1
  65. data/lib/plurimath/math/function/font_style/script.rb +0 -1
  66. data/lib/plurimath/math/function/font_style.rb +29 -2
  67. data/lib/plurimath/math/function/frac.rb +0 -3
  68. data/lib/plurimath/math/function/gcd.rb +0 -1
  69. data/lib/plurimath/math/function/glb.rb +0 -1
  70. data/lib/plurimath/math/function/hat.rb +0 -1
  71. data/lib/plurimath/math/function/hom.rb +0 -1
  72. data/lib/plurimath/math/function/inf.rb +1 -2
  73. data/lib/plurimath/math/function/int.rb +2 -3
  74. data/lib/plurimath/math/function/intent.rb +0 -1
  75. data/lib/plurimath/math/function/ker.rb +0 -1
  76. data/lib/plurimath/math/function/lcm.rb +0 -1
  77. data/lib/plurimath/math/function/left.rb +0 -1
  78. data/lib/plurimath/math/function/lg.rb +0 -1
  79. data/lib/plurimath/math/function/lim.rb +1 -2
  80. data/lib/plurimath/math/function/liminf.rb +0 -1
  81. data/lib/plurimath/math/function/limits.rb +0 -1
  82. data/lib/plurimath/math/function/limsup.rb +0 -1
  83. data/lib/plurimath/math/function/linebreak.rb +0 -1
  84. data/lib/plurimath/math/function/ln.rb +0 -1
  85. data/lib/plurimath/math/function/log.rb +1 -2
  86. data/lib/plurimath/math/function/longdiv.rb +0 -3
  87. data/lib/plurimath/math/function/lub.rb +0 -1
  88. data/lib/plurimath/math/function/max.rb +0 -1
  89. data/lib/plurimath/math/function/mbox.rb +0 -1
  90. data/lib/plurimath/math/function/menclose.rb +0 -3
  91. data/lib/plurimath/math/function/merror.rb +0 -3
  92. data/lib/plurimath/math/function/mglyph.rb +0 -3
  93. data/lib/plurimath/math/function/min.rb +0 -1
  94. data/lib/plurimath/math/function/mlabeledtr.rb +0 -20
  95. data/lib/plurimath/math/function/mod.rb +0 -1
  96. data/lib/plurimath/math/function/mpadded.rb +0 -3
  97. data/lib/plurimath/math/function/ms.rb +1 -77
  98. data/lib/plurimath/math/function/msgroup.rb +0 -27
  99. data/lib/plurimath/math/function/msline.rb +0 -3
  100. data/lib/plurimath/math/function/multiscript.rb +0 -14
  101. data/lib/plurimath/math/function/nary.rb +4 -0
  102. data/lib/plurimath/math/function/none.rb +1 -4
  103. data/lib/plurimath/math/function/norm.rb +0 -1
  104. data/lib/plurimath/math/function/obrace.rb +0 -1
  105. data/lib/plurimath/math/function/oint.rb +2 -3
  106. data/lib/plurimath/math/function/over.rb +0 -3
  107. data/lib/plurimath/math/function/overset.rb +3 -3
  108. data/lib/plurimath/math/function/phantom.rb +0 -3
  109. data/lib/plurimath/math/function/power.rb +0 -3
  110. data/lib/plurimath/math/function/power_base.rb +0 -3
  111. data/lib/plurimath/math/function/prod.rb +2 -3
  112. data/lib/plurimath/math/function/right.rb +0 -1
  113. data/lib/plurimath/math/function/root.rb +0 -3
  114. data/lib/plurimath/math/function/rule.rb +0 -1
  115. data/lib/plurimath/math/function/scarries.rb +0 -3
  116. data/lib/plurimath/math/function/scarry.rb +22 -0
  117. data/lib/plurimath/math/function/sec.rb +0 -1
  118. data/lib/plurimath/math/function/sech.rb +0 -1
  119. data/lib/plurimath/math/function/semantics.rb +0 -15
  120. data/lib/plurimath/math/function/sin.rb +0 -1
  121. data/lib/plurimath/math/function/sinh.rb +0 -1
  122. data/lib/plurimath/math/function/sqrt.rb +0 -3
  123. data/lib/plurimath/math/function/stackrel.rb +0 -3
  124. data/lib/plurimath/math/function/substack.rb +0 -1
  125. data/lib/plurimath/math/function/sum.rb +2 -3
  126. data/lib/plurimath/math/function/sup.rb +0 -1
  127. data/lib/plurimath/math/function/table/align.rb +0 -1
  128. data/lib/plurimath/math/function/table/array.rb +0 -1
  129. data/lib/plurimath/math/function/table/bmatrix.rb +0 -1
  130. data/lib/plurimath/math/function/table/cases.rb +0 -1
  131. data/lib/plurimath/math/function/table/eqarray.rb +0 -1
  132. data/lib/plurimath/math/function/table/matrix.rb +0 -1
  133. data/lib/plurimath/math/function/table/multline.rb +0 -1
  134. data/lib/plurimath/math/function/table/pmatrix.rb +0 -1
  135. data/lib/plurimath/math/function/table/split.rb +0 -1
  136. data/lib/plurimath/math/function/table/vmatrix.rb +0 -1
  137. data/lib/plurimath/math/function/table.rb +10 -23
  138. data/lib/plurimath/math/function/tan.rb +0 -1
  139. data/lib/plurimath/math/function/tanh.rb +0 -1
  140. data/lib/plurimath/math/function/td.rb +0 -4
  141. data/lib/plurimath/math/function/ternary_function.rb +6 -2
  142. data/lib/plurimath/math/function/text.rb +1 -6
  143. data/lib/plurimath/math/function/tilde.rb +4 -1
  144. data/lib/plurimath/math/function/tr.rb +0 -13
  145. data/lib/plurimath/math/function/ubrace.rb +0 -1
  146. data/lib/plurimath/math/function/ul.rb +4 -1
  147. data/lib/plurimath/math/function/underover.rb +0 -3
  148. data/lib/plurimath/math/function/underset.rb +22 -45
  149. data/lib/plurimath/math/function/unitsml.rb +2 -1
  150. data/lib/plurimath/math/function/vec.rb +4 -1
  151. data/lib/plurimath/math/function.rb +107 -10
  152. data/lib/plurimath/math/number.rb +9 -7
  153. data/lib/plurimath/math/symbols/comma.rb +1 -1
  154. data/lib/plurimath/math/symbols/plus.rb +1 -1
  155. data/lib/plurimath/math/symbols/symbol.rb +17 -4
  156. data/lib/plurimath/math.rb +8 -26
  157. data/lib/plurimath/mathml/constants.rb +1 -0
  158. data/lib/plurimath/mathml/formula_transformation.rb +442 -0
  159. data/lib/plurimath/mathml/parser.rb +11 -50
  160. data/lib/plurimath/mathml/translator.rb +584 -0
  161. data/lib/plurimath/mathml/utility/formula_transformation.rb +2 -341
  162. data/lib/plurimath/mathml.rb +5 -0
  163. data/lib/plurimath/number_formatter.rb +2 -1
  164. data/lib/plurimath/omml/parser.rb +10 -7
  165. data/lib/plurimath/omml/transform.rb +17 -5
  166. data/lib/plurimath/omml.rb +3 -0
  167. data/lib/plurimath/setup/opal.rb.erb +3 -4
  168. data/lib/plurimath/unicode_math/parse.rb +0 -5
  169. data/lib/plurimath/unicode_math/parser.rb +1 -6
  170. data/lib/plurimath/unicode_math/parsing_rules/absence_rules.rb +0 -1
  171. data/lib/plurimath/unicode_math/parsing_rules/common_rules.rb +0 -1
  172. data/lib/plurimath/unicode_math/parsing_rules/constants_rules.rb +0 -1
  173. data/lib/plurimath/unicode_math/parsing_rules/masked.rb +0 -1
  174. data/lib/plurimath/unicode_math/parsing_rules/sub_sup.rb +0 -1
  175. data/lib/plurimath/unicode_math/parsing_rules.rb +14 -0
  176. data/lib/plurimath/unicode_math.rb +6 -0
  177. data/lib/plurimath/utility.rb +1 -1
  178. data/lib/plurimath/version.rb +1 -1
  179. data/lib/plurimath/xml_engine/oga.rb +6 -6
  180. data/lib/plurimath/xml_engine/ox_engine.rb +2 -2
  181. data/lib/plurimath/xml_engine.rb +2 -0
  182. data/lib/plurimath.rb +43 -18
  183. data/plurimath.gemspec +5 -4
  184. metadata +33 -15
  185. data/lib/plurimath/mathml/utility/empty_defined_methods.rb +0 -483
  186. data/lib/plurimath/mathml/utility.rb +0 -369
@@ -4,29 +4,8 @@ module Plurimath
4
4
  class Mathml
5
5
  module Utility
6
6
  module FormulaTransformation
7
- CONDITIONAL_COMMON_UNARY_FUNCTIONS = %w[
8
- scarries
9
- phantom
10
- mpadded
11
- merror
12
- ].freeze
13
-
14
7
  private
15
8
 
16
- def update_temp(value)
17
- @temp_mathml_order = Array(value)
18
- end
19
-
20
- def update_temp_order(value, order_name)
21
- update_temp(
22
- replace_order_with_value(
23
- Array(@temp_mathml_order),
24
- Array(update_temp_mathml_values(value)),
25
- order_name,
26
- ),
27
- )
28
- end
29
-
30
9
  def filter_values(value, array_to_instance: false, replacing_order: true)
31
10
  return value unless value.is_a?(Array)
32
11
  return array_to_instance ? nil : value if value.empty?
@@ -39,7 +18,7 @@ module Plurimath
39
18
  if array_to_instance
40
19
  filter_values(value.first.value, array_to_instance: true)
41
20
  else
42
- value.first.value
21
+ value.first
43
22
  end
44
23
  elsif value.is_a?(Array) && value.any?(Math::Formula::Mrow)
45
24
  value.each_with_index do |element, index|
@@ -116,11 +95,7 @@ module Plurimath
116
95
  value.each_with_index do |val, index|
117
96
  next unless val.is_a?(Math::Symbols::Symbol)
118
97
 
119
- if val.temp_mathml_order&.any?
120
- update_symbol(val, value, index)
121
- else
122
- value[index] = mathml_symbol_to_class(val.value)
123
- end
98
+ value[index] = mathml_symbol_to_class(val.value) unless val.value.nil?
124
99
  end
125
100
  value
126
101
  end
@@ -132,74 +107,6 @@ module Plurimath
132
107
  )
133
108
  end
134
109
 
135
- def replace_order_with_value(order, value, tag_name)
136
- value_index = 0
137
- value_array = Array(value)
138
-
139
- order.each_with_object([]) do |item, result|
140
- next result << item if item != tag_name
141
- next if value_index >= value_array.length
142
-
143
- result << value_array[value_index]
144
- value_index += 1
145
- end
146
- end
147
-
148
- def update_temp_mathml_values(value)
149
- value.each_with_index do |element, index|
150
- next unless element.respond_to?(:temp_mathml_order)
151
-
152
- if element.symbol? && element.temp_mathml_order&.none?
153
- value[index] = validate_symbols(element)
154
- end
155
-
156
- next unless element.temp_mathml_order&.any?
157
-
158
- if element.is_ternary_function?
159
- if element.is_a?(Math::Function::Multiscript)
160
- multi = multiscript(element.clear_temp_order)
161
- element.parameter_one = multi[0]
162
- element.parameter_two = filter_values(Array(multi[1])[0])
163
- element.parameter_three = filter_values(Array(multi[1])[1])
164
- elsif first_element_is_ternary_function?(element)
165
- new_element = ternary_element_from(element.temp_mathml_order)
166
- new_element.parameter_one = filter_values(
167
- Array(element.temp_mathml_order.shift),
168
- array_to_instance: true,
169
- )
170
- new_element.parameter_two = filter_values(
171
- Array(element.temp_mathml_order.shift),
172
- array_to_instance: true,
173
- )
174
- value[index] = new_element
175
- elsif first_element_is_binary_function?(element)
176
- new_element = element.temp_mathml_order.shift
177
- new_element.parameter_one = element.temp_mathml_order.shift
178
- new_element.parameter_two = element.temp_mathml_order.shift
179
- value[index] = new_element
180
- elsif element.is_a?(Math::Function::PowerBase)
181
- update_power_base_value(element)
182
- else
183
- element.parameter_one = element.temp_mathml_order.shift
184
- element.parameter_two = element.temp_mathml_order.shift
185
- element.parameter_three = element.temp_mathml_order.shift
186
- end
187
- elsif element.is_binary_function?
188
- update_binary_function_value(element, value, index)
189
- elsif element.is_unary?
190
- element.parameter_one = update_unary_function(element)
191
- elsif element.symbol? && symbol_updatable?(element)
192
- update_symbol(element, value, index)
193
- end
194
- end
195
- value
196
- end
197
-
198
- def validated_order(order, rejectable_array: nil)
199
- rejectable_array ||= ["comment", "text"]
200
- order.reject { |str| rejectable_array.include?(str) }
201
- end
202
-
203
110
  def value_is_ternary_or_nary?(value)
204
111
  return if value.any?(String)
205
112
 
@@ -209,74 +116,6 @@ module Plurimath
209
116
  (!value.first.parameter_one.nil? || !value.first.parameter_two.nil?)
210
117
  end
211
118
 
212
- def first_element_is_ternary_function?(element)
213
- (
214
- element.temp_mathml_order.first&.is_ternary_function? &&
215
- !(
216
- element.temp_mathml_order.first.is_a?(Math::Function::FontStyle) ||
217
- element.temp_mathml_order.first.is_a?(Math::Function::Fenced)
218
- )
219
- ) ||
220
- ternary_filtered_function?(element)
221
- end
222
-
223
- def first_element_is_binary_function?(element)
224
- (
225
- element.temp_mathml_order.first&.is_binary_function? &&
226
- !element.temp_mathml_order.first.is_a?(Math::Function::FontStyle)
227
- ) ||
228
- binary_filtered_function?(element)
229
- end
230
-
231
- def binary_filtered_function?(element)
232
- new_element = filter_values(
233
- [element.temp_mathml_order.first],
234
- array_to_instance: true,
235
- )
236
- new_element&.is_binary_function? && !new_element.all_values_exist?
237
- end
238
-
239
- def ternary_filtered_function?(element)
240
- new_element = filter_values(
241
- [element.temp_mathml_order.first],
242
- array_to_instance: true,
243
- )
244
- new_element&.is_ternary_function? &&
245
- !new_element.all_values_exist?
246
- end
247
-
248
- def ternary_element_from(order)
249
- element = order.shift
250
- return element if element.is_ternary_function?
251
-
252
- filter_values([element], array_to_instance: true)
253
- end
254
-
255
- def period_to_dot(element, value, index)
256
- return element unless element.is_a?(Math::Symbols::Period)
257
-
258
- value[index] = Math::Function::Dot.new
259
- end
260
-
261
- def multiscript(value)
262
- value.slice_before("mprescripts").map do |val|
263
- base_value = val.shift
264
- val = Plurimath::Utility.nil_to_none_object(val)
265
- part_val = val.partition.with_index { |_, i| i.even? }
266
- first_value = part_val[0].empty? ? nil : part_val[0]
267
- second_value = part_val[1].empty? ? nil : part_val[1]
268
- if base_value.to_s.include?("mprescripts")
269
- [first_value, second_value]
270
- else
271
- Math::Function::PowerBase.new(
272
- filter_values(base_value, array_to_instance: true),
273
- filter_values(first_value, array_to_instance: true),
274
- filter_values(second_value, array_to_instance: true),
275
- )
276
- end
277
- end
278
- end
279
-
280
119
  def ternary_naryable?(value)
281
120
  value.length == 2 &&
282
121
  value.first.is_a?(Math::Function::PowerBase) &&
@@ -294,184 +133,6 @@ module Plurimath
294
133
  value.first.is_a?(Math::Function::Power) &&
295
134
  value.first.parameter_one.is_nary_symbol?
296
135
  end
297
-
298
- def update_power_base_value(element)
299
- element.parameter_one = filter_values(
300
- Array(element.temp_mathml_order.shift),
301
- array_to_instance: true,
302
- )
303
- element.parameter_two = filter_values(
304
- Array(element.temp_mathml_order.shift),
305
- array_to_instance: true,
306
- )
307
- return unless element.is_a?(Math::Function::PowerBase)
308
-
309
- element.parameter_three = filter_values(
310
- Array(element.temp_mathml_order.shift),
311
- array_to_instance: true,
312
- )
313
- end
314
-
315
- def update_overset_value(element, value, index)
316
- case element.temp_mathml_order[1].class_name
317
- when "obrace", "ubrace"
318
- new_element = element.temp_mathml_order.pop
319
- new_element.parameter_one = element.temp_mathml_order.shift
320
- when "hat", "ddot"
321
- new_element = element.temp_mathml_order.pop
322
- new_element.parameter_one = filter_values(
323
- Array(element.temp_mathml_order.shift),
324
- array_to_instance: true,
325
- )
326
- return unless element.respond_to?(:options)
327
-
328
- new_element.attributes = element.options
329
- when "period", "dot"
330
- new_element = period_to_dot(
331
- element.temp_mathml_order.pop,
332
- value,
333
- index,
334
- )
335
- new_element.parameter_one = filter_values(
336
- Array(element.temp_mathml_order.shift),
337
- array_to_instance: true,
338
- )
339
- new_element.attributes = element.options
340
- when "bar"
341
- new_element = element.temp_mathml_order.pop
342
- new_element.parameter_one = element.temp_mathml_order.shift
343
- when "vec"
344
- new_element = element.temp_mathml_order.pop
345
- new_element.parameter_one = filter_values(
346
- Array(element.temp_mathml_order.shift),
347
- array_to_instance: true,
348
- )
349
- new_element.attributes = element.options
350
- when "ul", "underline"
351
- element.temp_mathml_order.pop
352
- new_element = Math::Function::Bar.new(
353
- filter_values(
354
- element.clear_temp_order,
355
- array_to_instance: true,
356
- ),
357
- element.options,
358
- )
359
- when "tilde"
360
- new_element = element.temp_mathml_order.pop
361
- new_element.parameter_one = filter_values(
362
- element.clear_temp_order,
363
- array_to_instance: true,
364
- )
365
- new_element.attributes = element.options
366
- else
367
- element.parameter_two = element.temp_mathml_order.shift
368
- element.parameter_one = element.temp_mathml_order.shift
369
- end
370
- value[index] = new_element if new_element
371
- end
372
-
373
- def update_underset_value(element, value, index)
374
- return if update_underset_first_temp_element(element, value, index)
375
-
376
- case element.temp_mathml_order[1]&.class_name
377
- when "obrace", "ubrace", "ul", "underline"
378
- new_element = element.temp_mathml_order.pop
379
- new_element.parameter_one = element.temp_mathml_order.shift
380
- when "bar"
381
- element.temp_mathml_order.pop
382
- new_element = Math::Function::Ul.new(
383
- filter_values(
384
- element.clear_temp_order,
385
- array_to_instance: true,
386
- ),
387
- element.options,
388
- )
389
- else
390
- element.parameter_two = element.temp_mathml_order.shift
391
- element.parameter_one = element.temp_mathml_order.shift
392
- end
393
- value[index] = new_element if new_element
394
- end
395
-
396
- def update_underset_first_temp_element(element, value, index)
397
- case element.temp_mathml_order[0]
398
- when Math::Function::Vec,
399
- ->(block_element) { updatable_ternary_function?(block_element) }
400
- new_element = element.temp_mathml_order.shift
401
- new_element.parameter_one = element.temp_mathml_order.shift
402
- value[index] = new_element
403
- return unless new_element.is_a?(Math::Function::Vec)
404
-
405
- new_element.attributes = element.options
406
- end
407
- end
408
-
409
- def updatable_ternary_function?(element)
410
- element.is_ternary_function? && !element.any_value_exist?
411
- end
412
-
413
- def update_binary_function_value(element, value, index)
414
- case element
415
- when Math::Function::Semantics, Math::Function::Stackrel
416
- element.parameter_one = filter_values(
417
- Array(element.clear_temp_order),
418
- array_to_instance: true,
419
- )
420
- when Math::Function::Overset
421
- update_overset_value(element, value, index)
422
- when Math::Function::Underset
423
- update_underset_value(element, value, index)
424
- when Math::Function::Power, Math::Function::Base
425
- update_power_base_value(element)
426
- when Math::Function::Td
427
- element.parameter_one = element.clear_temp_order
428
- when Math::Function::Root
429
- element.parameter_two = element.temp_mathml_order.shift
430
- element.parameter_one = element.temp_mathml_order.shift
431
- when Math::Function::Menclose
432
- element.parameter_two = filter_values(
433
- Array(element.clear_temp_order),
434
- array_to_instance: true,
435
- )
436
- else
437
- element.parameter_one = element.temp_mathml_order.shift
438
- element.parameter_two = element.temp_mathml_order.shift
439
- end
440
- end
441
-
442
- def update_unary_function(element)
443
- case element.class_name
444
- when *CONDITIONAL_COMMON_UNARY_FUNCTIONS
445
- filter_values(
446
- element.clear_temp_order,
447
- array_to_instance: true,
448
- )
449
- when "sqrt"
450
- element.temp_mathml_order.shift
451
- else
452
- element.clear_temp_order
453
- end
454
- end
455
-
456
- def symbol_updatable?(element)
457
- temp_element = element.temp_mathml_order.first
458
- return false unless temp_element
459
-
460
- temp_element.is_a?(Math::Function::FontStyle) ||
461
- temp_element.is_a?(Math::Function::Linebreak)
462
- end
463
-
464
- def update_symbol(element, value, index)
465
- new_element = element.temp_mathml_order.shift
466
- case new_element
467
- when Math::Function::FontStyle
468
- new_element.parameter_one = validate_symbols(element)
469
- value[index] = new_element
470
- when Math::Function::Linebreak
471
- new_element.parameter_one = validate_symbols(element)
472
- value[index] = new_element
473
- end
474
- end
475
136
  end
476
137
  end
477
138
  end
@@ -2,6 +2,11 @@
2
2
 
3
3
  module Plurimath
4
4
  class Mathml
5
+ autoload :Constants, "#{__dir__}/mathml/constants"
6
+ autoload :FormulaTransformation, "#{__dir__}/mathml/formula_transformation"
7
+ autoload :Parser, "#{__dir__}/mathml/parser"
8
+ autoload :Translator, "#{__dir__}/mathml/translator"
9
+
5
10
  attr_accessor :text
6
11
 
7
12
  def initialize(text)
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bigdecimal"
2
- require_relative "formatter"
3
4
 
4
5
  module Plurimath
5
6
  class NumberFormatter
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "transform"
4
3
  module Plurimath
5
4
  class Omml
6
5
  class Parser
@@ -51,12 +50,16 @@ module Plurimath
51
50
  if node.is_a?(String)
52
51
  node == "​" ? nil : node
53
52
  elsif !node.attributes.empty?
54
- {
55
- node.name => {
56
- attributes: node.attributes,
57
- value: parse_nodes(node.nodes),
58
- },
59
- }
53
+ if node.attributes.key?("val")
54
+ { node.name => node.attributes["val"] }
55
+ else
56
+ {
57
+ node.name => {
58
+ attributes: node.attributes,
59
+ value: parse_nodes(node.nodes),
60
+ },
61
+ }
62
+ end
60
63
  else
61
64
  customize_tags(node) if CUSTOMIZABLE_TAGS.include?(node.name)
62
65
  { node.name => parse_nodes(node.nodes) }
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parslet"
4
3
  module Plurimath
5
4
  class Omml
6
5
  class Transform < Parslet::Transform
@@ -110,8 +109,10 @@ module Plurimath
110
109
 
111
110
  rule(dPr: subtree(:dpr)) do
112
111
  flatten_dpr = dpr.flatten.compact
113
- open_paren = Utility.string_to_html_entity(flatten_dpr.find { |hash| hash[:begChr] }&.values&.first)
114
- close_paren = Utility.string_to_html_entity(flatten_dpr.find { |hash| hash[:endChr] }&.values&.first)
112
+ beg_entry = flatten_dpr.find { |hash| hash[:begChr] }
113
+ end_entry = flatten_dpr.find { |hash| hash[:endChr] }
114
+ open_paren = Utility.string_to_html_entity(beg_entry ? beg_entry.values.first : "(")
115
+ close_paren = Utility.string_to_html_entity(end_entry ? end_entry.values.first : ")")
115
116
  sep_chr = flatten_dpr.find { |hash| hash[:sepChr] }
116
117
  open_paren_object = Utility.symbol_object(open_paren, lang: :omml) if open_paren && !open_paren.empty?
117
118
  close_paren_object = Utility.symbol_object(close_paren, lang: :omml) if close_paren && !close_paren.empty?
@@ -166,8 +167,17 @@ module Plurimath
166
167
  index = acc_value.index { |d| d[:chr] }
167
168
  acc_value[index] = chr_value
168
169
  Utility.unary_function_classes(acc_value, lang: :omml)
169
- acc_value.first.attributes = { accent: true }
170
- acc_value.first
170
+ first = acc_value.first
171
+ if first.is_a?(Math::Function::UnaryFunction)
172
+ first.attributes = { accent: true }
173
+ first
174
+ else
175
+ # chr resolved to a Symbol, wrap in Overset
176
+ Math::Function::Overset.new(
177
+ acc_value.last,
178
+ first,
179
+ )
180
+ end
171
181
  end
172
182
 
173
183
  rule(func: subtree(:func)) do
@@ -265,6 +275,8 @@ module Plurimath
265
275
  function_class.parameter_one = Utility.filter_values(lim.flatten.compact)
266
276
  function_class
267
277
  else
278
+ # OMML is parsed back into Overset's source argument order so the
279
+ # internal model stays format-neutral across conversion paths.
268
280
  Math::Function::Overset.new(
269
281
  first_value,
270
282
  lim_values[1],
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Plurimath
4
4
  class Omml
5
+ autoload :Parser, "#{__dir__}/omml/parser"
6
+ autoload :Transform, "#{__dir__}/omml/transform"
7
+
5
8
  attr_accessor :text
6
9
 
7
10
  def initialize(text)
@@ -1,12 +1,11 @@
1
+ # Preload Math namespace/core so symbol classes resolve correctly in Opal.
2
+ require 'plurimath/math'
1
3
  require 'plurimath/math/core'
2
- require 'plurimath/math/function'
3
4
  require 'plurimath/math/symbols/symbol'
4
5
  require 'plurimath/math/symbols/paren'
5
6
 
6
7
  <% (
7
- Dir[File.dirname(__dir__)+"/math/function/*.rb"] +
8
- Dir[File.dirname(__dir__)+"/math/function/**/*.rb"] +
9
8
  Dir[File.dirname(__dir__)+"/math/symbols/**/*.rb"]
10
- ).each do |f| %>
9
+ ).uniq.each do |f| %>
11
10
  require 'plurimath/<%= f.split("lib/plurimath").last.gsub(/.rb$/,'') %>'
12
11
  <% end %>
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "parsing_rules/masked"
4
- require_relative "parsing_rules/sub_sup"
5
- require_relative "parsing_rules/common_rules"
6
- require_relative "parsing_rules/absence_rules"
7
- require_relative "parsing_rules/constants_rules"
8
3
  module Plurimath
9
4
  class UnicodeMath
10
5
  class Parse < Parslet::Parser
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parslet"
4
- require "parslet/convenience"
5
- require_relative "parse"
6
- require_relative "transform"
7
- require_relative "constants"
8
3
  module Plurimath
9
4
  class UnicodeMath
10
5
  class Parser
@@ -14,7 +9,7 @@ module Plurimath
14
9
 
15
10
  def initialize(text)
16
11
  text = pre_processing(text)
17
- @text = HTMLEntities.new.encode(text, :hexadecimal)
12
+ @text = ::HTMLEntities.new.encode(text, :hexadecimal)
18
13
  @text = @text.gsub("&#x26;", "&")
19
14
  @text = @text.gsub("&#x22;", "\"")
20
15
  @text = @text.gsub(/&#x2af7;.*&#x2af8;/, "")
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
4
3
  module Plurimath
5
4
  class UnicodeMath
6
5
  module ParsingRules
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
4
3
  module Plurimath
5
4
  class UnicodeMath
6
5
  module ParsingRules
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
4
3
  module Plurimath
5
4
  class UnicodeMath
6
5
  module ParsingRules
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
4
3
  module Plurimath
5
4
  class UnicodeMath
6
5
  module ParsingRules
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "helper"
4
3
  module Plurimath
5
4
  class UnicodeMath
6
5
  module ParsingRules
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class UnicodeMath
5
+ module ParsingRules
6
+ autoload :AbsenceRules, "#{__dir__}/parsing_rules/absence_rules"
7
+ autoload :CommonRules, "#{__dir__}/parsing_rules/common_rules"
8
+ autoload :ConstantsRules, "#{__dir__}/parsing_rules/constants_rules"
9
+ autoload :Helper, "#{__dir__}/parsing_rules/helper"
10
+ autoload :Masked, "#{__dir__}/parsing_rules/masked"
11
+ autoload :SubSup, "#{__dir__}/parsing_rules/sub_sup"
12
+ end
13
+ end
14
+ end
@@ -2,6 +2,12 @@
2
2
 
3
3
  module Plurimath
4
4
  class UnicodeMath
5
+ autoload :Constants, "#{__dir__}/unicode_math/constants"
6
+ autoload :Parse, "#{__dir__}/unicode_math/parse"
7
+ autoload :Parser, "#{__dir__}/unicode_math/parser"
8
+ autoload :ParsingRules, "#{__dir__}/unicode_math/parsing_rules"
9
+ autoload :Transform, "#{__dir__}/unicode_math/transform"
10
+
5
11
  attr_accessor :text
6
12
 
7
13
  def initialize(text)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "utility/intent_encoding"
4
3
  module Plurimath
5
4
  class Utility
5
+ autoload :IntentEncoding, "#{__dir__}/utility/intent_encoding"
6
6
  UNICODE_REGEX = %r{&#x[a-zA-Z0-9]+;}
7
7
  FONT_STYLES = {
8
8
  "double-struck": Math::Function::FontStyle::DoubleStruck,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.10.0"
4
+ VERSION = "0.10.2"
5
5
  end
@@ -1,13 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "plurimath/xml_engine"
4
3
  require "corelib/array/pack" if RUBY_ENGINE == "opal"
5
4
  require "oga"
6
- require_relative "oga/document"
7
- require_relative "oga/wrapper"
8
- require_relative "oga/element"
9
- require_relative "oga/dumper"
10
- require_relative "oga/node"
11
5
 
12
6
  module Plurimath
13
7
  module XmlEngine
@@ -40,6 +34,12 @@ module Plurimath
40
34
  root
41
35
  end
42
36
  end
37
+
38
+ autoload :Document, "#{__dir__}/oga/document"
39
+ autoload :Wrapper, "#{__dir__}/oga/wrapper"
40
+ autoload :Element, "#{__dir__}/oga/element"
41
+ autoload :Dumper, "#{__dir__}/oga/dumper"
42
+ autoload :Node, "#{__dir__}/oga/node"
43
43
  end
44
44
  end
45
45
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "plurimath/xml_engine"
4
- require "plurimath/xml_engine/ox_engine/element"
5
3
  require "ox"
6
4
  Ox.default_options = { encoding: "UTF-8" }
7
5
 
@@ -34,6 +32,8 @@ module Plurimath
34
32
  root
35
33
  end
36
34
  end
35
+
36
+ autoload :Element, "#{__dir__}/ox_engine/element"
37
37
  end
38
38
  end
39
39
  end