plurimath 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +13 -0
  3. data/.github/workflows/release.yml +22 -0
  4. data/.gitignore +1 -0
  5. data/.hound.yml +5 -0
  6. data/.rubocop.yml +8 -0
  7. data/AsciiMath-Supported-Data.adoc +2000 -0
  8. data/Gemfile +3 -0
  9. data/Latex-Supported-Data.adoc +1879 -0
  10. data/MathML-Supported-Data.adoc +287 -0
  11. data/README.adoc +96 -0
  12. data/lib/plurimath/asciimath/constants.rb +267 -229
  13. data/lib/plurimath/asciimath/parse.rb +125 -26
  14. data/lib/plurimath/asciimath/parser.rb +6 -3
  15. data/lib/plurimath/asciimath/transform.rb +1135 -208
  16. data/lib/plurimath/asciimath.rb +1 -1
  17. data/lib/plurimath/html/constants.rb +50 -0
  18. data/lib/plurimath/html/parse.rb +149 -0
  19. data/lib/plurimath/html/parser.rb +26 -0
  20. data/lib/plurimath/html/transform.rb +363 -0
  21. data/lib/plurimath/html.rb +1 -1
  22. data/lib/plurimath/latex/constants.rb +3729 -1906
  23. data/lib/plurimath/latex/parse.rb +167 -51
  24. data/lib/plurimath/latex/parser.rb +12 -4
  25. data/lib/plurimath/latex/transform.rb +598 -183
  26. data/lib/plurimath/math/base.rb +15 -0
  27. data/lib/plurimath/math/formula.rb +96 -11
  28. data/lib/plurimath/math/function/bar.rb +34 -0
  29. data/lib/plurimath/math/function/base.rb +32 -5
  30. data/lib/plurimath/math/function/binary_function.rb +104 -17
  31. data/lib/plurimath/math/function/cancel.rb +8 -0
  32. data/lib/plurimath/math/function/ceil.rb +3 -0
  33. data/lib/plurimath/math/function/color.rb +16 -6
  34. data/lib/plurimath/math/function/f.rb +8 -0
  35. data/lib/plurimath/math/function/fenced.rb +95 -3
  36. data/lib/plurimath/math/function/floor.rb +15 -0
  37. data/lib/plurimath/math/function/font_style/bold.rb +37 -0
  38. data/lib/plurimath/math/function/font_style/double_struck.rb +37 -0
  39. data/lib/plurimath/math/function/font_style/fraktur.rb +37 -0
  40. data/lib/plurimath/math/function/font_style/italic.rb +37 -0
  41. data/lib/plurimath/math/function/font_style/monospace.rb +37 -0
  42. data/lib/plurimath/math/function/font_style/normal.rb +37 -0
  43. data/lib/plurimath/math/function/font_style/sans-serif.rb +37 -0
  44. data/lib/plurimath/math/function/font_style/script.rb +37 -0
  45. data/lib/plurimath/math/function/font_style.rb +18 -25
  46. data/lib/plurimath/math/function/frac.rb +35 -5
  47. data/lib/plurimath/math/function/g.rb +7 -0
  48. data/lib/plurimath/math/function/hat.rb +12 -0
  49. data/lib/plurimath/math/function/inf.rb +21 -1
  50. data/lib/plurimath/math/function/int.rb +23 -2
  51. data/lib/plurimath/math/function/left.rb +25 -4
  52. data/lib/plurimath/math/function/lim.rb +40 -2
  53. data/lib/plurimath/math/function/limits.rb +8 -0
  54. data/lib/plurimath/math/function/log.rb +61 -4
  55. data/lib/plurimath/math/function/longdiv.rb +12 -0
  56. data/lib/plurimath/math/function/mbox.rb +31 -0
  57. data/lib/plurimath/math/function/menclose.rb +46 -0
  58. data/lib/plurimath/math/function/merror.rb +12 -0
  59. data/lib/plurimath/math/function/mod.rb +25 -4
  60. data/lib/plurimath/math/function/msgroup.rb +37 -0
  61. data/lib/plurimath/math/function/msline.rb +12 -0
  62. data/lib/plurimath/math/function/multiscript.rb +30 -0
  63. data/lib/plurimath/math/function/norm.rb +18 -1
  64. data/lib/plurimath/math/function/obrace.rb +17 -0
  65. data/lib/plurimath/math/function/oint.rb +2 -2
  66. data/lib/plurimath/math/function/over.rb +36 -0
  67. data/lib/plurimath/math/function/overset.rb +36 -7
  68. data/lib/plurimath/math/function/phantom.rb +28 -0
  69. data/lib/plurimath/math/function/power.rb +33 -9
  70. data/lib/plurimath/math/function/power_base.rb +110 -5
  71. data/lib/plurimath/math/function/prod.rb +29 -2
  72. data/lib/plurimath/math/function/right.rb +44 -0
  73. data/lib/plurimath/math/function/root.rb +27 -4
  74. data/lib/plurimath/math/function/rule.rb +33 -0
  75. data/lib/plurimath/math/function/scarries.rb +12 -0
  76. data/lib/plurimath/math/function/scarry.rb +12 -0
  77. data/lib/plurimath/math/function/sqrt.rb +24 -2
  78. data/lib/plurimath/math/function/stackrel.rb +27 -0
  79. data/lib/plurimath/math/function/substack.rb +7 -1
  80. data/lib/plurimath/math/function/sum.rb +56 -2
  81. data/lib/plurimath/math/function/sup.rb +3 -0
  82. data/lib/plurimath/math/function/table/align.rb +24 -0
  83. data/lib/plurimath/math/function/table/array.rb +44 -0
  84. data/lib/plurimath/math/function/table/bmatrix.rb +37 -0
  85. data/lib/plurimath/math/function/table/matrix.rb +32 -0
  86. data/lib/plurimath/math/function/table/multline.rb +24 -0
  87. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  88. data/lib/plurimath/math/function/table/split.rb +24 -0
  89. data/lib/plurimath/math/function/table/vmatrix.rb +24 -0
  90. data/lib/plurimath/math/function/table.rb +190 -20
  91. data/lib/plurimath/math/function/td.rb +27 -9
  92. data/lib/plurimath/math/function/ternary_function.rb +83 -8
  93. data/lib/plurimath/math/function/text.rb +45 -8
  94. data/lib/plurimath/math/function/tr.rb +28 -4
  95. data/lib/plurimath/math/function/ubrace.rb +17 -0
  96. data/lib/plurimath/math/function/ul.rb +29 -0
  97. data/lib/plurimath/math/function/unary_function.rb +85 -7
  98. data/lib/plurimath/math/function/underline.rb +12 -0
  99. data/lib/plurimath/math/function/underover.rb +107 -0
  100. data/lib/plurimath/math/function/underset.rb +39 -0
  101. data/lib/plurimath/math/function/vec.rb +10 -0
  102. data/lib/plurimath/math/function.rb +13 -2
  103. data/lib/plurimath/math/number.rb +11 -3
  104. data/lib/plurimath/math/symbol.rb +57 -9
  105. data/lib/plurimath/math/unicode.rb +11 -0
  106. data/lib/plurimath/math.rb +15 -6
  107. data/lib/plurimath/mathml/constants.rb +224 -179
  108. data/lib/plurimath/mathml/parser.rb +24 -7
  109. data/lib/plurimath/mathml/transform.rb +249 -148
  110. data/lib/plurimath/mathml.rb +1 -1
  111. data/lib/plurimath/omml/parser.rb +42 -0
  112. data/lib/plurimath/omml/transform.rb +278 -0
  113. data/lib/plurimath/omml.rb +1 -1
  114. data/lib/plurimath/unitsml.rb +4 -0
  115. data/lib/plurimath/utility.rb +395 -0
  116. data/lib/plurimath/version.rb +1 -1
  117. data/plurimath.gemspec +1 -0
  118. metadata +66 -9
  119. data/.github/workflows/test.yml +0 -36
  120. data/README.md +0 -40
  121. data/lib/plurimath/mathml/parse.rb +0 -63
