plurimath 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) 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 +4 -0
  6. data/Rakefile +11 -0
  7. data/lib/plurimath/asciimath/parse.rb +3 -2
  8. data/lib/plurimath/asciimath/transform.rb +47 -5
  9. data/lib/plurimath/latex/constants.rb +5 -1
  10. data/lib/plurimath/latex/parse.rb +20 -11
  11. data/lib/plurimath/latex/transform.rb +32 -14
  12. data/lib/plurimath/math/core.rb +212 -10
  13. data/lib/plurimath/math/formula.rb +154 -40
  14. data/lib/plurimath/math/function/abs.rb +28 -15
  15. data/lib/plurimath/math/function/bar.rb +5 -0
  16. data/lib/plurimath/math/function/base.rb +22 -2
  17. data/lib/plurimath/math/function/binary_function.rb +38 -12
  18. data/lib/plurimath/math/function/ceil.rb +24 -9
  19. data/lib/plurimath/math/function/color.rb +14 -0
  20. data/lib/plurimath/math/function/ddot.rb +6 -1
  21. data/lib/plurimath/math/function/deg.rb +4 -1
  22. data/lib/plurimath/math/function/det.rb +4 -1
  23. data/lib/plurimath/math/function/dim.rb +4 -1
  24. data/lib/plurimath/math/function/dot.rb +5 -0
  25. data/lib/plurimath/math/function/exp.rb +4 -1
  26. data/lib/plurimath/math/function/fenced.rb +51 -15
  27. data/lib/plurimath/math/function/floor.rb +24 -14
  28. data/lib/plurimath/math/function/font_style.rb +63 -8
  29. data/lib/plurimath/math/function/frac.rb +38 -18
  30. data/lib/plurimath/math/function/gcd.rb +4 -1
  31. data/lib/plurimath/math/function/glb.rb +8 -1
  32. data/lib/plurimath/math/function/hat.rb +16 -5
  33. data/lib/plurimath/math/function/hom.rb +4 -1
  34. data/lib/plurimath/math/function/inf.rb +16 -0
  35. data/lib/plurimath/math/function/int.rb +35 -9
  36. data/lib/plurimath/math/function/ker.rb +4 -1
  37. data/lib/plurimath/math/function/lcm.rb +17 -1
  38. data/lib/plurimath/math/function/left.rb +20 -2
  39. data/lib/plurimath/math/function/lg.rb +4 -1
  40. data/lib/plurimath/math/function/lim.rb +16 -0
  41. data/lib/plurimath/math/function/liminf.rb +4 -1
  42. data/lib/plurimath/math/function/limits.rb +29 -9
  43. data/lib/plurimath/math/function/limsup.rb +4 -1
  44. data/lib/plurimath/math/function/linebreak.rb +95 -0
  45. data/lib/plurimath/math/function/ln.rb +4 -1
  46. data/lib/plurimath/math/function/log.rb +27 -12
  47. data/lib/plurimath/math/function/longdiv.rb +19 -0
  48. data/lib/plurimath/math/function/lub.rb +4 -1
  49. data/lib/plurimath/math/function/max.rb +4 -1
  50. data/lib/plurimath/math/function/mbox.rb +8 -7
  51. data/lib/plurimath/math/function/menclose.rb +6 -0
  52. data/lib/plurimath/math/function/merror.rb +12 -3
  53. data/lib/plurimath/math/function/min.rb +4 -1
  54. data/lib/plurimath/math/function/mod.rb +48 -15
  55. data/lib/plurimath/math/function/msgroup.rb +32 -0
  56. data/lib/plurimath/math/function/msline.rb +10 -0
  57. data/lib/plurimath/math/function/multiscript.rb +27 -0
  58. data/lib/plurimath/math/function/nary.rb +128 -0
  59. data/lib/plurimath/math/function/norm.rb +24 -15
  60. data/lib/plurimath/math/function/obrace.rb +5 -0
  61. data/lib/plurimath/math/function/oint.rb +48 -20
  62. data/lib/plurimath/math/function/over.rb +29 -10
  63. data/lib/plurimath/math/function/overset.rb +19 -10
  64. data/lib/plurimath/math/function/phantom.rb +24 -6
  65. data/lib/plurimath/math/function/power.rb +19 -4
  66. data/lib/plurimath/math/function/power_base.rb +34 -33
  67. data/lib/plurimath/math/function/prod.rb +43 -23
  68. data/lib/plurimath/math/function/right.rb +20 -2
  69. data/lib/plurimath/math/function/root.rb +6 -0
  70. data/lib/plurimath/math/function/rule.rb +8 -1
  71. data/lib/plurimath/math/function/scarries.rb +14 -0
  72. data/lib/plurimath/math/function/semantics.rb +15 -0
  73. data/lib/plurimath/math/function/sqrt.rb +5 -0
  74. data/lib/plurimath/math/function/stackrel.rb +14 -0
  75. data/lib/plurimath/math/function/substack.rb +18 -51
  76. data/lib/plurimath/math/function/sum.rb +36 -12
  77. data/lib/plurimath/math/function/sup.rb +11 -2
  78. data/lib/plurimath/math/function/table/array.rb +1 -1
  79. data/lib/plurimath/math/function/table/matrix.rb +4 -0
  80. data/lib/plurimath/math/function/table.rb +62 -26
  81. data/lib/plurimath/math/function/td.rb +42 -4
  82. data/lib/plurimath/math/function/ternary_function.rb +48 -10
  83. data/lib/plurimath/math/function/text.rb +25 -3
  84. data/lib/plurimath/math/function/tilde.rb +5 -0
  85. data/lib/plurimath/math/function/tr.rb +29 -1
  86. data/lib/plurimath/math/function/ubrace.rb +5 -0
  87. data/lib/plurimath/math/function/unary_function.rb +115 -29
  88. data/lib/plurimath/math/function/underover.rb +27 -58
  89. data/lib/plurimath/math/function/underset.rb +25 -9
  90. data/lib/plurimath/math/function/vec.rb +45 -0
  91. data/lib/plurimath/math/function.rb +7 -5
  92. data/lib/plurimath/math/number.rb +12 -8
  93. data/lib/plurimath/math/symbol.rb +25 -13
  94. data/lib/plurimath/math.rb +1 -3
  95. data/lib/plurimath/mathml/parser.rb +6 -4
  96. data/lib/plurimath/mathml/transform.rb +26 -19
  97. data/lib/plurimath/omml/parser.rb +3 -3
  98. data/lib/plurimath/omml/transform.rb +34 -21
  99. data/lib/plurimath/setup/oga.rb +5 -0
  100. data/lib/plurimath/setup/opal.rb.erb +8 -0
  101. data/lib/plurimath/setup/ox.rb +5 -0
  102. data/lib/plurimath/unitsml.rb +2 -1
  103. data/lib/plurimath/utility.rb +77 -41
  104. data/lib/plurimath/version.rb +1 -1
  105. data/lib/plurimath/xml_engine/oga.rb +246 -0
  106. data/lib/plurimath/xml_engine/ox.rb +29 -0
  107. data/lib/plurimath/xml_engine.rb +6 -0
  108. data/lib/plurimath.rb +12 -2
  109. metadata +12 -3
  110. data/lib/plurimath/math/function/scarry.rb +0 -12
