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
@@ -7,15 +7,38 @@ module Plurimath
7
7
  module Function
8
8
  class Root < BinaryFunction
9
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>"
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("mroot"),
14
+ [
15
+ second_value,
16
+ first_value,
17
+ ],
18
+ )
12
19
  end
13
20
 
14
21
  def to_latex
15
- first_value = parameter_one.to_latex if parameter_one
16
- second_value = parameter_two.to_latex if parameter_two
22
+ first_value = parameter_one&.to_latex
23
+ second_value = parameter_two&.to_latex
17
24
  "\\sqrt[#{first_value}]{#{second_value}}"
18
25
  end
26
+
27
+ def to_omml_without_math_tag
28
+ rad_element = Utility.ox_element("rad", namespace: "m")
29
+ pr_element = Utility.ox_element("radPr", namespace: "m")
30
+ deg_element = Utility.ox_element("deg", namespace: "m")
31
+ e_element = Utility.ox_element("e", namespace: "m")
32
+ Utility.update_nodes(
33
+ rad_element,
34
+ [
35
+ pr_element << Utility.pr_element("ctrl", true, namespace: "m"),
36
+ deg_element << parameter_two.to_omml_without_math_tag,
37
+ e_element << parameter_one.to_omml_without_math_tag,
38
+ ],
39
+ )
40
+ rad_element
41
+ end
19
42
  end
20
43
  end
21
44
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ternary_function"
4
+ module Plurimath
5
+ module Math
6
+ module Function
7
+ class Rule < TernaryFunction
8
+ def to_asciimath
9
+ ""
10
+ end
11
+
12
+ def to_latex
13
+ first_value = "[#{parameter_one.to_latex}]" if parameter_one
14
+ second_value = "{#{parameter_two.to_latex}}" if parameter_two
15
+ third_value = "{#{parameter_three.to_latex}}" if parameter_three
16
+ "\\rule#{first_value}#{second_value}#{third_value}"
17
+ end
18
+
19
+ def to_mathml_without_math_tag
20
+ Utility.ox_element("mi")
21
+ end
22
+
23
+ def to_omml_without_math_tag
24
+ Utility.ox_element("m:e")
25
+ end
26
+
27
+ def to_html
28
+ ""
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "unary_function"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Scarries < UnaryFunction
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "unary_function"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Scarry < UnaryFunction
9
+ end
10
+ end
11
+ end
12
+ end
@@ -7,8 +7,30 @@ module Plurimath
7
7
  module Function
8
8
  class Sqrt < UnaryFunction
9
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>"
10
+ sqrt_tag = Utility.ox_element("msqrt")
11
+ first_value = parameter_one&.to_mathml_without_math_tag
12
+ sqrt_tag << first_value if first_value
13
+ sqrt_tag
14
+ end
15
+
16
+ def to_omml_without_math_tag
17
+ rad_element = Utility.ox_element("rad", namespace: "m")
18
+ pr_element = Utility.ox_element("radPr", namespace: "m")
19
+ pr_element << Utility.ox_element(
20
+ "degHide",
21
+ namespace: "m",
22
+ attributes: { "m:val": "1" },
23
+ )
24
+ e_element = Utility.ox_element("e", namespace: "m")
25
+ Utility.update_nodes(
26
+ rad_element,
27
+ [
28
+ pr_element << Utility.pr_element("ctrl", true, namespace: "m"),
29
+ Utility.ox_element("deg", namespace: "m"),
30
+ e_element << parameter_one.to_omml_without_math_tag,
31
+ ],
32
+ )
33
+ rad_element
12
34
  end
13
35
  end
14
36
  end
@@ -6,6 +6,33 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Stackrel < BinaryFunction
9
+ def to_asciimath
10
+ first_value = wrapped(parameter_one)
11
+ second_value = wrapped(parameter_two)
12
+ "#{class_name}#{first_value}#{second_value}"
13
+ end
14
+
15
+ def to_mathml_without_math_tag
16
+ mover = Utility.ox_element("mover")
17
+ first_value = Utility.ox_element("mrow")
18
+ first_value << parameter_one.to_mathml_without_math_tag if parameter_one
19
+ second_value = Utility.ox_element("mrow")
20
+ second_value << parameter_two.to_mathml_without_math_tag if parameter_two
21
+ Utility.update_nodes(mover, [second_value, first_value])
22
+ end
23
+
24
+ def to_html
25
+ first_value = parameter_one&.to_html
26
+ second_value = parameter_two&.to_html
27
+ "#{first_value}#{second_value}"
28
+ end
29
+
30
+ protected
31
+
32
+ def wrapped(field)
33
+ string = field&.to_asciimath || ""
34
+ string.start_with?("(") ? string : "(#{string})"
35
+ end
9
36
  end
10
37
  end
11
38
  end
@@ -6,12 +6,18 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Substack < BinaryFunction
9
-
10
9
  def to_latex
11
10
  first_value = parameter_one.to_latex if parameter_one
12
11
  second_value = "\\\\#{parameter_two.to_latex}" if parameter_two
13
12
  "\\#{class_name}{#{first_value}#{second_value}}"
14
13
  end
14
+
15
+ def to_mathml_without_math_tag
16
+ value_array = []
17
+ value_array << parameter_one.to_mathml_without_math_tag if parameter_one
18
+ value_array << parameter_two.to_mathml_without_math_tag if parameter_two
19
+ Utility.update_nodes(Utility.ox_element("mtable"), value_array)
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -7,8 +7,8 @@ module Plurimath
7
7
  module Function