@@ -5,36 +5,206 @@ require_relative "ternary_function"
5
5
  module Plurimath
6
6
  module Math
7
7
  module Function
8
- class Table < TernaryFunction
8
+ class Table
9
+ attr_accessor :value, :open_paren, :close_paren, :options
10
+
11
+ def initialize(value = nil,
12
+ open_paren = nil,
13
+ close_paren = nil,
14
+ options = {})
15
+ @value = value
16
+ @open_paren = open_paren
17
+ @close_paren = close_paren
18
+ @options = options
19
+ end
20
+
21
+ def ==(object)
22
+ object.class == self.class &&
23
+ object.value == value &&
24
+ object.options == options &&
25
+ object.open_paren == open_paren &&
26
+ object.close_paren == close_paren
27
+ end
28
+
9
29
  def to_asciimath
10
- first_value = parameter_one.map(&:to_asciimath).join(",")
11
- second_value = parameter_two.nil? ? "[" : parameter_two
12
- third_value = parameter_three.nil? ? "]" : parameter_three
13
- "#{second_value}#{first_value}#{third_value}"
30
+ parenthesis = Asciimath::Constants::TABLE_PARENTHESIS
31
+ first_value = value.map(&:to_asciimath).join(", ")
32
+ third_value = close_paren.is_a?(::Array) || close_paren.nil?
33
+ lparen = open_paren.nil? ? "[" : open_paren
34
+ rparen = third_value ? parenthesis[lparen.to_sym] : close_paren
35
+ "#{lparen}#{first_value}#{rparen}"
14
36
  end