@@ -4,7 +4,7 @@ module Plurimath
4
4
  module Math
5
5
  module Function
6
6
  class TernaryFunction < Core
7
- attr_accessor :parameter_one, :parameter_two, :parameter_three
7
+ attr_accessor :parameter_one, :parameter_two, :parameter_three, :hide_function_name
8
8
 
9
9
  def initialize(parameter_one = nil,
10
10
  parameter_two = nil,
@@ -12,7 +12,7 @@ module Plurimath
12
12
  @parameter_one = parameter_one
13
13
  @parameter_two = parameter_two
14
14
  @parameter_three = parameter_three
15
- Utility.validate_left_right([parameter_one, parameter_two, parameter_three])
15
+ Utility.validate_left_right(variables.map { |var| get(var) })
16
16
  end
17
17
 
18
18
  def to_asciimath
@@ -30,10 +30,12 @@ module Plurimath
30
30
  end
31
31
 
32
32
  def to_mathml_without_math_tag
33
- value_arr = [parameter_one&.to_mathml_without_math_tag]
34
- value_arr << parameter_two&.to_mathml_without_math_tag
35
- value_arr << parameter_three&.to_mathml_without_math_tag
36
- class_tag = Utility.ox_element("m#{class_name}")
33
+ value_arr = [
34
+ validate_mathml_fields(parameter_one),
35
+ validate_mathml_fields(parameter_two),
36
+ validate_mathml_fields(parameter_three),
37
+ ]
38
+ class_tag = ox_element("m#{class_name}")
37
39
  Utility.update_nodes(class_tag, value_arr)
38
40
  end
39
41
 
@@ -59,6 +61,46 @@ module Plurimath
59
61
  !(parameter_one.nil? && parameter_two.nil? && parameter_three.nil?)
60
62
  end
61
63
 
64
+ def to_asciimath_math_zone(spacing, last = false, _)
65
+ parameters = self.class::FUNCTION
66
+ new_spacing = gsub_spacing(spacing, last)
67
+ new_arr = ["#{spacing}\"#{to_asciimath}\" #{parameters[:name]}\n"]
68
+ ascii_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr })
69
+ ascii_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr })
70
+ ascii_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr })
71
+ new_arr
72
+ end
73
+
74
+ def to_latex_math_zone(spacing, last = false, _)
75
+ parameters = self.class::FUNCTION
76
+ new_spacing = gsub_spacing(spacing, last)
77
+ new_arr = ["#{spacing}\"#{to_latex}\" #{parameters[:name]}\n"]
78
+ latex_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr })
79
+ latex_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr })
80
+ latex_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr })
81
+ new_arr
82
+ end
83
+
84
+ def to_mathml_math_zone(spacing, last = false, _)
85
+ parameters = self.class::FUNCTION
86
+ new_spacing = gsub_spacing(spacing, last)
87
+ new_arr = ["#{spacing}\"#{dump_mathml(self)}\" #{parameters[:name]}\n"]
88
+ mathml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr })
89
+ mathml_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr })
90
+ mathml_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr })
91
+ new_arr
92
+ end
93
+
94
+ def to_omml_math_zone(spacing, last = false, _, display_style:)
95
+ parameters = self.class::FUNCTION
96
+ new_spacing = gsub_spacing(spacing, last)
97
+ new_arr = ["#{spacing}\"#{dump_omml(self, display_style)}\" #{parameters[:name]}\n"]
98
+ omml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr, display_style: display_style })
99
+ omml_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ ", array: new_arr, display_style: display_style })
100
+ omml_fields_to_print(parameter_three, { spacing: new_spacing, field_name: parameters[:third_value], additional_space: " |_ ", array: new_arr, display_style: display_style })
101
+ new_arr
102
+ end
103
+
62
104
  protected
