plurimath 0.2.1 → 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/.hound.yml +5 -0
- data/.rubocop.yml +8 -0
- data/AsciiMath-Supported-Data.adoc +1994 -274
- data/Gemfile +2 -0
- data/Latex-Supported-Data.adoc +1875 -1868
- data/MathML-Supported-Data.adoc +280 -263
- data/README.adoc +22 -20
- data/lib/plurimath/asciimath/constants.rb +186 -141
- data/lib/plurimath/asciimath/parse.rb +104 -39
- data/lib/plurimath/asciimath/parser.rb +3 -1
- data/lib/plurimath/asciimath/transform.rb +1074 -238
- data/lib/plurimath/html/parse.rb +1 -1
- data/lib/plurimath/latex/constants.rb +3228 -1432
- data/lib/plurimath/latex/parse.rb +106 -83
- data/lib/plurimath/latex/parser.rb +11 -4
- data/lib/plurimath/latex/transform.rb +354 -99
- data/lib/plurimath/math/base.rb +15 -0
- data/lib/plurimath/math/formula.rb +90 -13
- data/lib/plurimath/math/function/bar.rb +35 -1
- data/lib/plurimath/math/function/base.rb +25 -4
- data/lib/plurimath/math/function/binary_function.rb +101 -19
- 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 +15 -5
- data/lib/plurimath/math/function/f.rb +8 -0
- data/lib/plurimath/math/function/fenced.rb +95 -8
- data/lib/plurimath/math/function/floor.rb +15 -0
- data/lib/plurimath/math/function/font_style/bold.rb +19 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +19 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +19 -0
- data/lib/plurimath/math/function/font_style/italic.rb +37 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +19 -0
- data/lib/plurimath/math/function/font_style/normal.rb +37 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +19 -0
- data/lib/plurimath/math/function/font_style/script.rb +19 -0
- data/lib/plurimath/math/function/font_style.rb +18 -5
- data/lib/plurimath/math/function/frac.rb +33 -3
- 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 -0
- data/lib/plurimath/math/function/int.rb +23 -2
- data/lib/plurimath/math/function/left.rb +25 -1
- data/lib/plurimath/math/function/lim.rb +40 -2
- data/lib/plurimath/math/function/limits.rb +9 -0
- data/lib/plurimath/math/function/log.rb +55 -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 +19 -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 +19 -0
- data/lib/plurimath/math/function/norm.rb +17 -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 +12 -5
- data/lib/plurimath/math/function/overset.rb +34 -5
- data/lib/plurimath/math/function/phantom.rb +28 -0
- data/lib/plurimath/math/function/power.rb +27 -9
- data/lib/plurimath/math/function/power_base.rb +109 -11
- data/lib/plurimath/math/function/prod.rb +25 -4
- data/lib/plurimath/math/function/right.rb +22 -2
- data/lib/plurimath/math/function/root.rb +23 -1
- 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 +23 -1
- data/lib/plurimath/math/function/stackrel.rb +27 -0
- data/lib/plurimath/math/function/substack.rb +7 -0
- data/lib/plurimath/math/function/sum.rb +50 -2
- data/lib/plurimath/math/function/sup.rb +3 -0
- data/lib/plurimath/math/function/table/align.rb +5 -5
- data/lib/plurimath/math/function/table/array.rb +25 -6
- data/lib/plurimath/math/function/table/bmatrix.rb +18 -7
- data/lib/plurimath/math/function/table/matrix.rb +13 -5
- data/lib/plurimath/math/function/table/multline.rb +5 -5
- data/lib/plurimath/math/function/table/pmatrix.rb +5 -5
- data/lib/plurimath/math/function/table/split.rb +5 -5
- data/lib/plurimath/math/function/table/vmatrix.rb +5 -6
- data/lib/plurimath/math/function/table.rb +185 -27
- data/lib/plurimath/math/function/td.rb +22 -9
- data/lib/plurimath/math/function/ternary_function.rb +74 -9
- data/lib/plurimath/math/function/text.rb +36 -11
- data/lib/plurimath/math/function/tr.rb +23 -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 +81 -8
- 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 +7 -1
- data/lib/plurimath/math/number.rb +5 -5
- data/lib/plurimath/math/symbol.rb +51 -12
- data/lib/plurimath/math/unicode.rb +11 -0
- data/lib/plurimath/math.rb +7 -3
- data/lib/plurimath/mathml/constants.rb +224 -147
- data/lib/plurimath/mathml/parser.rb +24 -8
- data/lib/plurimath/mathml/transform.rb +249 -153
- data/lib/plurimath/omml/parser.rb +24 -4
- data/lib/plurimath/omml/transform.rb +219 -157
- data/lib/plurimath/utility.rb +342 -20
- data/lib/plurimath/version.rb +1 -1
- metadata +21 -6
- data/.github/workflows/test.yml +0 -33
- data/lib/plurimath/mathml/parse.rb +0 -68
- data/lib/plurimath/omml/constants.rb +0 -154
@@ -15,9 +15,9 @@ module Plurimath
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_asciimath
|
18
|
-
first_value = parameter_one
|
19
|
-
second_value = "_
|
20
|
-
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
|
21
21
|
"#{first_value}#{second_value}#{third_value}"
|
22
22
|
end
|
23
23
|
|
@@ -29,23 +29,88 @@ module Plurimath
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_mathml_without_math_tag
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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}"
|
37
44
|
end
|
38
45
|
|
39
46
|
def to_html
|
40
47
|
first_value = "<i>#{parameter_one.to_html}</i>" if parameter_one
|
41
48
|
second_value = "<i>#{parameter_two.to_html}</i>" if parameter_two
|
42
49
|
third_value = "<i>#{parameter_three.to_html}</i>" if parameter_three
|
43
|
-
first_value
|
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
|
44
59
|
end
|
45
60
|
|
46
61
|
def class_name
|
47
62
|
self.class.name.split("::").last.downcase
|
48
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
|
49
114
|
end
|
50
115
|
end
|
51
116
|
end
|
@@ -1,42 +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
13
|
"\"#{parse_text('asciimath') || parameter_one}\""
|
11
14
|
end
|
12
15
|
|
13
16
|
def to_mathml_without_math_tag
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def symbol_value(unicode)
|
18
|
-
Mathml::Constants::UNICODE_SYMBOLS.invert[unicode] ||
|
19
|
-
Mathml::Constants::SYMBOLS.invert[unicode]
|
17
|
+
text = Utility.ox_element("mtext")
|
18
|
+
text << (parse_text("mathml") || parameter_one) if parameter_one
|
20
19
|
end
|
21
20
|
|
22
21
|
def to_latex
|
23
|
-
parse_text("latex") || parameter_one
|
22
|
+
text_value = parse_text("latex") || parameter_one
|
23
|
+
"\\text{#{text_value}}"
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_html
|
27
27
|
parse_text("html") || parameter_one
|
28
28
|
end
|
29
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
|
+
|
37
|
+
def symbol_value(unicode)
|
38
|
+
Mathml::Constants::UNICODE_SYMBOLS.invert[unicode] ||
|
39
|
+
Mathml::Constants::SYMBOLS.invert[unicode]
|
40
|
+
end
|
41
|
+
|
30
42
|
def parse_text(lang)
|
31
|
-
|
32
|
-
|
43
|
+
html_value = first_value(lang).dup
|
44
|
+
html_value&.gsub!(PARSER_REGEX) do |_text|
|
33
45
|
last_match = Regexp.last_match
|
34
46
|
if ["mathml", "html"].include?(lang)
|
35
|
-
symbol_value(last_match[:unicode])
|
47
|
+
symbol_value(last_match[:unicode])
|
36
48
|
else
|
37
|
-
last_match[:unicode]
|
49
|
+
last_match[:unicode]
|
38
50
|
end
|
39
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
|
40
65
|
end
|
41
66
|
end
|
42
67
|
end
|
@@ -7,23 +7,42 @@ 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(" & ")
|
21
27
|
end
|
22
28
|
|
23
29
|
def to_html
|
24
30
|
first_value = parameter_one.map(&:to_html).join
|
25
31
|
"<tr>#{first_value}</tr>"
|
26
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
|
45
|
+
end
|
27
46
|
end
|
28
47
|
end
|
29
48
|
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
|
@@ -7,6 +7,7 @@ module Plurimath
|
|
7
7
|
attr_accessor :parameter_one
|
8
8
|
|
9
9
|
def initialize(parameter_one = nil)
|
10
|
+
parameter_one = parameter_one.to_s if parameter_one.is_a?(Parslet::Slice)
|
10
11
|
@parameter_one = parameter_one
|
11
12
|
end
|
12
13
|
|
@@ -16,30 +17,102 @@ module Plurimath
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def to_asciimath
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
value = if Utility::UNARY_CLASSES.any?(class_name)
|
21
|
+
asciimath_value
|
22
|
+
elsif parameter_one
|
23
|
+
"(#{asciimath_value})"
|
24
|
+
end
|
25
|
+
"#{class_name}#{value}"
|
24
26
|
end
|
25
27
|
|
26
28
|
def to_mathml_without_math_tag
|
27
|
-
"
|
29
|
+
row_tag = Utility.ox_element("mrow")
|
30
|
+
tag_name = Utility::UNARY_CLASSES.include?(class_name) ? "mi" : "mo"
|
31
|
+
new_arr = [Utility.ox_element(tag_name) << class_name]
|
32
|
+
new_arr += mathml_value if parameter_one
|
33
|
+
Utility.update_nodes(row_tag, new_arr)
|
28
34
|
end
|
29
35
|
|
30
36
|
def to_latex
|
31
|
-
first_value = "{#{
|
37
|
+
first_value = "{#{latex_value}}" if parameter_one
|
32
38
|
"\\#{class_name}#{first_value}"
|
33
39
|
end
|
34
40
|
|
35
41
|
def to_html
|
36
|
-
first_value =
|
42
|
+
first_value = if parameter_one.is_a?(Array)
|
43
|
+
"<i>#{parameter_one.map(&:to_html).join}</i>"
|
44
|
+
elsif parameter_one
|
45
|
+
"<i>#{parameter_one.to_html}</i>"
|
46
|
+
end
|
37
47
|
"<i>#{class_name}</i>#{first_value}"
|
38
48
|
end
|
39
49
|
|
50
|
+
def to_omml_without_math_tag
|
51
|
+
func = Utility.ox_element("func", namespace: "m")
|
52
|
+
funcpr = Utility.ox_element("funcPr", namespace: "m")
|
53
|
+
funcpr << Utility.pr_element("ctrl", true, namespace: "m")
|
54
|
+
fname = Utility.ox_element("fName", namespace: "m")
|
55
|
+
mr = Utility.ox_element("r", namespace: "m")
|
56
|
+
rpr = Utility.rpr_element
|
57
|
+
mt = Utility.ox_element("t", namespace: "m") << class_name
|
58
|
+
fname << Utility.update_nodes(mr, [rpr, mt])
|
59
|
+
me = Utility.ox_element("e", namespace: "m")
|
60
|
+
Utility.update_nodes(me, omml_value) if parameter_one
|
61
|
+
Utility.update_nodes(
|
62
|
+
func,
|
63
|
+
[
|
64
|
+
funcpr,
|
65
|
+
fname,
|
66
|
+
me,
|
67
|
+
],
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
40
71
|
def class_name
|
41
72
|
self.class.name.split("::").last.downcase
|
42
73
|
end
|
74
|
+
|
75
|
+
protected
|
76
|
+
|
77
|
+
def asciimath_value
|
78
|
+
return "" unless parameter_one
|
79
|
+
|
80
|
+
case parameter_one
|
81
|
+
when Array
|
82
|
+
parameter_one.compact.map(&:to_asciimath).join
|
83
|
+
else
|
84
|
+
parameter_one.to_asciimath
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def mathml_value
|
89
|
+
case parameter_one
|
90
|
+
when Array
|
91
|
+
parameter_one.compact.map(&:to_mathml_without_math_tag)
|
92
|
+
else
|
93
|
+
Array(parameter_one&.to_mathml_without_math_tag)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def latex_value
|
98
|
+
if parameter_one.is_a?(Array)
|
99
|
+
return parameter_one&.compact&.map(&:to_latex)&.join(" ")
|
100
|
+
end
|
101
|
+
|
102
|
+
parameter_one&.to_latex
|
103
|
+
end
|
104
|
+
|
105
|
+
def omml_value
|
106
|
+
if parameter_one.is_a?(Array)
|
107
|
+
return parameter_one.compact.map(&:to_omml_without_math_tag)
|
108
|
+
end
|
109
|
+
|
110
|
+
first_value = parameter_one.to_omml_without_math_tag
|
111
|
+
if parameter_one.is_a?(Symbol)
|
112
|
+
first_value = Utility.ox_element("t", namespace: "m") << first_value
|
113
|
+
end
|
114
|
+
Array(first_value)
|
115
|
+
end
|
43
116
|
end
|
44
117
|
end
|
45
118
|
end
|
@@ -6,6 +6,113 @@ module Plurimath
|
|
6
6
|
module Math
|
7
7
|
module Function
|
8
8
|
class Underover < TernaryFunction
|
9
|
+
def to_asciimath
|
10
|
+
first_value = first_field_wrap(parameter_one) if parameter_one
|
11
|
+
second_value = "_#{wrapped(parameter_two)}" if parameter_two
|
12
|
+
third_value = "^#{wrapped(parameter_three)}" if parameter_three
|
13
|
+
"#{first_value}#{second_value}#{third_value}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_latex
|
17
|
+
first_value = first_field_wrap(parameter_one, type: "latex") if parameter_one
|
18
|
+
second_value = "_#{wrapped(parameter_two, type: 'latex')}" if parameter_two
|
19
|
+
third_value = "^#{wrapped(parameter_three, type: 'latex')}" if parameter_three
|
20
|
+
"#{first_value}#{second_value}#{third_value}"
|
21
|
+
end
|
22
|
+
|
23
|
+
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
|
+
Utility.update_nodes(
|
29
|
+
class_tag,
|
30
|
+
[
|
31
|
+
first_value,
|
32
|
+
second_value,
|
33
|
+
third_value,
|
34
|
+
],
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_omml_without_math_tag
|
39
|
+
limupp = Utility.ox_element("limUpp", namespace: "m")
|
40
|
+
limpr = Utility.ox_element("limUppPr", namespace: "m")
|
41
|
+
limpr << Utility.pr_element("ctrl", namespace: "m")
|
42
|
+
e_tag = Utility.ox_element("e", namespace: "m")
|
43
|
+
e_tag << parameter_one&.to_omml_without_math_tag
|
44
|
+
lim = Utility.ox_element("lim", namespace: "m")
|
45
|
+
lim << parameter_two&.to_omml_without_math_tag if parameter_two
|
46
|
+
Utility.update_nodes(
|
47
|
+
limupp,
|
48
|
+
[
|
49
|
+
e_tag,
|
50
|
+
lim,
|
51
|
+
],
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def omml_nary_tag
|
56
|
+
pr = Utility.ox_element("naryPr", namespace: "m")
|
57
|
+
[pr_element_value(pr), sub_value, sup_value]
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def hidden_sub_tag(pr_element)
|
63
|
+
return true unless parameter_two.nil?
|
64
|
+
|
65
|
+
pr_element << Utility.ox_element(
|
66
|
+
"subHide",
|
67
|
+
namespace: "m",
|
68
|
+
attributes: { "m:val": 1 },
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def hidden_sup_tag(pr_element)
|
73
|
+
return true unless parameter_three.nil?
|
74
|
+
|
75
|
+
pr_element << Utility.ox_element(
|
76
|
+
"supHide",
|
77
|
+
namespace: "m",
|
78
|
+
attributes: { "m:val": 1 },
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def pr_element_value(pr_element)
|
83
|
+
first_value(pr_element)
|
84
|
+
pr_element << Utility.ox_element(
|
85
|
+
"limLoc",
|
86
|
+
namespace: "m",
|
87
|
+
attributes: { "m:val": "undOvr" },
|
88
|
+
)
|
89
|
+
hidden_sub_tag(pr_element)
|
90
|
+
hidden_sup_tag(pr_element)
|
91
|
+
pr_element << Utility.pr_element("ctrl", true, namespace: "m")
|
92
|
+
end
|
93
|
+
|
94
|
+
def sub_value
|
95
|
+
sub = Utility.ox_element("sub", namespace: "m")
|
96
|
+
sub << omml_value(parameter_two) if parameter_two
|
97
|
+
sub
|
98
|
+
end
|
99
|
+
|
100
|
+
def sup_value
|
101
|
+
sup = Utility.ox_element("sup", namespace: "m")
|
102
|
+
sup << omml_value(parameter_three) if parameter_three
|
103
|
+
sup
|
104
|
+
end
|
105
|
+
|
106
|
+
def first_value(pr_element)
|
107
|
+
first_value = parameter_one.is_a?(Number) ? parameter_one.value : parameter_one.to_omml_without_math_tag
|
108
|
+
unless first_value == "∫"
|
109
|
+
pr_element << Utility.ox_element(
|
110
|
+
"chr",
|
111
|
+
namespace: "m",
|
112
|
+
attributes: { "m:val": first_value },
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
9
116
|
end
|
10
117
|
end
|
11
118
|
end
|
@@ -6,6 +6,45 @@ module Plurimath
|
|
6
6
|
module Math
|
7
7
|
module Function
|
8
8
|
class Underset < BinaryFunction
|
9
|
+
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
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_omml_without_math_tag
|
22
|
+
first_value = if parameter_one.is_a?(Math::Symbol)
|
23
|
+
mt = Utility.ox_element("t", namespace: "m")
|
24
|
+
mt << parameter_one.to_omml_without_math_tag
|
25
|
+
else
|
26
|
+
parameter_one.to_omml_without_math_tag
|
27
|
+
end
|
28
|
+
second_value = if parameter_two.is_a?(Math::Symbol)
|
29
|
+
mt = Utility.ox_element("t", namespace: "m")
|
30
|
+
mt << parameter_two.to_omml_without_math_tag
|
31
|
+
else
|
32
|
+
parameter_two.to_omml_without_math_tag
|
33
|
+
end
|
34
|
+
limlow = Utility.ox_element("limLow", namespace: "m")
|
35
|
+
limlowpr = Utility.ox_element("limLowPr", namespace: "m")
|
36
|
+
limlowpr << Utility.pr_element("ctrl", true, namespace: "m")
|
37
|
+
me = Utility.ox_element("e", namespace: "m") << first_value
|
38
|
+
lim = Utility.ox_element("lim", namespace: "m") << second_value if second_value
|
39
|
+
Utility.update_nodes(
|
40
|
+
limlow,
|
41
|
+
[
|
42
|
+
limlowpr,
|
43
|
+
me,
|
44
|
+
lim,
|
45
|
+
],
|
46
|
+
)
|
47
|
+
end
|
9
48
|
end
|
10
49
|
end
|
11
50
|
end
|
@@ -8,7 +8,13 @@ module Plurimath
|
|
8
8
|
class Vec < UnaryFunction
|
9
9
|
def to_mathml_without_math_tag
|
10
10
|
first_value = parameter_one&.to_mathml_without_math_tag
|
11
|
-
|
11
|
+
Utility.update_nodes(
|
12
|
+
Utility.ox_element("mover"),
|
13
|
+
[
|
14
|
+
first_value,
|
15
|
+
Utility.ox_element("mo") << "→",
|
16
|
+
],
|
17
|
+
)
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module Plurimath
|
4
4
|
module Math
|
5
|
-
class Number
|
5
|
+
class Number < Base
|
6
6
|
attr_accessor :value
|
7
7
|
|
8
8
|
def initialize(value)
|
9
|
-
@value =
|
9
|
+
@value = super
|
10
10
|
end
|
11
11
|
|
12
12
|
def ==(object)
|
@@ -18,7 +18,7 @@ module Plurimath
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_mathml_without_math_tag
|
21
|
-
"
|
21
|
+
Utility.ox_element("mn") << value
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_latex
|
@@ -29,8 +29,8 @@ module Plurimath
|
|
29
29
|
value
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def to_omml_without_math_tag
|
33
|
+
Utility.ox_element("t", namespace: "m") << value
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|