15
37
 
16
38
  def to_mathml_without_math_tag
17
- table_value = parameter_one.map(&:to_mathml_without_math_tag).join
18
- if Latex::Constants::PARENTHESIS.key?(parameter_two) || parameter_two == "|"
19
- "<mfenced open='#{parameter_two}' close='#{parameter_three}'>"\
20
- "<mtable>#{table_value}</mtable></mfenced>"
21
- elsif parameter_two == "norm["
22
- "<mo>&#x2225;</mo>#{table_value}<mo>&#x2225;</mo>"
23
- else
24
- "<mtable>#{table_value}</mtable>"
39
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
40
+ Utility.update_nodes(
41
+ table_tag,
42
+ value&.map(&:to_mathml_without_math_tag),
43
+ )
44
+ return norm_table(table_tag) if open_paren == "norm["
45
+
46
+ if present?(open_paren) || present?(close_paren)
47
+ first_paren = Utility.ox_element("mo") << mathml_parenthesis(open_paren)
48
+ second_paren = Utility.ox_element("mo") << mathml_parenthesis(close_paren)
49
+ mrow_tag = Utility.ox_element("mrow")
50
+ return Utility.update_nodes(mrow_tag, [first_paren, table_tag, second_paren])
25
51
  end
52
+
53
+ table_tag
26
54
  end
27
55
 
28
56
  def to_latex