63
105
 
64
106
  def latex_wrapped(field)
@@ -69,10 +111,6 @@ module Plurimath
69
111
  end
70
112
  end
71
113
 
72
- def invert_unicode_symbols
73
- Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
74
- end
75
-
76
114
  def wrapped(field, type: "ascii")
77
115
  return "" unless field
78
116
 
@@ -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
@@ -27,7 +29,7 @@ module Plurimath
27
29
  parse_text("html") || parameter_one
28
30
  end
29
31
 
30
- def to_omml_without_math_tag(_display_style)
32
+ def to_omml_without_math_tag(_)
31
33
  text = Utility.ox_element("t", namespace: "m")
32
34
  text << (parse_text("omml") || parameter_one)
33
35
  [text]
@@ -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,7 +74,7 @@ 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
80
  when "mathml", "html", "omml"
@@ -36,6 +36,11 @@ module Plurimath
36
36
  false
37
37
  end
38
38
 
39
+ def line_breaking(obj)
40
+ parameter_one&.line_breaking(obj)
41
+ obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
42
+ end
43
+
39
44
  protected
40
45
 
41
46
  def acc_tag(display_style)
@@ -32,7 +32,7 @@ module Plurimath
32
32
  end
33
33
 
34
34
  def to_omml_without_math_tag(display_style)
