plurimath 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +36 -0
- data/.rubocop.yml +2 -0
- data/lib/plurimath/asciimath/constants.rb +308 -0
- data/lib/plurimath/asciimath/parse.rb +87 -0
- data/lib/plurimath/asciimath/parser.rb +24 -0
- data/lib/plurimath/asciimath/transform.rb +304 -0
- data/lib/plurimath/asciimath.rb +16 -0
- data/lib/plurimath/html.rb +15 -0
- data/lib/plurimath/latex/constants.rb +1963 -0
- data/lib/plurimath/latex/parse.rb +105 -0
- data/lib/plurimath/latex/parser.rb +24 -0
- data/lib/plurimath/latex/transform.rb +298 -0
- data/lib/plurimath/latex.rb +15 -0
- data/lib/plurimath/math/formula.rb +43 -0
- data/lib/plurimath/math/function/abs.rb +12 -0
- data/lib/plurimath/math/function/arccos.rb +12 -0
- data/lib/plurimath/math/function/arcsin.rb +12 -0
- data/lib/plurimath/math/function/arctan.rb +12 -0
- data/lib/plurimath/math/function/bar.rb +16 -0
- data/lib/plurimath/math/function/base.rb +30 -0
- data/lib/plurimath/math/function/binary_function.rb +53 -0
- data/lib/plurimath/math/function/cancel.rb +12 -0
- data/lib/plurimath/math/function/ceil.rb +12 -0
- data/lib/plurimath/math/function/color.rb +23 -0
- data/lib/plurimath/math/function/cos.rb +12 -0
- data/lib/plurimath/math/function/cosh.rb +12 -0
- data/lib/plurimath/math/function/cot.rb +12 -0
- data/lib/plurimath/math/function/coth.rb +12 -0
- data/lib/plurimath/math/function/csc.rb +12 -0
- data/lib/plurimath/math/function/csch.rb +12 -0
- data/lib/plurimath/math/function/ddot.rb +12 -0
- data/lib/plurimath/math/function/deg.rb +12 -0
- data/lib/plurimath/math/function/det.rb +12 -0
- data/lib/plurimath/math/function/dim.rb +12 -0
- data/lib/plurimath/math/function/dot.rb +12 -0
- data/lib/plurimath/math/function/exp.rb +12 -0
- data/lib/plurimath/math/function/f.rb +12 -0
- data/lib/plurimath/math/function/fenced.rb +22 -0
- data/lib/plurimath/math/function/floor.rb +12 -0
- data/lib/plurimath/math/function/font_style.rb +45 -0
- data/lib/plurimath/math/function/frac.rb +23 -0
- data/lib/plurimath/math/function/g.rb +12 -0
- data/lib/plurimath/math/function/gcd.rb +12 -0
- data/lib/plurimath/math/function/glb.rb +12 -0
- data/lib/plurimath/math/function/hat.rb +12 -0
- data/lib/plurimath/math/function/hom.rb +12 -0
- data/lib/plurimath/math/function/inf.rb +18 -0
- data/lib/plurimath/math/function/int.rb +17 -0
- data/lib/plurimath/math/function/ker.rb +12 -0
- data/lib/plurimath/math/function/lcm.rb +12 -0
- data/lib/plurimath/math/function/left.rb +23 -0
- data/lib/plurimath/math/function/lg.rb +12 -0
- data/lib/plurimath/math/function/lim.rb +23 -0
- data/lib/plurimath/math/function/liminf.rb +12 -0
- data/lib/plurimath/math/function/limits.rb +19 -0
- data/lib/plurimath/math/function/limsup.rb +12 -0
- data/lib/plurimath/math/function/ln.rb +12 -0
- data/lib/plurimath/math/function/log.rb +23 -0
- data/lib/plurimath/math/function/lub.rb +12 -0
- data/lib/plurimath/math/function/max.rb +12 -0
- data/lib/plurimath/math/function/min.rb +12 -0
- data/lib/plurimath/math/function/mod.rb +23 -0
- data/lib/plurimath/math/function/norm.rb +15 -0
- data/lib/plurimath/math/function/obrace.rb +12 -0
- data/lib/plurimath/math/function/oint.rb +17 -0
- data/lib/plurimath/math/function/overset.rb +23 -0
- data/lib/plurimath/math/function/power.rb +30 -0
- data/lib/plurimath/math/function/power_base.rb +26 -0
- data/lib/plurimath/math/function/prod.rb +23 -0
- data/lib/plurimath/math/function/root.rb +22 -0
- data/lib/plurimath/math/function/sec.rb +12 -0
- data/lib/plurimath/math/function/sech.rb +12 -0
- data/lib/plurimath/math/function/sin.rb +12 -0
- data/lib/plurimath/math/function/sinh.rb +12 -0
- data/lib/plurimath/math/function/sqrt.rb +16 -0
- data/lib/plurimath/math/function/stackrel.rb +12 -0
- data/lib/plurimath/math/function/substack.rb +18 -0
- data/lib/plurimath/math/function/sum.rb +23 -0
- data/lib/plurimath/math/function/sup.rb +12 -0
- data/lib/plurimath/math/function/table.rb +42 -0
- data/lib/plurimath/math/function/tan.rb +12 -0
- data/lib/plurimath/math/function/tanh.rb +12 -0
- data/lib/plurimath/math/function/td.rb +27 -0
- data/lib/plurimath/math/function/ternary_function.rb +42 -0
- data/lib/plurimath/math/function/text.rb +32 -0
- data/lib/plurimath/math/function/tilde.rb +12 -0
- data/lib/plurimath/math/function/tr.rb +25 -0
- data/lib/plurimath/math/function/ubrace.rb +12 -0
- data/lib/plurimath/math/function/ul.rb +12 -0
- data/lib/plurimath/math/function/unary_function.rb +41 -0
- data/lib/plurimath/math/function/underover.rb +12 -0
- data/lib/plurimath/math/function/underset.rb +12 -0
- data/lib/plurimath/math/function/vec.rb +12 -0
- data/lib/plurimath/math/function.rb +3 -0
- data/lib/plurimath/math/number.rb +29 -0
- data/lib/plurimath/math/symbol.rb +34 -0
- data/lib/plurimath/math.rb +51 -0
- data/lib/plurimath/mathml/constants.rb +327 -0
- data/lib/plurimath/mathml/parse.rb +63 -0
- data/lib/plurimath/mathml/parser.rb +25 -0
- data/lib/plurimath/mathml/transform.rb +195 -0
- data/lib/plurimath/mathml.rb +16 -0
- data/lib/plurimath/omml.rb +15 -0
- data/lib/plurimath/unicode.rb +15 -0
- data/lib/plurimath/unitsml.rb +11 -0
- data/lib/plurimath/version.rb +3 -1
- data/lib/plurimath.rb +3 -5
- data/plurimath.gemspec +3 -3
- metadata +129 -11
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "binary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Overset < BinaryFunction
|
|
9
|
+
def to_mathml_without_math_tag
|
|
10
|
+
first_value = parameter_one.to_mathml_without_math_tag if parameter_one
|
|
11
|
+
second_value = parameter_two.to_mathml_without_math_tag if parameter_two
|
|
12
|
+
"<mover>#{second_value}#{first_value}</mover>"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_latex
|
|
16
|
+
first_value = "{#{parameter_one.to_latex}" if parameter_one
|
|
17
|
+
second_value = "#{parameter_two.to_latex}}" if parameter_two
|
|
18
|
+
"#{first_value}\\over#{second_value}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "binary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Power < BinaryFunction
|
|
9
|
+
def to_asciimath
|
|
10
|
+
first_value = parameter_one.to_asciimath if parameter_one
|
|
11
|
+
second_value = "^#{parameter_two.to_asciimath}" if parameter_two
|
|
12
|
+
"#{first_value}#{second_value}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_mathml_without_math_tag
|
|
16
|
+
first_value = parameter_one.to_mathml_without_math_tag
|
|
17
|
+
second_value = parameter_two.to_mathml_without_math_tag
|
|
18
|
+
"<msup>#{first_value}#{second_value}</msup>"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_latex
|
|
22
|
+
first_value = parameter_one.to_latex if parameter_one
|
|
23
|
+
first_value = "{#{first_value}}" if parameter_one.is_a?(Math::Formula)
|
|
24
|
+
second_value = parameter_two.to_latex
|
|
25
|
+
"#{first_value}^{#{second_value}}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "ternary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class PowerBase < TernaryFunction
|
|
9
|
+
def to_mathml_without_math_tag
|
|
10
|
+
first_value = parameter_one.to_mathml_without_math_tag if parameter_one
|
|
11
|
+
second_value = parameter_two.to_mathml_without_math_tag if parameter_two
|
|
12
|
+
third_value = parameter_three.to_mathml_without_math_tag if parameter_three
|
|
13
|
+
"<msubsup>#{first_value}#{second_value}#{third_value}</msubsup>"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_latex
|
|
17
|
+
first_value = parameter_one.to_latex if parameter_one
|
|
18
|
+
second_value = parameter_two.to_latex if parameter_two
|
|
19
|
+
third_value = parameter_three.to_latex if parameter_three
|
|
20
|
+
first_value = "{#{first_value}}" if parameter_one.is_a?(Math::Formula)
|
|
21
|
+
"#{first_value}_{#{second_value}}^{#{third_value}}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "binary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Prod < BinaryFunction
|
|
9
|
+
def to_asciimath
|
|
10
|
+
first_value = "_(#{parameter_one.to_asciimath})" if parameter_one
|
|
11
|
+
second_value = "^(#{parameter_two.to_asciimath})" if parameter_two
|
|
12
|
+
"prod#{first_value}#{second_value}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_latex
|
|
16
|
+
first_value = "_{#{parameter_one.to_latex}}" if parameter_one
|
|
17
|
+
second_value = "^{#{parameter_two.to_latex}}" if parameter_two
|
|
18
|
+
"\\prod#{first_value}#{second_value}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "binary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Root < BinaryFunction
|
|
9
|
+
def to_mathml_without_math_tag
|
|
10
|
+
first_value = parameter_one.to_mathml_without_math_tag if parameter_one
|
|
11
|
+
"<root>#{first_value}</root>"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_latex
|
|
15
|
+
first_value = parameter_one.to_latex if parameter_one
|
|
16
|
+
second_value = parameter_two.to_latex if parameter_two
|
|
17
|
+
"\\sqrt[#{first_value}]{#{second_value}}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "unary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Sqrt < UnaryFunction
|
|
9
|
+
def to_mathml_without_math_tag
|
|
10
|
+
first_value = parameter_one.to_mathml_without_math_tag if parameter_one
|
|
11
|
+
"<msqrt>#{first_value}</msqrt>"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "binary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Substack < BinaryFunction
|
|
9
|
+
|
|
10
|
+
def to_latex
|
|
11
|
+
first_value = parameter_one.to_latex if parameter_one
|
|
12
|
+
second_value = "\\\\#{parameter_two.to_latex}" if parameter_two
|
|
13
|
+
"\\#{class_name}{#{first_value}#{second_value}}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "binary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Sum < BinaryFunction
|
|
9
|
+
def to_asciimath
|
|
10
|
+
first_value = "_(#{parameter_one.to_asciimath})" if parameter_one
|
|
11
|
+
second_value = "^(#{parameter_two.to_asciimath})" if parameter_two
|
|
12
|
+
"sum#{first_value}#{second_value}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_latex
|
|
16
|
+
first_value = "_{#{parameter_one.to_latex}}" if parameter_one
|
|
17
|
+
second_value = "^{#{parameter_two.to_latex}}" if parameter_two
|
|
18
|
+
"\\sum#{first_value}#{second_value}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "ternary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Table < TernaryFunction
|
|
9
|
+
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}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
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>∥</mo>#{table_value}<mo>∥</mo>"
|
|
23
|
+
else
|
|
24
|
+
"<mtable>#{table_value}</mtable>"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
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}}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def latex_environment
|
|
36
|
+
matrices_hash = Latex::Constants::ENVIRONMENTS
|
|
37
|
+
matrices_hash.invert[parameter_two] if matrices_hash.value?(parameter_two)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "unary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Td < UnaryFunction
|
|
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
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_mathml_without_math_tag
|
|
18
|
+
"<mtd>#{parameter_one.map(&:to_mathml_without_math_tag).join}</mtd>"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_latex
|
|
22
|
+
parameter_one.map(&:to_latex).join
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
module Math
|
|
5
|
+
module Function
|
|
6
|
+
class TernaryFunction
|
|
7
|
+
attr_accessor :parameter_one, :parameter_two, :parameter_three
|
|
8
|
+
|
|
9
|
+
def initialize(parameter_one = nil, parameter_two = nil, parameter_three = nil)
|
|
10
|
+
@parameter_one = parameter_one
|
|
11
|
+
@parameter_two = parameter_two
|
|
12
|
+
@parameter_three = parameter_three
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
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
|
|
19
|
+
"#{first_value}#{second_value}#{third_value}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def ==(object)
|
|
23
|
+
self.class == object.class &&
|
|
24
|
+
object.parameter_one == parameter_one &&
|
|
25
|
+
object.parameter_two == parameter_two &&
|
|
26
|
+
object.parameter_three == parameter_three
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
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}>"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def class_name
|
|
37
|
+
self.class.name.split("::").last.downcase
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "unary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Text < UnaryFunction
|
|
9
|
+
def to_asciimath
|
|
10
|
+
"\"#{parameter_one}\""
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
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>"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def symbol_value(unicode)
|
|
22
|
+
Mathml::Constants::UNICODE_SYMBOLS.invert[unicode] ||
|
|
23
|
+
Mathml::Constants::SYMBOLS.invert[unicode]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_latex
|
|
27
|
+
parameter_one
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "unary_function"
|
|
4
|
+
|
|
5
|
+
module Plurimath
|
|
6
|
+
module Math
|
|
7
|
+
module Function
|
|
8
|
+
class Tr < UnaryFunction
|
|
9
|
+
def to_asciimath
|
|
10
|
+
"[#{parameter_one.map(&:to_asciimath).join(',')}]"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_mathml_without_math_tag
|
|
14
|
+
"<mtr>#{parameter_one.map(&:to_mathml_without_math_tag).join}</mtr>"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_latex
|
|
18
|
+
parameter_one.reject do |td|
|
|
19
|
+
td if td.is_a?(Symbol) && td.value == "|"
|
|
20
|
+
end.map(&:to_latex).join("&")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
module Math
|
|
5
|
+
module Function
|
|
6
|
+
class UnaryFunction
|
|
7
|
+
attr_accessor :parameter_one
|
|
8
|
+
|
|
9
|
+
def initialize(parameter_one = nil)
|
|
10
|
+
@parameter_one = parameter_one
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def ==(object)
|
|
14
|
+
object.class == self.class &&
|
|
15
|
+
object.parameter_one == parameter_one
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_asciimath
|
|
19
|
+
"#{class_name}#{value_to_asciimath}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def value_to_asciimath
|
|
23
|
+
"(#{parameter_one.to_asciimath})" unless parameter_one.nil?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_mathml_without_math_tag
|
|
27
|
+
"<mi>#{class_name}</mi>"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_latex
|
|
31
|
+
first_value = "{#{parameter_one.to_latex}}" if parameter_one
|
|
32
|
+
"\\#{class_name}#{first_value}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def class_name
|
|
36
|
+
self.class.name.split("::").last.downcase
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
module Math
|
|
5
|
+
class Number
|
|
6
|
+
attr_accessor :value
|
|
7
|
+
|
|
8
|
+
def initialize(value)
|
|
9
|
+
@value = value
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def ==(object)
|
|
13
|
+
object.value == value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_asciimath
|
|
17
|
+
value
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_mathml_without_math_tag
|
|
21
|
+
"<mn>#{value}</mn>"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_latex
|
|
25
|
+
value
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
module Math
|
|
5
|
+
class Symbol
|
|
6
|
+
attr_accessor :value
|
|
7
|
+
|
|
8
|
+
def initialize(sym)
|
|
9
|
+
@value = sym
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def ==(object)
|
|
13
|
+
object.value == value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_asciimath
|
|
17
|
+
value
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_mathml_without_math_tag
|
|
21
|
+
"<mo>#{mathml_symbol_value}</mo>"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def mathml_symbol_value
|
|
25
|
+
Mathml::Constants::UNICODE_SYMBOLS.invert[value] || value
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def to_latex
|
|
29
|
+
symbols = Latex::Constants::SYMBOLS
|
|
30
|
+
symbols.include?(value) ? "\\#{value}" : value
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|