29
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
30
- environment = latex_environment
31
- divider = "{#{parameter_three&.map(&:to_latex).join}}" if environment == "array"
32
- "\\begin{#{environment}}#{divider}#{first_value}\\end{#{environment}}"
57
+ if open_paren == "norm["
58
+ return "\\begin{Vmatrix}#{latex_content}\\end{Vmatrix}"
59
+ end
60
+
61
+ separator = "{#{table_attribute(:latex)}}" if environment&.include?("array")
62
+ left_paren = latex_parenthesis(open_paren) || "."
63
+ right_paren = latex_parenthesis(close_paren) || "."
64
+ left = "\\left #{left_paren}\\begin{matrix}"
65
+ right = "\\end{matrix}\\right #{right_paren}"
66
+ "#{left}#{separator}#{latex_content}#{right}"
67
+ end
68
+
69
+ def to_html
70
+ first_value = value.map(&:to_html).join
71
+ "<table>#{first_value}</table>"
72
+ end
73
+
74
+ def to_omml_without_math_tag
75
+ if value.map { |d| d.parameter_one.length == 1 }.all?
76
+ single_td_table
77
+ else
78
+ multiple_td_table
79
+ end
80
+ end
81
+
82
+ def class_name
83
+ self.class.name.split("::").last.downcase
84
+ end
85
+
86
+ protected
87
+
88
+ def present?(field)
89
+ !(field.nil? || field.empty?)
90
+ end
91
+
92
+ def mathml_parenthesis(field)
93
+ return "" if field&.include?(":")
94
+
95
+ present?(field) ? field : ""
96
+ end
97
+
98
+ def latex_parenthesis(field)
99
+ return " ." if field&.include?(":")
100
+
101
+ return "\\#{field}" if ["{", "}"].include?(field)
102
+
103
+ field
104
+ end
105
+
106
+ def table_attribute(type = :mathml)
107
+ column_string = column_lines
108
+ case type
109
+ when :mathml
110
+ mathml_attrs(column_string)
111
+ when :latex
112
+ column_string.insert(0, "none") if column_string.include?("solid")
113
+ column_string&.map { |d| d == "solid" ? "|" : "a" }&.join
114
+ end
115
+ end
116
+
117
+ def column_lines
118
+ columns_array = []
119
+ value.first.parameter_one.each_with_index do |td, i|
120
+ if td.parameter_one.find { |obj| Utility.symbol_value(obj, "|") }
121
+ columns_array.empty? ? columns_array = ["solid"] : columns_array[i - 1] = "solid"
122
+ else
123
+ columns_array << "none"
124
+ end
125
+ end
126
+ columns_array
127
+ end
128
+
129
+ def mathml_attrs(column_strings)
130
+ args = options&.dup&.reject { |arg| arg.to_s == "asterisk" }
131
+ args[:columnlines] = column_strings.join(" ") if column_strings.include?("solid")
132
+ args
133
+ end
134
+
135
+ def latex_content
136
+ value&.map(&:to_latex)&.join(" \\\\ ")
137
+ end
138
+
139
+ def matrix_class
140
+ matrix = if open_paren
141
+ Latex::Constants::MATRICES.invert[open_paren]
142
+ else
143
+ class_name
144
+ end
145
+ options&.key?(:asterisk) ? "{#{matrix}*}" : "{#{matrix}}"
146
+ end
147
+
148
+ def opening
149
+ "#{matrix_class}#{latex_columnalign}"
150
+ end
151
+
152
+ def latex_columnalign
153
+ return "" unless Hash(options)[:asterisk]
154
+
155
+ columnalign = Hash(value&.first&.parameter_one&.first&.parameter_two)[:columnalign]
156
+ "[#{Utility::ALIGNMENT_LETTERS.invert[columnalign]}]"
157
+ end
158
+
159
+ def environment
160
+ matrices_hash = Latex::Constants::MATRICES
161
+ matric_value = matrices_hash.value?(open_paren)
162
+ matrices_hash.invert[open_paren].to_s if matric_value
163
+ end
164
+
165
+ def single_td_table
166
+ eqarr = Utility.ox_element("eqArr", namespace: "m")
167
+ eqarrpr = Utility.ox_element("eqArrPr", namespace: "m")
168
+ eqarrpr << Utility.pr_element("ctrl", true, namespace: "m")
169
+ eqarr << eqarrpr
170
+ tr_value = value.map(&:to_omml_without_math_tag).flatten
171
+ Utility.update_nodes(eqarr, tr_value.compact)
172
+ end
173
+
174
+ def multiple_td_table
175
+ count = { "m:val": value&.first&.parameter_one&.count }
176
+ mcjc = { "m:val": "center" }
177
+ mm = Utility.ox_element("m", namespace: "m")
178
+ mpr = Utility.ox_element("mpr", namespace: "m")
179
+ mcs = Utility.ox_element("mcs", namespace: "m")
180
+ mc = Utility.ox_element("mc", namespace: "m")
181
+ mcpr = Utility.ox_element("mcPr", namespace: "m")
182
+ mcount = Utility.ox_element(
183
+ "count",
184
+ namespace: "m",
185
+ attributes: count,
186
+ )
187
+ mcjc = Utility.ox_element(
188
+ "mcJc",
189
+ namespace: "m",
190
+ attributes: mcjc,
191
+ )
192
+ ctrlpr = Utility.pr_element("ctrl", true, namespace: "m")
193
+ Utility.update_nodes(mcpr, [mcount, mcjc])
194
+ mc << mcpr
195
+ mcs << mc
196
+ mpr << mcs
197
+ mpr << ctrlpr
198
+ mm_value = value&.map(&:to_omml_without_math_tag)
199
+ Utility.update_nodes(mm, mm_value.insert(0, mpr).flatten)
33
200
  end
34
201
 
35
- def latex_environment
36
- matrices_hash = Latex::Constants::ENVIRONMENTS
37
- matrices_hash.invert[parameter_two] if matrices_hash.value?(parameter_two)
202
+ def norm_table(table_tag)
203
+ mo_tag = Utility.ox_element("mo") << "&#x2225;"
204
+ Utility.update_nodes(
205
+ Utility.ox_element("mrow"),
206
+ [mo_tag, table_tag, mo_tag],
207
+ )
38
208
  end