35
- omml_content = parameter_one&.map { |obj| obj.to_omml_without_math_tag(display_style) }
35
+ omml_content = parameter_one&.map { |object| object.to_omml_without_math_tag(display_style) }
36
36
  if parameter_one.count.eql?(1)
37
37
  omml_content
38
38
  else
@@ -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
@@ -56,6 +56,11 @@ module Plurimath
56
56
  symbol = Symbol.new("⏟")
57
57
  Underset.new(parameter_one, symbol).to_omml_without_math_tag(true)
58
58
  end
59
+
60
+ def line_breaking(obj)
61
+ parameter_one&.line_breaking(obj)
62
+ obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
63
+ end
59
64
  end
60
65
 
61
66
  Underbrace = Ubrace
@@ -4,12 +4,13 @@ module Plurimath
4
4
  module Math
5
5
  module Function
6
6
  class UnaryFunction < Core
7
- attr_accessor :parameter_one
7
+ attr_accessor :parameter_one, :hide_function_name
8
8
 
9
9
  def initialize(parameter_one = nil)
10
10
  parameter_one = parameter_one.to_s if parameter_one.is_a?(Parslet::Slice)
11
11
  @parameter_one = parameter_one
12
- Utility.validate_left_right([parameter_one])
12
+ method(:post_initialize).call if methods.include?(:post_initialize)
13
+ Utility.validate_left_right(variables.map { |var| get(var) })
13
14
  end
14
15
 
15
16
  def ==(object)
@@ -27,12 +28,12 @@ module Plurimath
27
28
  end
28
29
 
29
30
  def to_mathml_without_math_tag
30
- row_tag = Utility.ox_element("mrow")
31
31
  tag_name = Utility::UNARY_CLASSES.include?(class_name) ? "mi" : "mo"
32
- new_arr = [Utility.ox_element(tag_name) << class_name]
32
+ new_arr = []
33
+ new_arr << (ox_element(tag_name) << class_name) unless hide_function_name
33
34
  if parameter_one
34
35
  new_arr += mathml_value
35
- Utility.update_nodes(row_tag, new_arr)
36
+ Utility.update_nodes(ox_element("mrow"), new_arr)
36
37
  else
37
38
  new_arr.first
38
39
  end
@@ -54,33 +55,90 @@ module Plurimath
54
55
  def to_omml_without_math_tag(display_style)
55
56
  return r_element(class_name, rpr_tag: false) unless parameter_one
56
57
 
57
- func = Utility.ox_element("func", namespace: "m")
58
- funcpr = Utility.ox_element("funcPr", namespace: "m")
59
- funcpr << Utility.pr_element("ctrl", true, namespace: "m")
60
- fname = Utility.ox_element("fName", namespace: "m")
61
- mr = Utility.ox_element("r", namespace: "m")
62
- rpr = Utility.rpr_element
63
- mt = Utility.ox_element("t", namespace: "m") << class_name
64
- fname << Utility.update_nodes(mr, [rpr, mt])
65
- me = Utility.ox_element("e", namespace: "m")
66
- Utility.update_nodes(me, omml_value(display_style)) if parameter_one
67
- Utility.update_nodes(
68
- func,
69
- [
70
- funcpr,
71
- fname,
72
- me,
73
- ],
74
- )
75
- [func]
58
+ if @hide_function_name
59
+ value = omml_value(display_style)
60
+ else
61
+ func = Utility.ox_element("func", namespace: "m")
62
+ value = Utility.update_nodes(func, function_values(display_style))
63
+ end
64
+ Array(value)
76
65
  end
77
66
 
