plurimath 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +13 -0
- data/.github/workflows/release.yml +22 -0
- data/.gitignore +1 -0
- data/.hound.yml +5 -0
- data/.rubocop.yml +8 -0
- data/AsciiMath-Supported-Data.adoc +2000 -0
- data/Gemfile +3 -0
- data/Latex-Supported-Data.adoc +1879 -0
- data/MathML-Supported-Data.adoc +287 -0
- data/README.adoc +96 -0
- data/lib/plurimath/asciimath/constants.rb +267 -229
- data/lib/plurimath/asciimath/parse.rb +125 -26
- data/lib/plurimath/asciimath/parser.rb +6 -3
- data/lib/plurimath/asciimath/transform.rb +1135 -208
- data/lib/plurimath/asciimath.rb +1 -1
- data/lib/plurimath/html/constants.rb +50 -0
- data/lib/plurimath/html/parse.rb +149 -0
- data/lib/plurimath/html/parser.rb +26 -0
- data/lib/plurimath/html/transform.rb +363 -0
- data/lib/plurimath/html.rb +1 -1
- data/lib/plurimath/latex/constants.rb +3729 -1906
- data/lib/plurimath/latex/parse.rb +167 -51
- data/lib/plurimath/latex/parser.rb +12 -4
- data/lib/plurimath/latex/transform.rb +598 -183
- data/lib/plurimath/math/base.rb +15 -0
- data/lib/plurimath/math/formula.rb +96 -11
- data/lib/plurimath/math/function/bar.rb +34 -0
- data/lib/plurimath/math/function/base.rb +32 -5
- data/lib/plurimath/math/function/binary_function.rb +104 -17
- data/lib/plurimath/math/function/cancel.rb +8 -0
- data/lib/plurimath/math/function/ceil.rb +3 -0
- data/lib/plurimath/math/function/color.rb +16 -6
- data/lib/plurimath/math/function/f.rb +8 -0
- data/lib/plurimath/math/function/fenced.rb +95 -3
- data/lib/plurimath/math/function/floor.rb +15 -0
- data/lib/plurimath/math/function/font_style/bold.rb +37 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +37 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +37 -0
- data/lib/plurimath/math/function/font_style/italic.rb +37 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +37 -0
- data/lib/plurimath/math/function/font_style/normal.rb +37 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +37 -0
- data/lib/plurimath/math/function/font_style/script.rb +37 -0
- data/lib/plurimath/math/function/font_style.rb +18 -25
- data/lib/plurimath/math/function/frac.rb +35 -5
- data/lib/plurimath/math/function/g.rb +7 -0
- data/lib/plurimath/math/function/hat.rb +12 -0
- data/lib/plurimath/math/function/inf.rb +21 -1
- data/lib/plurimath/math/function/int.rb +23 -2
- data/lib/plurimath/math/function/left.rb +25 -4
- data/lib/plurimath/math/function/lim.rb +40 -2
- data/lib/plurimath/math/function/limits.rb +8 -0
- data/lib/plurimath/math/function/log.rb +61 -4
- data/lib/plurimath/math/function/longdiv.rb +12 -0
- data/lib/plurimath/math/function/mbox.rb +31 -0
- data/lib/plurimath/math/function/menclose.rb +46 -0
- data/lib/plurimath/math/function/merror.rb +12 -0
- data/lib/plurimath/math/function/mod.rb +25 -4
- data/lib/plurimath/math/function/msgroup.rb +37 -0
- data/lib/plurimath/math/function/msline.rb +12 -0
- data/lib/plurimath/math/function/multiscript.rb +30 -0
- data/lib/plurimath/math/function/norm.rb +18 -1
- data/lib/plurimath/math/function/obrace.rb +17 -0
- data/lib/plurimath/math/function/oint.rb +2 -2
- data/lib/plurimath/math/function/over.rb +36 -0
- data/lib/plurimath/math/function/overset.rb +36 -7
- data/lib/plurimath/math/function/phantom.rb +28 -0
- data/lib/plurimath/math/function/power.rb +33 -9
- data/lib/plurimath/math/function/power_base.rb +110 -5
- data/lib/plurimath/math/function/prod.rb +29 -2
- data/lib/plurimath/math/function/right.rb +44 -0
- data/lib/plurimath/math/function/root.rb +27 -4
- data/lib/plurimath/math/function/rule.rb +33 -0
- data/lib/plurimath/math/function/scarries.rb +12 -0
- data/lib/plurimath/math/function/scarry.rb +12 -0
- data/lib/plurimath/math/function/sqrt.rb +24 -2
- data/lib/plurimath/math/function/stackrel.rb +27 -0
- data/lib/plurimath/math/function/substack.rb +7 -1
- data/lib/plurimath/math/function/sum.rb +56 -2
- data/lib/plurimath/math/function/sup.rb +3 -0
- data/lib/plurimath/math/function/table/align.rb +24 -0
- data/lib/plurimath/math/function/table/array.rb +44 -0
- data/lib/plurimath/math/function/table/bmatrix.rb +37 -0
- data/lib/plurimath/math/function/table/matrix.rb +32 -0
- data/lib/plurimath/math/function/table/multline.rb +24 -0
- data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
- data/lib/plurimath/math/function/table/split.rb +24 -0
- data/lib/plurimath/math/function/table/vmatrix.rb +24 -0
- data/lib/plurimath/math/function/table.rb +190 -20
- data/lib/plurimath/math/function/td.rb +27 -9
- data/lib/plurimath/math/function/ternary_function.rb +83 -8
- data/lib/plurimath/math/function/text.rb +45 -8
- data/lib/plurimath/math/function/tr.rb +28 -4
- data/lib/plurimath/math/function/ubrace.rb +17 -0
- data/lib/plurimath/math/function/ul.rb +29 -0
- data/lib/plurimath/math/function/unary_function.rb +85 -7
- data/lib/plurimath/math/function/underline.rb +12 -0
- data/lib/plurimath/math/function/underover.rb +107 -0
- data/lib/plurimath/math/function/underset.rb +39 -0
- data/lib/plurimath/math/function/vec.rb +10 -0
- data/lib/plurimath/math/function.rb +13 -2
- data/lib/plurimath/math/number.rb +11 -3
- data/lib/plurimath/math/symbol.rb +57 -9
- data/lib/plurimath/math/unicode.rb +11 -0
- data/lib/plurimath/math.rb +15 -6
- data/lib/plurimath/mathml/constants.rb +224 -179
- data/lib/plurimath/mathml/parser.rb +24 -7
- data/lib/plurimath/mathml/transform.rb +249 -148
- data/lib/plurimath/mathml.rb +1 -1
- data/lib/plurimath/omml/parser.rb +42 -0
- data/lib/plurimath/omml/transform.rb +278 -0
- data/lib/plurimath/omml.rb +1 -1
- data/lib/plurimath/unitsml.rb +4 -0
- data/lib/plurimath/utility.rb +395 -0
- data/lib/plurimath/version.rb +1 -1
- data/plurimath.gemspec +1 -0
- metadata +66 -9
- data/.github/workflows/test.yml +0 -36
- data/README.md +0 -40
- 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
|
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
|
-
|
11
|
-
|
12
|
-
third_value
|
13
|
-
"
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
36
|
-
|
37
|
-
|
202
|
+
def norm_table(table_tag)
|
203
|
+
mo_tag = Utility.ox_element("mo") << "∥"
|
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 "
|
3
|
+
require_relative "binary_function"
|
4
4
|
|
5
5
|
module Plurimath
|
6
6
|
module Math
|
7
7
|
module Function
|
8
|
-
class Td <
|
8
|
+
class Td < BinaryFunction
|
9
9
|
def to_asciimath
|
10
|
-
|
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
|
-
"
|
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.
|
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,
|
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
|
17
|
-
second_value = "_
|
18
|
-
third_value = "
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
27
|
-
|
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
|
-
|
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, "⎯")
|
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
|
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") << "⏟")
|
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") << "¯",
|
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
|