39
209
  end
40
210
  end
@@ -1,25 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "unary_function"
3
+ require_relative "binary_function"
4
4
 
5
5
  module Plurimath
6
6
  module Math
7
7
  module Function
8
- class Td < UnaryFunction
8
+ class Td < BinaryFunction
9
9
  def to_asciimath
10
- if parameter_one.length > 1
11
- "[#{parameter_one.map(&:to_asciimath).join(',')}]"
12
- else
13
- "#{parameter_one.map(&:to_asciimath).join(',')}"
14
- end
10
+ parameter_one.map(&:to_asciimath).join(" ")
15
11
  end
16
12
 
17
13
  def to_mathml_without_math_tag
18
- "<mtd>#{parameter_one.map(&:to_mathml_without_math_tag).join}</mtd>"
14
+ return "" if Utility.symbol_value(parameter_one.first, "|")
15
+
16
+ td_attribute = parameter_two if parameter_two&.any?
17
+
18
+ Utility.update_nodes(
19
+ Utility.ox_element("mtd", attributes: td_attribute),
20
+ parameter_one.map(&:to_mathml_without_math_tag),
21
+ )
19
22
  end
20
23
 
21
24
  def to_latex
22
- parameter_one.map(&:to_latex).join
25
+ return "" if Utility.symbol_value(parameter_one.first, "|")
26
+
27
+ parameter_one.map(&:to_latex).join(" ")
28
+ end
29
+
30
+ def to_html
31
+ first_value = parameter_one.map(&:to_html).join
32
+ "<td>#{first_value}</td>"
33
+ end
34
+
35
+ def to_omml_without_math_tag
36
+ me = Utility.ox_element("e", namespace: "m")
37
+ Utility.update_nodes(
38
+ me,
39
+ parameter_one&.map(&:to_omml_without_math_tag),
40
+ )
23
41
  end
24
42
  end
25
43
  end
@@ -6,16 +6,18 @@ module Plurimath
6
6
  class TernaryFunction
7
7
  attr_accessor :parameter_one, :parameter_two, :parameter_three
8
8
 
9
- def initialize(parameter_one = nil, parameter_two = nil, parameter_three = nil)
9
+ def initialize(parameter_one = nil,
10
+ parameter_two = nil,
11
+ parameter_three = nil)
10
12
  @parameter_one = parameter_one
11
13
  @parameter_two = parameter_two
12
14
  @parameter_three = parameter_three
13
15
  end
14
16
 
15
17
  def to_asciimath
16
- first_value = parameter_one.to_asciimath if parameter_one
17
- second_value = "_(#{parameter_two.to_asciimath})" if parameter_two
18
- third_value = "^(#{parameter_three.to_asciimath})" if parameter_three
18
+ first_value = first_field_wrap(parameter_one) if parameter_one
19
+ second_value = "_#{wrapped(parameter_two)}" if parameter_two
20
+ third_value = "^#{wrapped(parameter_three)}" if parameter_three
19
21
  "#{first_value}#{second_value}#{third_value}"
20
22
  end
21
23
 
@@ -27,15 +29,88 @@ module Plurimath
27
29
  end
28
30
 
29
31
  def to_mathml_without_math_tag
30
- first_value = parameter_one.to_mathml_without_math_tag if parameter_one
31
- second_value = parameter_two.to_mathml_without_math_tag if parameter_two
32
- third_value = parameter_three.to_mathml_without_math_tag if parameter_three
33
- "<m#{class_name}>#{first_value}#{second_value}#{third_value}</m#{class_name}>"
32
+ value_arr = [parameter_one&.to_mathml_without_math_tag]
33
+ value_arr << parameter_two&.to_mathml_without_math_tag
34
+ value_arr << parameter_three&.to_mathml_without_math_tag
35
+ class_tag = Utility.ox_element("m#{class_name}")
36
+ Utility.update_nodes(class_tag, value_arr)
37
+ end
38
+
39
+ def to_latex
40
+ first_value = parameter_one&.to_latex
41
+ second_value = parameter_two&.to_latex
42
+ third_value = parameter_three&.to_latex
43
+ "#{first_value}#{second_value}#{third_value}"
44
+ end
45
+
46
+ def to_html
47
+ first_value = "<i>#{parameter_one.to_html}</i>" if parameter_one
48
+ second_value = "<i>#{parameter_two.to_html}</i>" if parameter_two
49
+ third_value = "<i>#{parameter_three.to_html}</i>" if parameter_three
50
+ "#{first_value}#{second_value}#{third_value}"
51
+ end
52
+
53
+ def to_omml_without_math_tag
54
+ r_tag = Utility.ox_element("r", namespace: "m")
55
+ r_tag << omml_value(parameter_one) if parameter_one
56
+ r_tag << omml_value(parameter_two) if parameter_two
57
+ r_tag << omml_value(parameter_three) if parameter_three
58
+ r_tag
34
59
  end