78
- protected
67
+ def to_asciimath_math_zone(spacing, last = false, _)
68
+ new_spacing = gsub_spacing(spacing, last)
69
+ new_arr = [
70
+ "#{spacing}\"#{to_asciimath}\" function apply\n",
71
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
72
+ ]
73
+ ascii_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ " , array: new_arr })
74
+ new_arr
75
+ end
76
+
77
+ def to_latex_math_zone(spacing, last = false, _)
78
+ new_spacing = gsub_spacing(spacing, last)
79
+ new_arr = [
80
+ "#{spacing}\"#{to_latex}\" function apply\n",
81
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
82
+ ]
83
+ latex_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ " , array: new_arr })
84
+ new_arr
85
+ end
86
+
87
+ def to_mathml_math_zone(spacing, last = false, _)
88
+ new_spacing = gsub_spacing(spacing, last)
89
+ new_arr = [
90
+ "#{spacing}\"#{dump_mathml(self)}\" function apply\n",
91
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
92
+ ]
93
+ mathml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ ", array: new_arr })
94
+ new_arr
95
+ end
96
+
97
+ def to_omml_math_zone(spacing, last = false, _, display_style:)
98
+ new_spacing = gsub_spacing(spacing, last)
99
+ new_arr = [
100
+ "#{spacing}\"#{dump_omml(self, display_style)}\" function apply\n",
101
+ "#{new_spacing}|_ \"#{class_name}\" function name\n",
102
+ ]
103
+ omml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: " |_ ", array: new_arr, display_style: display_style })
104
+ new_arr
105
+ end
106
+
107
+ def custom_array_line_breaking(obj)
108
+ parameter_value = result(parameter_one)
109
+ if parameter_value.size > 1
110
+ breaked_result = parameter_value.first.last.omml_line_break(parameter_value)
111
+ update(Array(breaked_result.shift))
112
+ obj.update(self.class.new(breaked_result.flatten))
113
+ reprocess_parameter_one(obj)
114
+ return
115
+ end
116
+
117
+ parameter_one.each.with_index(1) do |object, index|
118
+ object.line_breaking(obj)
119
+ break obj.insert(parameter_one.slice!(index..parameter_one.size)) if obj.value_exist?
120
+ end
121
+ end
79
122
 
80
- def invert_unicode_symbols
81
- Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
123
+ def update(value)
124
+ self.parameter_one = value
82
125
  end
83
126
 
127
+ def reprocess_parameter_one(obj)
128
+ new_obj = Formula.new([])
129
+ self.line_breaking(new_obj)
130
+ if new_obj.value_exist?
131
+ obj.value.insert(0, Linebreak.new)
132
+ obj.value.insert(0, self.class.new(new_obj.value))
133
+ end
134
+ end
135
+
136
+ def value_nil?
137
+ !parameter_one
138
+ end
139
+
140
+ protected
141
+
84
142
  def asciimath_value
85
143
  return "" unless parameter_one
86
144
 
@@ -111,10 +169,38 @@ module Plurimath
111
169
 
112
170
  def omml_value(display_style)
113
171
  if parameter_one.is_a?(Array)
114
- return parameter_one&.compact&.map { |obj| obj.insert_t_tag(display_style) }
172
+ return parameter_one&.compact&.map { |object| formula_to_nodes(object, display_style) }
115
173
  end
116
174
 
117
- Array(parameter_one&.insert_t_tag(display_style))
175
+ Array(formula_to_nodes(parameter_one, display_style))
176
+ end
177
+
178
+ def formula_to_nodes(object, display_style)
179
+ object&.insert_t_tag(display_style)
180
+ end
181
+
182
+ def latex_paren
183
+ Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'
184
+ end
185
+
186
+ def exist?
187
+ !(parameter_one.is_a?(Array) ? parameter_one.empty? : parameter_one.nil?)
188
+ end
189
+
190
+ def function_values(display_style)
191
+ funcpr = Utility.ox_element("funcPr", namespace: "m")
192
+ funcpr << Utility.pr_element("ctrl", true, namespace: "m")
193
+ fname = Utility.ox_element("fName", namespace: "m")
194
+ fname << Utility.update_nodes(
195
+ Utility.ox_element("r", namespace: "m"),
196
+ [
197
+ Utility.rpr_element,
198
+ (Utility.ox_element("t", namespace: "m") << class_name),
199
+ ],
200
+ )
201
+ me = Utility.ox_element("e", namespace: "m")
202
+ Utility.update_nodes(me, omml_value(display_style)) if parameter_one
203
+ [funcpr, fname, me]
118
204
  end