8
8
  class Sum < BinaryFunction
9
9
  def to_asciimath
10
- first_value = "_(#{parameter_one.to_asciimath})" if parameter_one
11
- second_value = "^(#{parameter_two.to_asciimath})" if parameter_two
10
+ first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
+ second_value = "^#{wrapped(parameter_two)}" if parameter_two
12
12
  "sum#{first_value}#{second_value}"
13
13
  end
14
14
 
@@ -17,6 +17,60 @@ module Plurimath
17
17
  second_value = "^{#{parameter_two.to_latex}}" if parameter_two
18
18
  "\\sum#{first_value}#{second_value}"
19
19
  end
20
+
21
+ def to_mathml_without_math_tag
22
+ first_value = Utility.ox_element("mo") << invert_unicode_symbols.to_s
23
+ if parameter_one || parameter_two
24
+ value_array = []
25
+ value_array << parameter_one&.to_mathml_without_math_tag
26
+ value_array << parameter_two&.to_mathml_without_math_tag
27
+ tag_name = if parameter_two && parameter_one
28
+ "underover"
29
+ else
30
+ parameter_one ? "under" : "over"
31
+ end
32
+ munderover_tag = Utility.ox_element("m#{tag_name}")
33
+ Utility.update_nodes(
34
+ munderover_tag,
35
+ value_array.insert(0, first_value),
36
+ )
37
+ else
38
+ first_value
39
+ end
40
+ end
41
+
42
+ def to_html
43
+ first_value = "<sub>#{parameter_one.to_html}</sub>" if parameter_one
44
+ second_value = "<sup>#{parameter_two.to_html}</sup>" if parameter_two
45
+ "<i>&sum;</i>#{first_value}#{second_value}"
46
+ end
47
+
48
+ def to_omml_without_math_tag
49
+ limupp = Utility.ox_element("limLow", namespace: "m")
50
+ limupppr = Utility.ox_element("limUppPr", namespace: "m")
51
+ sum << Utility.pr_element("e", true, namespace: "m")
52
+ me = (Utility.ox_element("e", namespace: "m") << omml_first_value)
53
+ lim = (Utility.ox_element("lim", namespace: "m") << omml_second_value)
54
+ Utility.update_nodes(limupp, [limupppr, me, lim])
55
+ end
56
+
57
+ protected
58
+
59
+ def omml_first_value
60
+ return parameter_one.to_omml_without_math_tag unless parameter_one.is_a?(Math::Symbol)
61
+
62
+ mt = Utility.ox_element("t", namespace: "m")
63
+ mt << parameter_one.to_omml_without_math_tag if parameter_one
64
+ mt
65
+ end
66
+
67
+ def omml_second_value
68
+ return parameter_two.to_omml_without_math_tag unless parameter_two.is_a?(Math::Symbol)
69
+
70
+ mt = Utility.ox_element("t", namespace: "m")
71
+ mt << parameter_two.to_omml_without_math_tag if parameter_two
72
+ mt
73
+ end
20
74
  end
21
75
  end
22
76
  end
@@ -6,6 +6,9 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Sup < UnaryFunction
9
+ def to_mathml_without_math_tag
10
+ Utility.ox_element("mo") << "sup"
11
+ end
9
12
  end
10
13
  end
11
14
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Align < Table
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Array < Table
10
+ def initialize(value = [],
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin{array}#{array_args}#{latex_content}\\end{array}"
19
+ end
20
+
21
+ def array_args
22
+ args = []
23
+ value.first.parameter_one.each do |td|
24
+ args << if Utility.symbol_value(td.parameter_one.first, "|")
25
+ "|"
26
+ else
27
+ Utility::ALIGNMENT_LETTERS.invert[Hash(td.parameter_two)[:columnalign]]&.to_s
28
+ end
29
+ end
30
+ "{#{args.join}}" unless args.compact.empty?
31
+ end
32
+
33
+ def to_mathml_without_math_tag
34
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
35
+ Utility.update_nodes(
36
+ table_tag,
37
+ value&.map(&:to_mathml_without_math_tag),
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Bmatrix < Table
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+
21
+ def to_mathml_without_math_tag
22
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
23
+ Utility.update_nodes(
24
+ table_tag,
25
+ value&.map(&:to_mathml_without_math_tag),
26
+ )
27
+ attributes = {
28
+ open: mathml_parenthesis(open_paren),
29
+ close: mathml_parenthesis(close_paren),
30
+ }
31
+ Utility.ox_element("mfenced", attributes: attributes) << table_tag
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Matrix < Table
10
+ def initialize(value = [],
11
+ open_paren = "(",
12
+ close_paren = ")",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+
21
+ def to_mathml_without_math_tag
22
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
23
+ Utility.update_nodes(
24
+ table_tag,
25
+ value&.map(&:to_mathml_without_math_tag),
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Multline < Table
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Pmatrix < Table
10
+ def initialize(value,
11
+ open_paren = "(",
12
+ close_paren = ")",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Split < Table
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../table"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Table
9
+ class Vmatrix < Table
10
+ def initialize(value,
11
+ open_paren = "|",
12
+ close_paren = "|",
13
+ options = {})
14
+ super
15
+ end
16
+
17
+ def to_latex
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end