35
60
 
36
61
  def class_name
37
62
  self.class.name.split("::").last.downcase
38
63
  end
64
+
65
+ protected
66
+
67
+ def omml_value(field)
68
+ case field
69
+ when Array
70
+ field.compact.map(&:to_omml_without_math_tag)
71
+ else
72
+ t_tag = Utility.ox_element("t", namespace: "m")
73
+ first_value = field.to_omml_without_math_tag
74
+ first_value = (t_tag << first_value) if field.is_a?(Symbol)
75
+ first_value
76
+ end
77
+ end
78
+
79
+ def wrapped(field, type: "ascii")
80
+ return "" unless field
81
+
82
+ type == "ascii" ? "(#{field.to_asciimath})" : "{#{field.to_latex}}"
83
+ end
84
+
85
+ def first_field_wrap(field, type: "ascii")
86
+ return "" unless field
87
+
88
+ type == "ascii" ? ascii_wrap(field) : latex_wrap(field)
89
+ end
90
+
91
+ def ascii_wrap(field)
92
+ asciimath = field.to_asciimath
93
+ return latex if ["obrace", "ubrace"].include?(field.class_name)
94
+
95
+ case field
96
+ when Formula || field.class.name.include?("Function")
97
+ "(#{asciimath})"
98
+ else
99
+ asciimath
100
+ end
101
+ end
102
+
103
+ def latex_wrap(field)
104
+ latex = field.to_latex
105
+ return latex if ["obrace", "ubrace"].include?(field.class_name)
106
+
107
+ case field
108
+ when Formula || field.class.name.include?("Function")
109
+ "{#{latex}}"
110
+ else
111
+ latex
112
+ end
113
+ end
39
114
  end
40
115
  end
41
116
  end
@@ -1,30 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "htmlentities"
3
4
  require_relative "unary_function"
4
5
 
5
6
  module Plurimath
6
7
  module Math
7
8
  module Function
8
9
  class Text < UnaryFunction
10
+ PARSER_REGEX = %r{unicode\[:(?<unicode>\w{1,})\]}.freeze
11
+
9
12
  def to_asciimath
10
- "\"#{parameter_one}\""
13
+ "\"#{parse_text('asciimath') || parameter_one}\""
11
14
  end
12
15
 
13
16
  def to_mathml_without_math_tag
14
- regex_exp = %r{unicode\[:(?<unicode>\w{1,})\]}
15
- parameter_one.gsub!(regex_exp) do |_text|
16
- symbol_value(Regexp.last_match[:unicode]).to_s
17
- end
18
- "<mtext>#{parameter_one}</mtext>"
17
+ text = Utility.ox_element("mtext")
18
+ text << (parse_text("mathml") || parameter_one) if parameter_one
19
+ end
20
+
21
+ def to_latex
22
+ text_value = parse_text("latex") || parameter_one
23
+ "\\text{#{text_value}}"
24
+ end
25
+
26
+ def to_html
27
+ parse_text("html") || parameter_one
19
28
  end
20
29
 
30
+ def to_omml_without_math_tag
31
+ text = Utility.ox_element("t", namespace: "m")
32
+ text << (parse_text("omml") || parameter_one)
33
+ end
34
+
35
+ protected
36
+
21
37
  def symbol_value(unicode)
22
38
  Mathml::Constants::UNICODE_SYMBOLS.invert[unicode] ||
23
39
  Mathml::Constants::SYMBOLS.invert[unicode]
24
40
  end
25
41
 
