plurimath 0.4.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rspec +3 -0
  4. data/.rspec-opal +11 -0
  5. data/Gemfile +3 -0
  6. data/Rakefile +11 -0
  7. data/lib/plurimath/asciimath/transform.rb +15 -0
  8. data/lib/plurimath/latex/constants.rb +3 -0
  9. data/lib/plurimath/latex/parse.rb +20 -11
  10. data/lib/plurimath/latex/transform.rb +24 -2
  11. data/lib/plurimath/math/core.rb +88 -0
  12. data/lib/plurimath/math/formula.rb +68 -24
  13. data/lib/plurimath/math/function/base.rb +8 -2
  14. data/lib/plurimath/math/function/binary_function.rb +36 -4
  15. data/lib/plurimath/math/function/color.rb +14 -0
  16. data/lib/plurimath/math/function/fenced.rb +27 -0
  17. data/lib/plurimath/math/function/floor.rb +1 -1
  18. data/lib/plurimath/math/function/font_style.rb +46 -0
  19. data/lib/plurimath/math/function/frac.rb +6 -0
  20. data/lib/plurimath/math/function/int.rb +7 -0
  21. data/lib/plurimath/math/function/left.rb +19 -1
  22. data/lib/plurimath/math/function/lim.rb +6 -0
  23. data/lib/plurimath/math/function/limits.rb +7 -0
  24. data/lib/plurimath/math/function/log.rb +6 -0
  25. data/lib/plurimath/math/function/menclose.rb +6 -0
  26. data/lib/plurimath/math/function/mod.rb +6 -0
  27. data/lib/plurimath/math/function/msgroup.rb +28 -0
  28. data/lib/plurimath/math/function/multiscript.rb +7 -0
  29. data/lib/plurimath/math/function/nary.rb +94 -0
  30. data/lib/plurimath/math/function/oint.rb +6 -0
  31. data/lib/plurimath/math/function/over.rb +6 -0
  32. data/lib/plurimath/math/function/overset.rb +6 -0
  33. data/lib/plurimath/math/function/power.rb +8 -2
  34. data/lib/plurimath/math/function/power_base.rb +10 -31
  35. data/lib/plurimath/math/function/prod.rb +19 -18
  36. data/lib/plurimath/math/function/right.rb +19 -1
  37. data/lib/plurimath/math/function/root.rb +6 -0
  38. data/lib/plurimath/math/function/rule.rb +7 -0
  39. data/lib/plurimath/math/function/semantics.rb +6 -0
  40. data/lib/plurimath/math/function/stackrel.rb +6 -0
  41. data/lib/plurimath/math/function/substack.rb +6 -0
  42. data/lib/plurimath/math/function/sum.rb +26 -25
  43. data/lib/plurimath/math/function/table.rb +52 -24
  44. data/lib/plurimath/math/function/td.rb +28 -0
  45. data/lib/plurimath/math/function/ternary_function.rb +44 -4
  46. data/lib/plurimath/math/function/text.rb +25 -3
  47. data/lib/plurimath/math/function/tr.rb +28 -0
  48. data/lib/plurimath/math/function/unary_function.rb +43 -3
  49. data/lib/plurimath/math/function/underover.rb +7 -55
  50. data/lib/plurimath/math/function/underset.rb +6 -0
  51. data/lib/plurimath/math/function/vec.rb +40 -0
  52. data/lib/plurimath/math/function.rb +7 -5
  53. data/lib/plurimath/math/number.rb +9 -5
  54. data/lib/plurimath/math/symbol.rb +13 -9
  55. data/lib/plurimath/math.rb +1 -3
  56. data/lib/plurimath/mathml/parser.rb +4 -4
  57. data/lib/plurimath/mathml/transform.rb +3 -4
  58. data/lib/plurimath/omml/parser.rb +19 -3
  59. data/lib/plurimath/omml/transform.rb +19 -14
  60. data/lib/plurimath/setup/oga.rb +5 -0
  61. data/lib/plurimath/setup/opal.rb.erb +8 -0
  62. data/lib/plurimath/setup/ox.rb +5 -0
  63. data/lib/plurimath/utility.rb +60 -34
  64. data/lib/plurimath/version.rb +1 -1
  65. data/lib/plurimath/xml_engine/oga.rb +246 -0
  66. data/lib/plurimath/xml_engine/ox.rb +29 -0
  67. data/lib/plurimath/xml_engine.rb +6 -0
  68. data/lib/plurimath.rb +12 -2
  69. metadata +11 -2
