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
@@ -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,25 +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
|
|
41
|
+
def to_html
|
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
|
47
|
+
"<i>#{class_name}</i>#{first_value}"
|
48
|
+
end
|
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
|
+
|
35
71
|
def class_name
|
36
72
|
self.class.name.split("::").last.downcase
|
37
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
|
38
116
|
end
|
39
117
|
end
|
40
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
|
@@ -6,6 +6,16 @@ module Plurimath
|
|
6
6
|
module Math
|
7
7
|
module Function
|
8
8
|
class Vec < 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("mover"),
|
13
|
+
[
|
14
|
+
first_value,
|
15
|
+
Utility.ox_element("mo") << "→",
|
16
|
+
],
|
17
|
+
)
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
11
21
|
end
|
@@ -1,3 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Plurimath
|
2
|
+
module Math
|
3
|
+
module Function
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# Include the first level files before the next
|
9
|
+
(
|
10
|
+
Dir.glob(File.join(__dir__, "function", "*.rb")) +
|
11
|
+
Dir.glob(File.join(__dir__, "function", "*", "*.rb"))
|
12
|
+
).each do |file|
|
13
|
+
require file
|
3
14
|
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,12 +18,20 @@ 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
|
25
25
|
value
|
26
26
|
end
|
27
|
+
|
28
|
+
def to_html
|
29
|
+
value
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_omml_without_math_tag
|
33
|
+
Utility.ox_element("t", namespace: "m") << value
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module Plurimath
|
4
4
|
module Math
|
5
|
-
class Symbol
|
5
|
+
class Symbol < Base
|
6
6
|
attr_accessor :value
|
7
7
|
|
8
8
|
def initialize(sym)
|
9
|
-
@value =
|
9
|
+
@value = super
|
10
10
|
end
|
11
11
|
|
12
12
|
def ==(object)
|
@@ -14,20 +14,68 @@ module Plurimath
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_asciimath
|
17
|
-
value
|
17
|
+
return "" if value.nil?
|
18
|
+
|
19
|
+
symbol = Asciimath::Constants::SYMBOLS.invert[value.strip.to_sym]
|
20
|
+
unicodes = Latex::Constants::UNICODE_SYMBOLS.invert
|
21
|
+
if value.match?(/&#x[0-9\w]+;/) && symbol.nil? && unicodes[value]
|
22
|
+
return unicodes[value].to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
symbol ? symbol.to_s : value
|
18
26
|
end
|
19
27
|
|
20
28
|
def to_mathml_without_math_tag
|
21
|
-
"
|
22
|
-
|
29
|
+
mi_tag = Utility.ox_element("mi")
|
30
|
+
return mi_tag if ["{:", ":}"].include?(value)
|
31
|
+
|
32
|
+
unicodes = Mathml::Constants::UNICODE_SYMBOLS
|
33
|
+
unicode = unicodes.invert[value]
|
34
|
+
if operator?(unicode) || unicode
|
35
|
+
mo_value = (unicodes[value] || unicode || value).to_s
|
36
|
+
return Utility.ox_element("mo") << mo_value
|
37
|
+
end
|
23
38
|
|
24
|
-
|
25
|
-
Mathml::Constants::UNICODE_SYMBOLS.invert[value] || value
|
39
|
+
mi_tag << value
|
26
40
|
end
|
27
41
|
|
28
42
|
def to_latex
|
29
|
-
|
30
|
-
|
43
|
+
returned = specific_values
|
44
|
+
return returned if returned
|
45
|
+
|
46
|
+
special_char = %w[& #]
|
47
|
+
symbols = Latex::Constants::UNICODE_SYMBOLS.invert
|
48
|
+
|
49
|
+
symbol = symbols[value]
|
50
|
+
if Latex::Constants::SYMBOLS[symbol] == :operant
|
51
|
+
special_char.include?(value) ? "\\#{symbol}" : symbol
|
52
|
+
else
|
53
|
+
symbols.key?(value) ? "\\#{symbol}" : value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_html
|
58
|
+
value
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_omml_without_math_tag
|
62
|
+
value
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def operator?(unicode)
|
68
|
+
Mathml::Constants::OPERATORS.any? do |d|
|
69
|
+
[unicode.to_s, value.strip].include?(d)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def specific_values
|
74
|
+
return "" if ["{:", ":}"].include?(value)
|
75
|
+
|
76
|
+
return "\\#{value}" if ["{", "}"].include?(value) || value == "_"
|
77
|
+
|
78
|
+
return "\\operatorname{if}" if value == "if"
|
31
79
|
end
|
32
80
|
end
|
33
81
|
end
|
data/lib/plurimath/math.rb
CHANGED
@@ -7,24 +7,33 @@ require_relative "mathml"
|
|
7
7
|
require_relative "html"
|
8
8
|
require_relative "latex"
|
9
9
|
require_relative "unitsml"
|
10
|
-
require_relative "math/
|
11
|
-
require_relative "math/function"
|
10
|
+
require_relative "math/base"
|
12
11
|
require_relative "math/number"
|
13
12
|
require_relative "math/symbol"
|
13
|
+
require_relative "math/unicode"
|
14
|
+
require_relative "math/formula"
|
15
|
+
require_relative "math/function"
|
14
16
|
require_relative "asciimath/parser"
|
15
17
|
require_relative "mathml/parser"
|
16
18
|
require_relative "latex/parser"
|
19
|
+
require_relative "html/parser"
|
20
|
+
require_relative "omml/parser"
|
21
|
+
require_relative "utility"
|
22
|
+
require "ox"
|
23
|
+
Ox.default_options = { encoding: "UTF-8" }
|
24
|
+
|
17
25
|
module Plurimath
|
18
26
|
module Math
|
19
27
|
class Error < StandardError; end
|
20
28
|
|
21
29
|
VALID_TYPES = {
|
22
|
-
unicode: Unicode,
|
23
|
-
asciimath: Asciimath,
|
24
30
|
omml: Omml,
|
25
|
-
mathml: Mathml,
|
26
31
|
html: Html,
|
27
32
|
latex: Latex,
|
33
|
+
mathml: Mathml,
|
34
|
+
unitsml: Unitsml,
|
35
|
+
unicode: Unicode,
|
36
|
+
asciimath: Asciimath,
|
28
37
|
}.freeze
|
29
38
|
|
30
39
|
def parse(text, type)
|
@@ -42,7 +51,7 @@ module Plurimath
|
|
42
51
|
end
|
43
52
|
|
44
53
|
def valid_type?(type)
|
45
|
-
(type.is_a?(Symbol) || type.is_a?(String)) &&
|
54
|
+
(type.is_a?(::Symbol) || type.is_a?(String)) &&
|
46
55
|
VALID_TYPES.key?(type.to_sym)
|
47
56
|
end
|
48
57
|
|