26
- def to_latex
27
- parameter_one
42
+ def parse_text(lang)
43
+ html_value = first_value(lang).dup
44
+ html_value&.gsub!(PARSER_REGEX) do |_text|
45
+ last_match = Regexp.last_match
46
+ if ["mathml", "html"].include?(lang)
47
+ symbol_value(last_match[:unicode])
48
+ else
49
+ last_match[:unicode]
50
+ end
51
+ end
52
+ html_value
53
+ end
54
+
55
+ def first_value(lang)
56
+ if lang == "omml"
57
+ entities = HTMLEntities.new
58
+ entities.encode(
59
+ entities.decode(parameter_one),
60
+ :named,
61
+ )
62
+ else
63
+ parameter_one
64
+ end
28
65
  end
29
66
  end
30
67
  end
@@ -7,17 +7,41 @@ module Plurimath
7
7
  module Function
8
8
  class Tr < UnaryFunction
9
9
  def to_asciimath
10
- "[#{parameter_one.map(&:to_asciimath).join(',')}]"
10
+ "[#{parameter_one.map(&:to_asciimath).join(', ')}]"
11
11
  end
12
12
 
13
13
  def to_mathml_without_math_tag
14
- "<mtr>#{parameter_one.map(&:to_mathml_without_math_tag).join}</mtr>"
14
+ first_value = parameter_one.dup
15
+ row_lines = first_value.first.parameter_one
16
+ row_lines.shift if Utility.symbol_value(row_lines.first, "&#x23af;")
17
+ Utility.update_nodes(
18
+ Utility.ox_element("mtr"),
19
+ first_value.map(&:to_mathml_without_math_tag).compact,
20
+ )
15
21
  end
16
22
 
17
23
  def to_latex
18
24
  parameter_one.reject do |td|
19
- td if td.is_a?(Symbol) && td.value == "|"
20
- end.map(&:to_latex).join("&")
25
+ td if Utility.symbol_value(td, "|") || Utility.symbol_value(td.parameter_one.first, "|")
26
+ end.map(&:to_latex).join(" & ")
27
+ end
28
+
29
+ def to_html
30
+ first_value = parameter_one.map(&:to_html).join
31
+ "<tr>#{first_value}</tr>"
32
+ end
33
+
34
+ def to_omml_without_math_tag
35
+ omml_content = parameter_one&.map(&:to_omml_without_math_tag)
36
+ if parameter_one.count.eql?(1)
37
+ omml_content
38
+ else
39
+ mr = Utility.ox_element("mr", namespace: "m")
40
+ Utility.update_nodes(
41
+ mr,
42
+ omml_content,
43
+ )
44
+ end
21
45
  end
22
46
  end
23
47
  end
@@ -6,7 +6,24 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Ubrace < UnaryFunction
9
+ def to_latex
10
+ first_value = "{#{parameter_one.to_latex}}" if parameter_one
11
+ "\\underbrace#{first_value}"
12
+ end
13
+
14
+ def to_mathml_without_math_tag
15
+ mo_tag = (Utility.ox_element("mo") << "&#x23df;")
16
+ if parameter_one
17
+ over_tag = Utility.ox_element("munder")
18
+ arr_value = mathml_value
19
+ Utility.update_nodes(over_tag, (arr_value << mo_tag))
20
+ else
21
+ mo_tag
22
+ end
23
+ end
9
24
  end
25
+
26
+ Underbrace = Ubrace
10
27
  end
11
28
  end
12
29
  end
@@ -6,6 +6,35 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Ul < UnaryFunction
9
+ def to_mathml_without_math_tag
10
+ first_value = parameter_one&.to_mathml_without_math_tag
11
+ Utility.update_nodes(
12
+ Utility.ox_element("munder"),
13
+ [
14
+ first_value,
15
+ Utility.ox_element("mo") << "&#xaf;",
16
+ ],
17
+ )
18
+ end
19
+
20
+ def to_omml_without_math_tag
21
+ bar = Utility.ox_element("bar", namespace: "m")
22
+ barpr = Utility.ox_element("barPr", namespace: "m")
23
+ barpr << Utility.pr_element("ctrl", true, namespace: "m")
24
+ me = Utility.ox_element("e", namespace: "m")
25
+ me << parameter_one.to_omml_without_math_tag
26
+ Utility.update_nodes(
27
+ bar,
28
+ [
29
+ barpr,
30
+ me,
31
+ ],
32
+ )
33
+ end
34
+
35
+ def class_name
36
+ "underline"
37
+ end
9
38
  end
10
39
  end
11
40
  end