@@ -6,6 +6,13 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Sum < TernaryFunction
9
+ FUNCTION = {
10
+ name: "summation",
11
+ first_value: "subscript",
12
+ second_value: "supscript",
13
+ third_value: "term",
14
+ }.freeze
15
+
9
16
  def to_asciimath
10
17
  first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
18
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
@@ -20,32 +27,26 @@ module Plurimath
20
27
 
21
28
  def to_mathml_without_math_tag
22
29
  first_value = Utility.ox_element("mo") << invert_unicode_symbols.to_s
23
- if parameter_one || parameter_two
24
- value_array = []
25
- value_array << parameter_one&.to_mathml_without_math_tag
26
- value_array << parameter_two&.to_mathml_without_math_tag
27
- tag_name = if parameter_two && parameter_one
28
- "underover"
29
- else
30
- parameter_one ? "under" : "over"
31
- end
32
- munderover_tag = Utility.ox_element("m#{tag_name}")
33
- Utility.update_nodes(
34
- munderover_tag,
35
- value_array.insert(0, first_value),
36
- )
37
- return munderover_tag if parameter_three.nil?
30
+ return first_value unless parameter_one || parameter_two
38
31
 
39
- Utility.update_nodes(
40
- Utility.ox_element("mrow"),
41
- [
42
- munderover_tag,
43
- parameter_three&.to_mathml_without_math_tag,
44
- ].flatten.compact,
45
- )
46
- else
47
- first_value
48
- end
32
+ value_array = [parameter_one&.to_mathml_without_math_tag]
33
+ value_array << parameter_two&.to_mathml_without_math_tag
34
+ tag_name = if parameter_two && parameter_one
35
+ "underover"
36
+ else
37
+ parameter_one ? "under" : "over"
38
+ end
39
+ munderover_tag = Utility.ox_element("m#{tag_name}")
40
+ Utility.update_nodes(munderover_tag, value_array.insert(0, first_value))
41
+ return munderover_tag if parameter_three.nil?
42
+
43
+ Utility.update_nodes(
44
+ Utility.ox_element("mrow"),
45
+ [
46
+ munderover_tag,
47
+ parameter_three&.to_mathml_without_math_tag,
48
+ ].flatten.compact,
49
+ )
49
50
  end
50
51
 
51
52
  def to_html
@@ -52,13 +52,11 @@ module Plurimath
52
52
  end
53
53
 
54
54
  def to_latex
55
- if open_paren == "norm["
56
- return "\\begin{Vmatrix}#{latex_content}\\end{Vmatrix}"
57
- end
55
+ return "\\begin{Vmatrix}#{latex_content}\\end{Vmatrix}" if open_paren == "norm["
58
56
 
59
57
  separator = "{#{table_attribute(:latex)}}" if environment&.include?("array")
60
- left_paren = latex_parenthesis(open_paren) || "."
61
- right_paren = latex_parenthesis(close_paren) || "."
58
+ left_paren = latex_parenthesis(open_paren)
59
+ right_paren = latex_parenthesis(close_paren)
62
60
  left = "\\left #{left_paren}\\begin{matrix}"
63
61
  right = "\\end{matrix}\\right #{right_paren}"
64
62
  "#{left}#{separator}#{latex_content}#{right}"
@@ -70,11 +68,40 @@ module Plurimath
70
68
  end
71
69
 
72
70
  def to_omml_without_math_tag(display_style)