119
205
  end
120
206
  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
@@ -21,16 +28,12 @@ module Plurimath
21
28
  end
22
29
 
23
30
  def to_mathml_without_math_tag
24
- first_value = parameter_one&.to_mathml_without_math_tag
25
- second_value = parameter_two&.to_mathml_without_math_tag
26
- third_value = parameter_three&.to_mathml_without_math_tag
27
- class_tag = Utility.ox_element("m#{class_name}")
28
31
  Utility.update_nodes(
29
- class_tag,
32
+ ox_element("m#{class_name}"),
30
33
  [
31
- first_value,
32
- second_value,
33
- third_value,
34
+ validate_mathml_fields(parameter_one),
35
+ validate_mathml_fields(parameter_two),
36
+ validate_mathml_fields(parameter_three),
34
37
  ],
35
38
  )
36
39
  end
@@ -44,58 +47,24 @@ module Plurimath
44
47
  underover(display_style)
45
48
  end
46
49
 
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
50
+ def line_breaking(obj)
51
+ parameter_one&.line_breaking(obj)
52
+ if obj.value_exist?
53
+ obj.update(
54
+ Underover.new(Utility.filter_values(obj.value), parameter_two, parameter_three)
55
+ )
56
+ self.parameter_two = nil
57
+ self.parameter_three = nil
58
+ return
59
+ end
89
60
 
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 },
61
+ parameter_two.line_breaking(obj)
62
+ if obj.value_exist?
63
+ obj.update(
64
+ Underover.new(nil, Utility.filter_values(obj.value), parameter_three)
98
65
  )
66
+ self.parameter_two = nil
67
+ self.parameter_three = nil
99
68
  end
100
69
  end
101
70
  end
@@ -6,16 +6,18 @@ 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
- first_value = parameter_one&.to_mathml_without_math_tag
11
- second_value = parameter_two&.to_mathml_without_math_tag
12
- Utility.update_nodes(
13
- Utility.ox_element("munder"),
14
- [
15
- second_value,
16
- first_value,
17
- ],
18
- )
16
+ value_array = [
17
+ validate_mathml_fields(parameter_two),
18
+ validate_mathml_fields(parameter_one),
19
+ ]
20
+ Utility.update_nodes(ox_element("munder"), value_array)
19
21
  end
20
22
 
21
23
  def to_omml_without_math_tag(display_style)
@@ -37,6 +39,20 @@ module Plurimath
37
39
  )
38
40
  [limlow]
39
41
  end
42
+
43
+ def line_breaking(obj)
44
+ parameter_one&.line_breaking(obj)
45
+ if obj.value_exist?
46
+ obj.update(self.class.new(Utility.filter_values(obj.value), parameter_two))
47
+ self.parameter_two = nil
48
+ return
49
+ end
50
+
51
+ parameter_two&.line_breaking(obj)
52
+ if obj.value_exist?
53
+ obj.update(self.class.new(nil, Utility.filter_values(obj.value)))
54
+ end
55
+ end
40
56
  end
41
57
  end
42
58
  end
@@ -37,6 +37,51 @@ 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
+
80
+ def line_breaking(obj)
81
+ parameter_one&.line_breaking(obj)
82
+ obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
83
+ end
84
+
40
85
  protected
41
86
 
42
87
  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
@@ -29,17 +29,21 @@ module Plurimath
29
29
  value
30
30
  end
31
31
 
32
- def to_omml_without_math_tag(_display_style)
33
- [(Utility.ox_element("t", namespace: "m") << value)]
32
+ def to_omml_without_math_tag(_)
33
+ [t_tag]
34
34
  end
35
35
 
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]
36
+ def insert_t_tag(_)
37
+ [
38
+ (Utility.ox_element("r", namespace: "m") << t_tag),
39
+ ]
40
40
  end
41
41
 
42
- def font_style_t_tag(_display_style)
42
+ def font_style_t_tag(_)
43
+ t_tag
44
+ end
45
+
46
+ def t_tag
43
47
  Utility.ox_element("t", namespace: "m") << value
44
48
  end
45
49