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
@@ -5,6 +5,13 @@ module Plurimath
5
5
  class Formula < Core
6
6
  attr_accessor :value, :left_right_wrapper, :displaystyle, :input_string
7
7
 
8
+ MATH_ZONE_TYPES = %i[
9
+ omml
10
+ latex
11
+ mathml
12
+ asciimath
13
+ ].freeze
14
+
8
15
  def initialize(
9
16
  value = [],
10
17
  left_right_wrapper = true,
@@ -18,7 +25,9 @@ module Plurimath
18
25
  end
19
26
 
20
27
  def ==(object)
21
- object.value == value &&
28
+ object.respond_to?(:value) &&
29
+ object.respond_to?(:left_right_wrapper) &&
30
+ object.value == value &&
22
31
  object.left_right_wrapper == left_right_wrapper
23
32
  end
24
33
 
@@ -28,21 +37,29 @@ module Plurimath
28
37
  parse_error!(:asciimath)
29
38
  end
30
39
 
31
- def to_mathml(display_style: displaystyle)
40
+ def to_mathml(display_style: displaystyle, split_on_linebreak: false)
41
+ return line_breaked_mathml(display_style) if split_on_linebreak
42
+
32
43
  math_attrs = {
33
44
  xmlns: "http://www.w3.org/1998/Math/MathML",
34
45
  display: "block",
35
46
  }
36
47
  style_attrs = { displaystyle: boolean_display_style(display_style) }
37
- math = Utility.ox_element("math", attributes: math_attrs)
38
- style = Utility.ox_element("mstyle", attributes: style_attrs)
48
+ math = ox_element("math", attributes: math_attrs)
49
+ style = ox_element("mstyle", attributes: style_attrs)
39
50
  Utility.update_nodes(style, mathml_content)
40
51
  Utility.update_nodes(math, [style])
41
- Ox.dump(math, indent: 2).gsub("&amp;", "&")
52
+ dump_nodes(math, indent: 2)
42
53
  rescue
43
54
  parse_error!(:mathml)
44
55
  end
45
56
 
57
+ def line_breaked_mathml(display_style)
58
+ new_line_support.map do |formula|
59
+ formula.to_mathml(display_style: display_style)
60
+ end.join
61
+ end
62
+
46
63
  def to_mathml_without_math_tag
47
64
  return mathml_content unless left_right_wrapper
48
65
 
@@ -68,7 +85,7 @@ module Plurimath
68
85
  parse_error!(:html)
69
86
  end
70
87
 
71
- def omml_math_attrs
88
+ def omml_attrs
72
89
  {
73
90
  "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
74
91
  "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
@@ -91,16 +108,20 @@ module Plurimath
91
108
  }
92
109
  end
93
110
 
94
- def to_omml(display_style: displaystyle)
95
- para_element = Utility.ox_element(
96
- "oMathPara",
97
- attributes: omml_math_attrs,
98
- namespace: "m",
99
- )
100
- math_element = Utility.ox_element("oMath", namespace: "m")
101
- content = omml_content(boolean_display_style(display_style))
102
- para_element << Utility.update_nodes(math_element, content)
103
- Ox.dump(para_element, indent: 2).gsub("&amp;", "&").lstrip
111
+ def to_omml(display_style: displaystyle, split_on_linebreak: false)
112
+ objects = split_on_linebreak ? new_line_support : [self]
113
+
114
+ para_element = Utility.ox_element("oMathPara", attributes: omml_attrs, namespace: "m")
115
+ objects.each.with_index(1) do |object, index|
116
+ para_element << Utility.update_nodes(
117
+ Utility.ox_element("oMath", namespace: "m"),
118
+ object.omml_content(boolean_display_style(display_style)),
119
+ )
120
+ next if objects.length == index
121
+
122
+ para_element << omml_br_tag
123
+ end
124
+ dump_nodes(para_element, indent: 2)
104
125
  rescue
105
126
  parse_error!(:omml)
106
127
  end
@@ -110,24 +131,58 @@ module Plurimath
110
131
  end
111
132
 
112
133
  def to_omml_without_math_tag(display_style)
113
- return nary_tag(display_style) if nary_tag_able?(display_style)
114
-
115
134
  omml_content(display_style)
116
135
  end
117
136
 
118
- def nary_tag(display_style)
119
- nary_element = Utility.ox_element("nary", namespace: "m")
120
- e_tag = Utility.ox_element("e", namespace: "m")
121
- Utility.update_nodes(e_tag, value.last.insert_t_tag(display_style))
122
- Utility.update_nodes(
123
- nary_element,
124
- (value.first.omml_nary_tag(display_style) << e_tag),
125
- )
126
- [nary_element]
137
+ def to_display(type = nil)
138
+ return type_error! unless MATH_ZONE_TYPES.include?(type.downcase.to_sym)
139
+
140
+ math_zone = case type
141
+ when :asciimath
142
+ " |_ \"#{to_asciimath}\"\n#{to_asciimath_math_zone(" ").join}"
143
+ when :latex
144
+ " |_ \"#{to_latex}\"\n#{to_latex_math_zone(" ").join}"
145
+ when :mathml
146
+ " |_ \"#{to_mathml.gsub(/\n\s*/, "")}\"\n#{to_mathml_math_zone(" ").join}"
147
+ when :omml
148
+ " |_ \"#{to_omml.gsub(/\n\s*/, "")}\"\n#{to_omml_math_zone(" ", display_style: displaystyle).join}"
149
+ end
150
+ <<~MATHZONE.sub(/\n$/, "")
151
+ |_ Math zone
152
+ #{math_zone}
153
+ MATHZONE
127
154
  end
128
155
 
129
- def extract_class_from_text
130
- return false unless (value.length < 2 && value&.first&.is_a?(Function::Text))
156
+ def to_asciimath_math_zone(spacing = "", last = false, indent = true)
157
+ filtered_values(value).map.with_index(1) do |object, index|
158
+ last = index == @values.length
159
+ object.to_asciimath_math_zone(new_space(spacing, indent), last, indent)
160
+ end
161
+ end
162
+
163
+ def to_latex_math_zone(spacing = "", last = false, indent = true)
164
+ filtered_values(value).map.with_index(1) do |object, index|
165
+ last = index == @values.length
166
+ object.to_latex_math_zone(new_space(spacing, indent), last, indent)
167
+ end
168
+ end
169
+
170
+ def to_mathml_math_zone(spacing = "", last = false, indent = true)
171
+ filtered_values(value).map.with_index(1) do |object, index|
172
+ last = index == @values.length
173
+ object.to_mathml_math_zone(new_space(spacing, indent), last, indent)
174
+ end
175
+ end
176
+
177
+ def to_omml_math_zone(spacing = "", last = false, indent = true, display_style:)
178
+ filtered_values(value).map.with_index(1) do |object, index|
179
+ last = index == @values.length
180
+ object.to_omml_math_zone(new_space(spacing, indent), last, indent, display_style: display_style)
181
+ end
182
+ end
183
+
184
+ def extract_class_name_from_text
185
+ return unless value.length < 2 && value.first.is_a?(Function::Text)
131
186
 
132
187
  value.first.parameter_one
133
188
  end
@@ -136,29 +191,88 @@ module Plurimath
136
191
  value.first.nary_attr_value
137
192
  end
138
193
 
139
- def nary_tag_able?(display_style)
140
- value.length == 2 &&
141
- ["underover", "powerbase"].include?(value&.first&.class_name) &&
142
- !value.first.parameter_one.is_a?(Function::FontStyle) &&
143
- (
144
- value&.first&.parameter_one&.to_omml_without_math_tag(display_style)&.length == 1 ||
145
- value&.first&.parameter_one.to_omml_without_math_tag(display_style).match?(/^&#x\w*\d*;$/)
146
- )
147
- end
148
-
149
194
  def validate_function_formula
150
195
  (value.none?(Function::Left) || value.none?(Function::Right))
151
196
  end
152
197
 
198
+ def value_exist?
199
+ value && !value.empty?
200
+ end
201
+
202
+ def update(object)
203
+ self.value = Array(object)
204
+ end
205
+
206
+ def cloned_objects
207
+ cloned_obj = value.map(&:cloned_objects)
208
+ formula = self.class.new(cloned_obj)
209
+ formula.left_right_wrapper = @left_right_wrapper
210
+ formula
211
+ end
212
+
213
+ def new_line_support(array = [])
214
+ cloned = cloned_objects
215
+ obj = self.class.new
216
+ cloned.line_breaking(obj)
217
+ array << cloned
218
+ obj.value_exist? ? obj.new_line_support(array) : array
219
+ end
220
+
221
+ def line_breaking(obj)
222
+ if result.size > 1
223
+ breaked_result = result.first.last.omml_line_break(result)
224
+ update(Array(breaked_result.shift))
225
+ obj.update(breaked_result.flatten)
226
+ reprocess_value(obj)
227
+ return
228
+ end
229
+
230
+ value.each.with_index(1) do |object, index|
231
+ object.line_breaking(obj)
232
+ break obj.insert(value.slice!(index..value.size)) if obj.value_exist?
233
+ end
234
+ end
235
+
236
+ def reprocess_value(obj)
237
+ new_obj = self.class.new([])
238
+ self.line_breaking(new_obj)
239
+ if new_obj.value_exist?
240
+ obj.value.insert(0, Function::Linebreak.new)
241
+ obj.value.insert(0, self.class.new(new_obj.value))
242
+ end
243
+ end
244
+
245
+ def insert(values)
246
+ update(Array(value) + values)
247
+ end
248
+
249
+
153
250
  protected
154
251
 
155
252
  def boolean_display_style(display_style = displaystyle)
156
- YAML.load(display_style.to_s)
253
+ YAML.safe_load(display_style.to_s)
254
+ end
255
+
256
+ def new_space(spacing, indent)
257
+ if value.any? { |val| val.class_name == "left" } && value.any? { |val| val.class_name == "right" }
258
+ return spacing
259
+ end
260
+
261
+ (indent && wrapable?(spacing)) ? spacing + "|_ " : spacing
262
+ end
263
+
264
+ def wrapable?(spacing)
265
+ left_right_wrapper && !spacing.end_with?("|_ ")
157
266
  end
158
267
 
159
268
  def parse_error!(type)
160
269
  Math.parse_error!(input_string, type)
161
270
  end
271
+
272
+ def omml_br_tag
273
+ r_tag = ox_element("r", namespace: "m")
274
+ r_tag << ox_element("br")
275
+ end
162
276
  end
163
277
  end
164
278
  end
@@ -6,32 +6,45 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Abs < UnaryFunction
9
+ attr_accessor :open_paren, :close_paren
10
+
9
11
  def to_mathml_without_math_tag
10
12
  symbol = Utility.ox_element("mo") << "|"
11
- first_value = mathml_value&.insert(0, symbol)
12
- Utility.update_nodes(
13
- Utility.ox_element("mrow"),
14
- first_value << symbol,
15
- )
13
+ first_value = mathml_value
14
+ first_value = first_value&.insert(0, symbol) unless open_paren
15
+ first_value << symbol unless close_paren
16
+ Utility.update_nodes(ox_element("mrow"), first_value)
16
17
  end
17
18
 
18
19
  def to_omml_without_math_tag(display_style)
19
- md = (Utility.ox_element("d", namespace: "m") << mdpr_tag)
20
- me = Utility.ox_element("e", namespace: "m")
21
- Utility.update_nodes(me, omml_value(display_style))
22
- Utility.update_nodes(md, Array(me))
23
- [md]
20
+ Array(
21
+ md_tag << omml_parameter(parameter_one, display_style, tag_name: "e"),
22
+ )
23
+ end
24
+
25
+ def line_breaking(obj)
26
+ parameter_one.line_breaking(obj)
27
+ if obj.value_exist?
28
+ ceil_object = self.class.new(Utility.filter_values(obj.value))
29
+ ceil_object.open_paren = true
30
+ ceil_object.close_paren = false
31
+ obj.update(ceil_object)
32
+ self.close_paren = true
33
+ self.open_paren = false unless open_paren
34
+ end
24
35
  end
25
36
 
26
37
  protected
27
38
 
28
- def mdpr_tag
39
+ def md_tag
29
40
  attribute = { "m:val": "|" }
41
+ sepchr_attr = { "m:val": "" }
30
42
  mdpr = Utility.pr_element("d", namespace: "m")
31
- mdpr << Utility.ox_element("begChr", namespace: "m", attributes: attribute)
32
- mdpr << Utility.ox_element("endChr", namespace: "m", attributes: attribute)
33
- mdpr << Utility.ox_element("sepChr", namespace: "m", attributes: { "m:val": "" })
34
- mdpr << Utility.ox_element("grow", namespace: "m")
43
+ mdpr << ox_element("begChr", namespace: "m", attributes: attribute) unless open_paren
44
+ mdpr << ox_element("endChr", namespace: "m", attributes: attribute) unless close_paren
45
+ mdpr << ox_element("sepChr", namespace: "m", attributes: sepchr_attr)
46
+ mdpr << ox_element("grow", namespace: "m")
47
+ ox_element("d", namespace: "m") << mdpr
35
48
  end
36
49
  end
37
50
  end
@@ -48,6 +48,11 @@ module Plurimath
48
48
  Ul.new(parameter_one, attributes)
49
49
  end
50
50
 
51
+ def line_breaking(obj)
52
+ parameter_one&.line_breaking(obj)
53
+ obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
54
+ end
55
+
51
56
  protected
52
57
 
53
58
  def acc_tag(display_style)
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Base < BinaryFunction
9
+ FUNCTION = {
10
+ name: "subscript",
11
+ first_value: "base",
12
+ second_value: "script",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  first_value = parameter_one.to_asciimath if parameter_one
11
17
  second_value = "_#{wrapped(parameter_two)}" if parameter_two
@@ -16,8 +22,8 @@ module Plurimath
16
22
  tag_name = (Utility::MUNDER_CLASSES.include?(parameter_one&.class_name) ? "under" : "sub")
17
23
  sub_tag = Utility.ox_element("m#{tag_name}")
18
24
  mathml_value = []
19
- mathml_value << parameter_one&.to_mathml_without_math_tag
20
- mathml_value << parameter_two&.to_mathml_without_math_tag if parameter_two
25
+ mathml_value << validate_mathml_fields(parameter_one)
26
+ mathml_value << validate_mathml_fields(parameter_two)
21
27
  Utility.update_nodes(sub_tag, mathml_value)
22
28
  end
23
29
 
@@ -48,6 +54,20 @@ module Plurimath
48
54
  )
49
55
  [ssub_element]
50
56
  end
57
+
58
+ def line_breaking(obj)
59
+ parameter_one&.line_breaking(obj)
60
+ if obj.value_exist?
61
+ obj.update(self.class.new(Utility.filter_values(obj.value), parameter_two))
62
+ self.parameter_two = nil
63
+ return
64
+ end
65
+
66
+ parameter_two&.line_breaking(obj)
67
+ if obj.value_exist?
68
+ obj.update(self.class.new(nil, Utility.filter_values(obj.value)))
69
+ end
70
+ end
51
71
  end
52
72
  end
53
73
  end
@@ -4,12 +4,12 @@ module Plurimath
4
4
  module Math
5
5
  module Function
6
6
  class BinaryFunction < Core
7
- attr_accessor :parameter_one, :parameter_two
7
+ attr_accessor :parameter_one, :parameter_two, :hide_function_name
8
8
 
9
9
  def initialize(parameter_one = nil, parameter_two = nil)
10
10
  @parameter_one = parameter_one
11
11
  @parameter_two = parameter_two
12
- Utility.validate_left_right([parameter_one, parameter_two])
12
+ Utility.validate_left_right(variables.map { |var| get(var) })
13
13
  end
14
14
 
15
15
  def to_asciimath
@@ -64,6 +64,42 @@ module Plurimath
64
64
  !(parameter_one.nil? && parameter_two.nil?)
65
65
  end
66
66
 
67
+ def to_asciimath_math_zone(spacing, last = false, _)
68
+ parameters = self.class::FUNCTION
69
+ new_spacing = gsub_spacing(spacing, last)
70
+ new_arr = ["#{spacing}\"#{to_asciimath}\" #{parameters[:name]}\n"]
71
+ ascii_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ " , array: new_arr })
72
+ ascii_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ " , array: new_arr })
73
+ new_arr
74
+ end
75
+
76
+ def to_latex_math_zone(spacing, last = false, _)
77
+ parameters = self.class::FUNCTION
78
+ new_spacing = gsub_spacing(spacing, last)
79
+ new_arr = ["#{spacing}\"#{to_latex}\" #{parameters[:name]}\n"]
80
+ latex_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ " , array: new_arr })
81
+ latex_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_value], additional_space: " |_ " , array: new_arr })
82
+ new_arr
83
+ end
84
+
85
+ def to_mathml_math_zone(spacing, last = false, _)
86
+ parameters = self.class::FUNCTION
87
+ new_spacing = gsub_spacing(spacing, last)
88
+ new_arr = ["#{spacing}\"#{dump_mathml(self)}\" #{parameters[:name]}\n"]
89
+ mathml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: parameters[:first_value], additional_space: "| |_ ", array: new_arr })
90
+ mathml_fields_to_print(parameter_two, { spacing: new_spacing, field_name: parameters[:second_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
+ new_arr
101
+ end
102
+
67
103
  protected
68
104
 
69
105
  def latex_wrapped(field)
@@ -80,16 +116,6 @@ module Plurimath
80
116
  "(#{field.to_asciimath})"
81
117
  end
82
118
 
83
- def invert_unicode_symbols
84
- Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
85
- end
86
-
87
- def empty_tag(wrapper_tag)
88
- r_tag = Utility.ox_element("r", namespace: "m")
89
- r_tag << (Utility.ox_element("t", namespace: "m") << "&#8203;")
90
- wrapper_tag << r_tag
91
- end
92
-
93
119
  def underover(display_style)
94
120
  return r_element(class_name, rpr_tag: false) unless all_values_exist?
95
121
 
@@ -6,23 +6,22 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Ceil < UnaryFunction
9
+ attr_accessor :open_paren, :close_paren
10
+
9
11
  def to_latex
10
12
  "{\\lceil #{latex_value} \\rceil}"
11
13
  end
12
14
 
13
15
  def to_mathml_without_math_tag
14
- left_value = Utility.ox_element("mo") << "&#x2308;"
15
- first_value = mathml_value&.insert(0, left_value)
16
- right_value = Utility.ox_element("mo") << "&#x2309;"
17
- Utility.update_nodes(
18
- Utility.ox_element("mrow"),
19
- first_value << right_value,
20
- )
16
+ first_value = mathml_value
17
+ first_value = first_value&.insert(0, paren_node("&#x2308;")) unless open_paren
18
+ first_value = first_value << paren_node("&#x2309;") unless close_paren
19
+ Utility.update_nodes(ox_element("mrow"), first_value)
21
20
  end
22
21
 
23
22
  def to_omml_without_math_tag(display_style)
24
- lceil = Symbol.new("⌈")
25
- rceil = Symbol.new("⌉")
23
+ lceil = Symbol.new("⌈") unless open_paren
24
+ rceil = Symbol.new("⌉") unless close_paren
26
25
  fenced = Fenced.new(lceil, Array(parameter_one), rceil)
27
26
  Array(fenced.to_omml_without_math_tag(display_style))
28
27
  end
@@ -31,6 +30,22 @@ module Plurimath
31
30
  first_value = "<i>#{parameter_one.to_html}</i>" if parameter_one
32
31
  "<i>&#x2308;</i>#{first_value}<i>&#x2309;</i>"
33
32
  end
33
+
34
+ def line_breaking(obj)
35
+ parameter_one.line_breaking(obj)
36
+ if obj.value_exist?
37
+ ceil_object = self.class.new(Utility.filter_values(obj.value))
38
+ ceil_object.open_paren = true
39
+ ceil_object.close_paren = false
40
+ obj.update(ceil_object)
41
+ self.close_paren = true
42
+ self.open_paren = false unless open_paren
43
+ end
44
+ end
45
+
46
+ def paren_node(value)
47
+ ox_element("mo") << value
48
+ end
34
49
  end
35
50
  end
36
51
  end
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Color < BinaryFunction
9
+ FUNCTION = {
10
+ name: "color",
11
+ first_value: "mathcolor",
12
+ second_value: "text",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  first_value = "(#{parameter_one&.to_asciimath&.gsub(/\s/, '')})"
11
17
  second_value = "(#{parameter_two&.to_asciimath})"
@@ -31,6 +37,14 @@ module Plurimath
31
37
  def to_omml_without_math_tag(display_style)
32
38
  Array(parameter_two.insert_t_tag(display_style))
33
39
  end
40
+
41
+ def to_omml_math_zone(spacing, last = false, _, display_style:)
42
+ parameters = self.class::FUNCTION
43
+ new_spacing = gsub_spacing(spacing, last)
44
+ new_arr = ["#{spacing}\"#{dump_omml(self, display_style)}\" #{parameters[:name]}\n"]
45
+ omml_fields_to_print(parameter_two, { spacing: new_spacing, field_name: "text", additional_space: "| |_ ", array: new_arr, display_style: display_style })
46
+ new_arr
47
+ end
34
48
  end
35
49
  end
36
50
  end
@@ -21,7 +21,7 @@ module Plurimath
21
21
  )
22
22
  end
23
23
 
24
- def to_omml_without_math_tag(display_style)
24
+ def to_omml_without_math_tag(_)
25
25
  return r_element("..", rpr_tag: false) unless parameter_one
26
26
 
27
27
  symbol = Symbol.new("..")
@@ -32,6 +32,11 @@ module Plurimath
32
32
  first_value = "<i>#{parameter_one.to_html}</i>" if parameter_one
33
33
  "#{first_value}<i>..</i>"
34
34
  end
35
+
36
+ def line_breaking(obj)
37
+ parameter_one&.line_breaking(obj)
38
+ obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -11,7 +11,10 @@ module Plurimath
11
11
  end
12
12
 
13
13
  def to_omml_without_math_tag(display_style)
14
- [r_element("deg", rpr_tag: false), omml_value(display_style)]
14
+ array = []
15
+ array << r_element("deg", rpr_tag: false) unless hide_function_name
16
+ array += Array(omml_value(display_style))
17
+ array
15
18
  end
16
19
  end
17
20
  end
@@ -11,7 +11,10 @@ module Plurimath
11
11
  end
12
12
 
13
13
  def to_omml_without_math_tag(display_style)
14
- [r_element("det", rpr_tag: false), omml_value(display_style)]
14
+ array = []
15
+ array << r_element("det", rpr_tag: false) unless hide_function_name
16
+ array += Array(omml_value(display_style))
17
+ array
15
18
  end
16
19
  end
17
20
  end
@@ -11,7 +11,10 @@ module Plurimath
11
11
  end
12
12
 
13
13
  def to_omml_without_math_tag(display_style)
14
- [r_element("dim", rpr_tag: false), omml_value(display_style)]
14
+ array = []
15
+ array << r_element("dim", rpr_tag: false) unless hide_function_name
16
+ array += Array(omml_value(display_style))
17
+ array
15
18
  end
16
19
  end
17
20
  end
@@ -41,6 +41,11 @@ module Plurimath
41
41
  end
42
42
  end
43
43
 
44
+ def line_breaking(obj)
45
+ parameter_one&.line_breaking(obj)
46
+ obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
47
+ end
48
+
44
49
  protected
45
50
 
46
51
  def acc_tag(display_style)
@@ -11,7 +11,10 @@ module Plurimath
11
11
  end
12
12
 
13
13
  def to_omml_without_math_tag(display_style)
14
- [r_element("exp", rpr_tag: false), omml_value(display_style)]
14
+ array = []
15
+ array << r_element("exp", rpr_tag: false) unless hide_function_name
16
+ array += Array(omml_value(display_style))
17
+ array
15
18
  end
16
19
  end
17
20
  end