73
- if value.map { |d| d.parameter_one.length == 1 }.all?
74
- single_td_table(display_style)
75
- else
76
- fenced_table(multiple_td_table(display_style))
77
- end
71
+ ox_table = if value.map { |d| d.parameter_one.length == 1 }.all?
72
+ single_td_table(display_style)
73
+ else
74
+ multiple_td_table(display_style)
75
+ end
76
+ fenced_table(ox_table)
77
+ end
78
+
79
+ def to_asciimath_math_zone(spacing, last = false, indent = true)
80
+ [
81
+ "#{spacing}\"table\" function apply\n",
82
+ Formula.new(value).to_asciimath_math_zone(gsub_spacing(spacing, last), last, indent),
83
+ ]
84
+ end
85
+
86
+ def to_latex_math_zone(spacing, last = false, indent = true)
87
+ [
88
+ "#{spacing}\"table\" function apply\n",
89
+ Formula.new(value).to_latex_math_zone(gsub_spacing(spacing, last), last, indent),
90
+ ]
91
+ end
92
+
93
+ def to_mathml_math_zone(spacing, last = false, indent = true)
94
+ [
95
+ "#{spacing}\"table\" function apply\n",
96
+ Formula.new(value).to_mathml_math_zone(gsub_spacing(spacing, last), last, indent),
97
+ ]
98
+ end
99
+
100
+ def to_omml_math_zone(spacing, last = false, indent = true, display_style:)
101
+ [
102
+ "#{spacing}\"table\" function apply\n",
103
+ Formula.new(value).to_omml_math_zone(gsub_spacing(spacing, last), last, indent, display_style: display_style),
104
+ ]
78
105
  end
79
106
 
80
107
  protected
@@ -90,6 +117,7 @@ module Plurimath
90
117
  end
91
118
 
92
119
  def latex_parenthesis(field)
120
+ return "." unless field
93
121
  return " ." if field&.include?(":")
94
122
 
95
123
  return "\\#{field}" if ["{", "}"].include?(field)
@@ -215,7 +243,7 @@ module Plurimath
215
243
  end
216
244
 
217
245
  def fenced_table(ox_table)
218
- return ox_table unless open_paren && close_paren
246
+ return ox_table unless open_paren || close_paren
219
247
 
220
248
  d_node = Utility.ox_element("d", namespace: "m")
221
249
  e_node = Utility.ox_element("e", namespace: "m")
@@ -225,22 +253,22 @@ module Plurimath
225
253
  end
226
254
 
227
255
  def mdpr_node
228
- begchr = Utility.ox_element("begChr", namespace: "m")
229
- begchr.attributes["m:val"] = paren(open_paren)
230
- endchr = Utility.ox_element("endChr", namespace: "m")
231
- endchr.attributes["m:val"] = paren(close_paren)
232
256
  sepchr = Utility.ox_element("sepChr", attributes: { "m:val": "" }, namespace: "m")
233
257
  mgrow = Utility.ox_element("grow", namespace: "m")
234
258
  mdpr = Utility.ox_element("dPr", namespace: "m")
235
- Utility.update_nodes(
236
- mdpr,
237
- [
238
- begchr,
239
- endchr,
240
- sepchr,
241
- mgrow,
242
- ],
243
- )
259
+ Utility.update_nodes(mdpr, [begchr, endchr, sepchr, mgrow])
260
+ end
261
+
262
+ def begchr
263
+ return unless open_paren
264
+
265
+ Utility.ox_element("begChr", attributes: { "m:val": paren(open_paren) }, namespace: "m")
266
+ end
267
+
268
+ def endchr
269
+ return unless close_paren
270
+
271
+ Utility.ox_element("endChr", attributes: { "m:val": paren(close_paren) }, namespace: "m")
244
272
  end
245
273
 
246
274
  def paren(parenthesis)
@@ -42,6 +42,34 @@ module Plurimath
42
42
  )
43
43
  [me]
44
44
  end
45
+
46
+ def to_asciimath_math_zone(spacing, last = false, _)
47
+ [
48
+ "#{spacing}\"td\" function apply\n",
49
+ Formula.new(parameter_one).to_asciimath_math_zone(gsub_spacing(spacing, last), last),
50
+ ]
51
+ end
52
+
53
+ def to_latex_math_zone(spacing, last = false, indent = true)
54
+ [
55
+ "#{spacing}\"td\" function apply\n",
56
+ Formula.new(parameter_one).to_latex_math_zone(gsub_spacing(spacing, last), last, indent),
57
+ ]
58
+ end
59
+
60
+ def to_mathml_math_zone(spacing, last = false, indent = true)
61
+ [
62
+ "#{spacing}\"td\" function apply\n",
63
+ Formula.new(parameter_one).to_mathml_math_zone(gsub_spacing(spacing, last), last, indent),
64
+ ]
65
+ end
66
+
67
+ def to_omml_math_zone(spacing, last = false, indent = true, display_style:)
68
+ [
69
+ "#{spacing}\"td\" function apply\n",
70
+ Formula.new(parameter_one).to_omml_math_zone(gsub_spacing(spacing, last), last, indent, display_style: display_style),
71
+ ]
72
+ end
45
73
  end
46
74
  end
47
75
  end
@@ -59,6 +59,50 @@ module Plurimath
59
59
  !(parameter_one.nil? && parameter_two.nil? && parameter_three.nil?)
60
60
  end
61
61
 
62
+ def to_asciimath_math_zone(spacing, last = false, _)
63
+ parameters = self.class::FUNCTION
64
+ new_spacing = gsub_spacing(spacing, last)
65
+ new_arr = ["#{spacing}\"#{to_asciimath}\" #{parameters[:name]}\n"]
66
+ ascii_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr })
67
+ ascii_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr })
68
+ ascii_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr })
69
+ new_arr
70
+ end
71
+
72
+ def to_latex_math_zone(spacing, last = false, _)
73
+ parameters = self.class::FUNCTION
74
+ new_spacing = gsub_spacing(spacing, last)
75
+ new_arr = ["#{spacing}\"#{to_latex}\" #{parameters[:name]}\n"]
76
+ latex_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr })
77
+ latex_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr })
78
+ latex_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr })
79
+ new_arr
80
+ end
81
+
82
+ def to_mathml_math_zone(spacing, last = false, _)
83
+ parameters = self.class::FUNCTION
84
+ new_spacing = gsub_spacing(spacing, last)
85
+ new_arr = ["#{spacing}\"#{dump_mathml(self)}\" #{parameters[:name]}\n"]
86
+ mathml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr })
87
+ mathml_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr })
88
+ mathml_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr })
89
+ new_arr
90
+ end
91
+
92
+ def to_omml_math_zone(spacing, last = false, _, display_style:)
93
+ parameters = self.class::FUNCTION
94
+ new_spacing = gsub_spacing(spacing, last)
95
+ new_arr = ["#{spacing}\"#{dump_omml(self, display_style)}\" #{parameters[:name]}\n"]
96
+ omml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr, display_style: display_style })
97
+ omml_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr, display_style: display_style })
98
+ omml_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr, display_style: display_style })
99
+ new_arr
100
+ end
101
+
102
+ def any_value_exist?
103
+ !(parameter_one.nil? || parameter_two.nil? || parameter_three.nil?)
104
+ end
105
+
62
106
  protected
63
107
 
64
108
  def latex_wrapped(field)
@@ -69,10 +113,6 @@ module Plurimath
69
113
  end
70
114
  end
71
115
 
72
- def invert_unicode_symbols
73
- Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
74
- end
75
-
76
116
  def wrapped(field, type: "ascii")
77
117
  return "" unless field
78
118
 
@@ -15,7 +15,9 @@ module Plurimath
15
15
 
16
16
  def to_mathml_without_math_tag
17
17
  text = Utility.ox_element("mtext")
18
- text << (parse_text("mathml") || parameter_one) if parameter_one
18
+ return text unless parameter_one
19
+
20
+ text << (parse_text("mathml") || parameter_one)
19
21
  end
20
22
 
21
23
  def to_latex
@@ -43,6 +45,26 @@ module Plurimath
43
45
  false
44
46
  end
45
47
 
48
+ def to_asciimath_math_zone(spacing, _, _)
49
+ "#{spacing}#{to_asciimath} text\n"
50
+ end
51
+
52
+ def to_latex_math_zone(spacing, _, _)
53
+ "#{spacing}#{to_asciimath} text\n"
54
+ end
55
+
56
+ def to_mathml_math_zone(spacing, _, _)
57
+ "#{spacing}\"#{dump_mathml(self)}\" text\n"
58
+ end
59
+
60
+ def to_omml_math_zone(spacing, _, _, display_style:)
61
+ "#{spacing}\"#{dump_omml(self, display_style)}\" text\n"
62
+ end
63
+
64
+ def value
65
+ parameter_one
66
+ end
67
+
46
68
  protected
47
69
 
48
70
  def symbol_value(unicode)
@@ -52,10 +74,10 @@ module Plurimath
52
74
 
53
75
  def parse_text(lang)
54
76
  html_value = first_value(lang).dup
55
- html_value&.gsub!(PARSER_REGEX) do |_text|
77
+ html_value = html_value&.gsub(PARSER_REGEX) do |_text|
56
78
  last_match = Regexp.last_match
57
79
  case lang
58
- when "mathml", "html"
80
+ when "mathml", "html", "omml"
59
81
  symbol_value(last_match[:unicode])
60
82
  else
61
83
  last_match[:unicode]
@@ -44,6 +44,34 @@ module Plurimath
44
44
  [mr]
45
45
  end
46
46
  end
47
+
48
+ def to_asciimath_math_zone(spacing, last = false, indent = true)
49
+ [
50
+ "#{spacing}\"tr\" function apply\n",
51
+ Formula.new(parameter_one).to_asciimath_math_zone(gsub_spacing(spacing, last), last, indent),
52
+ ]
53
+ end
54
+
55
+ def to_latex_math_zone(spacing, last = false, indent = true)
56
+ [
57
+ "#{spacing}\"tr\" function apply\n",
58
+ Formula.new(parameter_one).to_latex_math_zone(gsub_spacing(spacing, last), last, indent),
59
+ ]
60
+ end
61
+
62
+ def to_mathml_math_zone(spacing, last = false, indent = true)
63
+ [
64
+ "#{spacing}\"tr\" function apply\n",
65
+ Formula.new(parameter_one).to_mathml_math_zone(gsub_spacing(spacing, last), last, indent),
66
+ ]
67
+ end
68
+
69
+ def to_omml_math_zone(spacing, last = false, indent = true, display_style:)
70
+ [
71
+ "#{spacing}\"tr\" function apply\n",
72
+ Formula.new(parameter_one).to_omml_math_zone(gsub_spacing(spacing, last), last, indent, display_style: display_style),
73
+ ]
74
+ end
47
75
  end
48
76
  end
49
77
  end
@@ -75,12 +75,48 @@ module Plurimath
75
75
  [func]
76
76
  end
77
77
 
78
- protected
78
+ def to_asciimath_math_zone(spacing, last = false, _)
79
+ new_spacing = gsub_spacing(spacing, last)
80
+ new_arr = [
81
+ "#{spacing}\"#{to_asciimath}\" function apply\n",
82
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
83
+ ]
84
+ ascii_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ " , array: new_arr })
85
+ new_arr
86
+ end
87
+
88
+ def to_latex_math_zone(spacing, last = false, _)
89
+ new_spacing = gsub_spacing(spacing, last)
90
+ new_arr = [
91
+ "#{spacing}\"#{to_latex}\" function apply\n",
92
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
93
+ ]
94
+ latex_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ " , array: new_arr })
95
+ new_arr
96
+ end
97
+
98
+ def to_mathml_math_zone(spacing, last = false, _)
99
+ new_spacing = gsub_spacing(spacing, last)
100
+ new_arr = [
101
+ "#{spacing}\"#{dump_mathml(self)}\" function apply\n",
102
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
103
+ ]
104
+ mathml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ ", array: new_arr })
105
+ new_arr
106
+ end
79
107
 
80
- def invert_unicode_symbols
81
- Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
108
+ def to_omml_math_zone(spacing, last = false, _, display_style:)
109
+ new_spacing = gsub_spacing(spacing, last)
110
+ new_arr = [
111
+ "#{spacing}\"#{dump_omml(self, display_style)}\" function apply\n",
112
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
113
+ ]
114
+ omml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ ", array: new_arr, display_style: display_style })
115
+ new_arr
82
116
  end
83
117
 
118
+ protected
119
+
84
120
  def asciimath_value
85
121
  return "" unless parameter_one
86
122
 
@@ -116,6 +152,10 @@ module Plurimath
116
152
 
117
153
  Array(parameter_one&.insert_t_tag(display_style))
118
154
  end
155
+
156
+ def latex_paren
157
+ Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'
158
+ end
119
159
  end
120
160
  end
121
161
  end
@@ -6,6 +6,13 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Underover < TernaryFunction
9
+ FUNCTION = {
10
+ name: "UnderOver",
11
+ first_value: "base",
12
+ second_value: "Under",
13
+ third_value: "Over",
14
+ }.freeze
15
+
9
16
  def to_asciimath
10
17
  first_value = first_field_wrap(parameter_one) if parameter_one
11
18
  second_value = "_#{wrapped(parameter_two)}" if parameter_two
@@ -43,61 +50,6 @@ module Plurimath
43
50
 
44
51
  underover(display_style)
45
52
  end
46
-
47
- def omml_nary_tag(display_style)
48
- pr = Utility.ox_element("naryPr", namespace: "m")
49
- [
50
- pr_element_value(pr),
51
- omml_parameter(parameter_two, display_style, tag_name: "sub"),
52
- omml_parameter(parameter_three, display_style, tag_name: "sup"),
53
- ]
54
- end
55
-
56
- protected
57
-
58
- def hidden_sub_tag(pr_element)
59
- return true unless parameter_two.nil?
60
-
61
- pr_element << Utility.ox_element(
62
- "subHide",
63
- namespace: "m",
64
- attributes: { "m:val": 1 },
65
- )
66
- end
67
-
68
- def hidden_sup_tag(pr_element)
69
- return true unless parameter_three.nil?
70
-
71
- pr_element << Utility.ox_element(
72
- "supHide",
73
- namespace: "m",
74
- attributes: { "m:val": 1 },
75
- )
76
- end
77
-
78
- def pr_element_value(pr_element)
79
- first_value(pr_element)
80
- pr_element << Utility.ox_element(
81
- "limLoc",
82
- namespace: "m",
83
- attributes: { "m:val": "undOvr" },
84
- )
85
- hidden_sub_tag(pr_element)
86
- hidden_sup_tag(pr_element)
87
- pr_element << Utility.pr_element("ctrl", true, namespace: "m")
88
- end
89
-
90
- def first_value(pr_element)
91
- first_value = parameter_one.nary_attr_value
92
- first_value = Utility.html_entity_to_unicode(first_value)
93
- unless first_value == "∫"
94
- pr_element << Utility.ox_element(
95
- "chr",
96
- namespace: "m",
97
- attributes: { "m:val": first_value },
98
- )
99
- end
100
- end
101
53
  end
102
54
  end
103
55
  end
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Underset < BinaryFunction
9
+ FUNCTION = {
10
+ name: "underscript",
11
+ first_value: "underscript value",
12
+ second_value: "base expression",
13
+ }.freeze
14
+
9
15
  def to_mathml_without_math_tag
10
16
  first_value = parameter_one&.to_mathml_without_math_tag
11
17
  second_value = parameter_two&.to_mathml_without_math_tag
@@ -37,6 +37,46 @@ module Plurimath
37
37
  end
38
38
  end
39
39
 
40
+ def to_asciimath_math_zone(spacing, last = false, _)
41
+ new_spacing = gsub_spacing(spacing, last)
42
+ new_arr = [
43
+ "#{spacing}\"#{to_asciimath}\" function apply\n",
44
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
45
+ ]
46
+ ascii_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "supscript", additional_space: "| |_ " , array: new_arr })
47
+ new_arr
48
+ end
49
+
50
+ def to_latex_math_zone(spacing, last = false, _)
51
+ new_spacing = gsub_spacing(spacing, last)
52
+ new_arr = [
53
+ "#{spacing}\"#{to_latex}\" function apply\n",
54
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
55
+ ]
56
+ latex_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "supscript", additional_space: "| |_ " , array: new_arr })
57
+ new_arr
58
+ end
59
+
60
+ def to_mathml_math_zone(spacing, last = false, _)
61
+ new_spacing = gsub_spacing(spacing, last)
62
+ new_arr = [
63
+ "#{spacing}\"#{dump_mathml(self)}\" overset\n",
64
+ "#{new_spacing}|_ \"<mo>&#x2192;</mo>\" base\n",
65
+ ]
66
+ mathml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "supscript", additional_space: "| |_ ", array: new_arr })
67
+ new_arr
68
+ end
69
+
70
+ def to_omml_math_zone(spacing, last = false, _, display_style:)
71
+ new_spacing = gsub_spacing(spacing, last)
72
+ new_arr = [
73
+ "#{spacing}\"#{dump_omml(self, display_style)}\" overset\n",
74
+ "#{new_spacing}|_ \"<m:t>&#x2192;</m:t>\" base\n",
75
+ ]
76
+ omml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "supscript", additional_space: "| |_ ", array: new_arr, display_style: display_style })
77
+ new_arr
78
+ end
79
+
40
80
  protected
41
81
 
42
82
  def acc_tag(display_style)
@@ -6,9 +6,11 @@ module Plurimath
6
6
  end
7
7
 
8
8
  # Include the first level files before the next
9
- (
10
- Dir.glob(File.join(__dir__, "function", "*.rb")) +
11
- Dir.glob(File.join(__dir__, "function", "*", "*.rb"))
12
- ).each do |file|
13
- require file
9
+ if RUBY_ENGINE != 'opal'
10
+ (
11
+ Dir.glob(File.join(__dir__, "function", "*.rb")) +
12
+ Dir.glob(File.join(__dir__, "function", "*", "*.rb"))
13
+ ).each do |file|
14
+ require file
15
+ end
14
16
  end
@@ -10,7 +10,7 @@ module Plurimath
10
10
  end
11
11
 
12
12
  def ==(object)
13
- object.value == value
13
+ object.respond_to?(:value) && object.value == value
14
14
  end
15
15
 
16
16
  def to_asciimath
@@ -30,16 +30,20 @@ module Plurimath
30
30
  end
31
31
 
32
32
  def to_omml_without_math_tag(_display_style)
33
- [(Utility.ox_element("t", namespace: "m") << value)]
33
+ [t_tag]
34
34
  end
35
35
 
36
36
  def insert_t_tag(_display_style)
37
- r_tag = Utility.ox_element("r", namespace: "m")
38
- r_tag << (Utility.ox_element("t", namespace: "m") << value)
39
- [r_tag]
37
+ [
38
+ (Utility.ox_element("r", namespace: "m") << t_tag),
39
+ ]
40
40
  end
41
41
 
42
42
  def font_style_t_tag(_display_style)
43
+ t_tag
44
+ end
45
+
46
+ def t_tag
43
47
  Utility.ox_element("t", namespace: "m") << value
44
48
  end
45
49
 
@@ -10,7 +10,7 @@ module Plurimath
10
10
  end
11
11
 
12
12
  def ==(object)
13
- object.value == value
13
+ object.respond_to?(:value) && object.value == value
14
14
  end
15
15
 
16
16
  def to_asciimath
@@ -29,11 +29,9 @@ module Plurimath
29
29
  mi_tag = Utility.ox_element("mi")
30
30
  return mi_tag if ["{:", ":}"].include?(value)
31
31
 
32
- unicodes = Mathml::Constants::UNICODE_SYMBOLS
33
- unicode = unicodes.invert[value]
32
+ unicode = Mathml::Constants::UNICODE_SYMBOLS.invert[value]
34
33
  if operator?(unicode) || unicode || explicit_checks(unicode)
35
- mo_value = (unicodes[value] || unicode || value).to_s
36
- return Utility.ox_element("mo") << mo_value
34
+ return Utility.ox_element("mo") << (unicode || value).to_s
37
35
  end
38
36
 
39
37
  mi_tag << value
@@ -63,9 +61,7 @@ module Plurimath
63
61
  end
64
62
 
65
63
  def insert_t_tag(_display_style)
66
- r_tag = Utility.ox_element("r", namespace: "m")
67
- r_tag << (Utility.ox_element("t", namespace: "m") << value)
68
- [r_tag]
64
+ [(Utility.ox_element("r", namespace: "m") << t_tag)]
69
65
  end
70
66
 
71
67
  def tag_name
@@ -81,7 +77,7 @@ module Plurimath
81
77
  end
82
78
 
83
79
  def font_style_t_tag(_display_style)
84
- Utility.ox_element("t", namespace: "m") << value
80
+ t_tag
85
81
  end
86
82
 
87
83
  def nary_attr_value
@@ -92,6 +88,14 @@ module Plurimath
92
88
  false
93
89
  end
94
90
 
91
+ def omml_nodes(display_style)
92
+ Array(t_tag)
93
+ end
94
+
95
+ def t_tag
96
+ Utility.ox_element("t", namespace: "m") << value
97
+ end
98
+
95
99
  private
96
100
 
97
101
  def operator?(unicode)