plurimath 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rspec +3 -0
  4. data/.rspec-opal +11 -0
  5. data/Gemfile +3 -0
  6. data/Rakefile +11 -0
  7. data/lib/plurimath/asciimath/transform.rb +15 -0
  8. data/lib/plurimath/latex/constants.rb +3 -0
  9. data/lib/plurimath/latex/parse.rb +20 -11
  10. data/lib/plurimath/latex/transform.rb +24 -2
  11. data/lib/plurimath/math/core.rb +88 -0
  12. data/lib/plurimath/math/formula.rb +68 -24
  13. data/lib/plurimath/math/function/base.rb +8 -2
  14. data/lib/plurimath/math/function/binary_function.rb +36 -4
  15. data/lib/plurimath/math/function/color.rb +14 -0
  16. data/lib/plurimath/math/function/fenced.rb +27 -0
  17. data/lib/plurimath/math/function/floor.rb +1 -1
  18. data/lib/plurimath/math/function/font_style.rb +45 -0
  19. data/lib/plurimath/math/function/frac.rb +6 -0
  20. data/lib/plurimath/math/function/int.rb +7 -0
  21. data/lib/plurimath/math/function/left.rb +19 -1
  22. data/lib/plurimath/math/function/lim.rb +6 -0
  23. data/lib/plurimath/math/function/limits.rb +7 -0
  24. data/lib/plurimath/math/function/log.rb +6 -0
  25. data/lib/plurimath/math/function/menclose.rb +6 -0
  26. data/lib/plurimath/math/function/mod.rb +6 -0
  27. data/lib/plurimath/math/function/msgroup.rb +28 -0
  28. data/lib/plurimath/math/function/multiscript.rb +7 -0
  29. data/lib/plurimath/math/function/nary.rb +94 -0
  30. data/lib/plurimath/math/function/oint.rb +6 -0
  31. data/lib/plurimath/math/function/over.rb +6 -0
  32. data/lib/plurimath/math/function/overset.rb +6 -0
  33. data/lib/plurimath/math/function/power.rb +8 -2
  34. data/lib/plurimath/math/function/power_base.rb +10 -31
  35. data/lib/plurimath/math/function/prod.rb +19 -18
  36. data/lib/plurimath/math/function/right.rb +19 -1
  37. data/lib/plurimath/math/function/root.rb +6 -0
  38. data/lib/plurimath/math/function/rule.rb +7 -0
  39. data/lib/plurimath/math/function/semantics.rb +6 -0
  40. data/lib/plurimath/math/function/stackrel.rb +6 -0
  41. data/lib/plurimath/math/function/substack.rb +6 -0
  42. data/lib/plurimath/math/function/sum.rb +26 -25
  43. data/lib/plurimath/math/function/table.rb +52 -24
  44. data/lib/plurimath/math/function/td.rb +28 -0
  45. data/lib/plurimath/math/function/ternary_function.rb +44 -4
  46. data/lib/plurimath/math/function/text.rb +24 -2
  47. data/lib/plurimath/math/function/tr.rb +28 -0
  48. data/lib/plurimath/math/function/unary_function.rb +43 -3
  49. data/lib/plurimath/math/function/underover.rb +7 -55
  50. data/lib/plurimath/math/function/underset.rb +6 -0
  51. data/lib/plurimath/math/function/vec.rb +40 -0
  52. data/lib/plurimath/math/function.rb +7 -5
  53. data/lib/plurimath/math/number.rb +9 -5
  54. data/lib/plurimath/math/symbol.rb +13 -9
  55. data/lib/plurimath/math.rb +1 -3
  56. data/lib/plurimath/mathml/parser.rb +4 -4
  57. data/lib/plurimath/mathml/transform.rb +3 -4
  58. data/lib/plurimath/omml/parser.rb +3 -3
  59. data/lib/plurimath/omml/transform.rb +12 -11
  60. data/lib/plurimath/setup/oga.rb +5 -0
  61. data/lib/plurimath/setup/opal.rb.erb +8 -0
  62. data/lib/plurimath/setup/ox.rb +5 -0
  63. data/lib/plurimath/utility.rb +48 -13
  64. data/lib/plurimath/version.rb +1 -1
  65. data/lib/plurimath/xml_engine/oga.rb +246 -0
  66. data/lib/plurimath/xml_engine/ox.rb +29 -0
  67. data/lib/plurimath/xml_engine.rb +6 -0
  68. data/lib/plurimath.rb +12 -2
  69. metadata +11 -2
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Frac < BinaryFunction
9
+ FUNCTION = {
10
+ name: "fraction",
11
+ first_value: "numerator",
12
+ second_value: "denominator",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  first_value = "(#{parameter_one&.to_asciimath})" if parameter_one
11
17
  second_value = "(#{parameter_two&.to_asciimath})" if parameter_two
@@ -6,6 +6,13 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Int < TernaryFunction
9
+ FUNCTION = {
10
+ name: "integral",
11
+ first_value: "lower limit",
12
+ second_value: "upper limit",
13
+ third_value: "integrand"
14
+ }
15
+
9
16
  def to_asciimath
10
17
  first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
18
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
@@ -30,13 +30,31 @@ module Plurimath
30
30
  end
31
31
 
32
32
  def to_latex
33
- "\\left #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'}"
33
+ "\\left #{latex_paren}"
34
34
  end
35
35
 
36
36
  def validate_function_formula
37
37
  false
38
38
  end
39
39
 
40
+ def to_asciimath_math_zone(spacing = "", _, _)
41
+ "#{spacing}\"#{latex_paren}\" left\n"
42
+ end
43
+
44
+ def to_latex_math_zone(spacing = "", _, _)
45
+ "#{spacing}\"#{latex_paren}\" left\n"
46
+ end
47
+
48
+ def to_mathml_math_zone(spacing = "", _, _)
49
+ mo_tag = (Utility.ox_element("mo") << left_paren)
50
+ "#{spacing}\"#{dump_ox_nodes(mo_tag).gsub(/\s+/, "")}\" left\n"
51
+ end
52
+
53
+ def to_omml_math_zone(spacing = "", _, _, display_style:)
54
+ t_tag = (Utility.ox_element("t", namespace: "m") << left_paren)
55
+ "#{spacing}\"#{dump_ox_nodes(t_tag).gsub(/\s+/, "")}\" left\n"
56
+ end
57
+
40
58
  protected
41
59
 
42
60
  def left_paren
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Lim < BinaryFunction
9
+ FUNCTION = {
10
+ name: "limit",
11
+ first_value: "limit subscript",
12
+ second_value: "limit supscript",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
17
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
@@ -6,6 +6,13 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Limits < TernaryFunction
9
+ FUNCTION = {
10
+ name: "function apply",
11
+ first_value: "base",
12
+ second_value: "subscript",
13
+ third_value: "supscript",
14
+ }.freeze
15
+
9
16
  def to_mathml_without_math_tag
10
17
  underover = Utility.ox_element("munderover")
11
18
  value_array = []
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Log < BinaryFunction
9
+ FUNCTION = {
10
+ name: "function apply",
11
+ first_value: "subscript",
12
+ second_value: "supscript",
13
+ }
14
+
9
15
  def to_asciimath
10
16
  first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
17
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Menclose < BinaryFunction
9
+ FUNCTION = {
10
+ name: "enclosure",
11
+ first_value: "enclosure type",
12
+ second_value: "expression",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  parameter_two&.to_asciimath
11
17
  end
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Mod < BinaryFunction
9
+ FUNCTION = {
10
+ name: "mod",
11
+ first_value: "base",
12
+ second_value: "argument",
13
+ }
14
+
9
15
  def to_asciimath
10
16
  first_value = parameter_one&.to_asciimath
11
17
  second_value = parameter_two&.to_asciimath
@@ -28,6 +28,34 @@ module Plurimath
28
28
  def to_html
29
29
  "<i>#{parameter_one.map(&:to_html).join}</i>"
30
30
  end
31
+
32
+ def to_asciimath_math_zone(spacing, last = false, _indent = true)
33
+ [
34
+ "#{spacing}\"msgroup\" function apply\n",
35
+ Formula.new(parameter_one).to_asciimath_math_zone(gsub_spacing(spacing, last)),
36
+ ]
37
+ end
38
+
39
+ def to_latex_math_zone(spacing, last = false, indent = true)
40
+ [
41
+ "#{spacing}\"msgroup\" function apply\n",
42
+ Formula.new(parameter_one).to_latex_math_zone(gsub_spacing(spacing, last), last, indent),
43
+ ]
44
+ end
45
+
46
+ def to_mathml_math_zone(spacing, last = false, indent = true)
47
+ [
48
+ "#{spacing}\"msgroup\" function apply\n",
49
+ Formula.new(parameter_one).to_mathml_math_zone(gsub_spacing(spacing, last), last, indent),
50
+ ]
51
+ end
52
+
53
+ def to_omml_math_zone(spacing, last = false, indent = true, display_style:)
54
+ [
55
+ "#{spacing}\"msgroup\" function apply\n",
56
+ Formula.new(parameter_one).to_omml_math_zone(gsub_spacing(spacing, last), last, indent, display_style: display_style),
57
+ ]
58
+ end
31
59
  end
32
60
  end
33
61
  end
@@ -5,6 +5,13 @@ module Plurimath
5
5
  module Math
6
6
  module Function
7
7
  class Multiscript < TernaryFunction
8
+ FUNCTION = {
9
+ name: "multiscript",
10
+ first_value: "base",
11
+ second_value: "subscript",
12
+ third_value: "supscript",
13
+ }.freeze
14
+
8
15
  def to_omml_without_math_tag(display_style)
9
16
  pre_element = Utility.ox_element("sPre", namespace: "m")
10
17
  pr_element = Utility.ox_element("sPrePr", namespace: "m")
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ module Math
5
+ module Function
6
+ class Nary < Core
7
+ attr_accessor :parameter_one, :parameter_two, :parameter_three, :parameter_four, :options
8
+
9
+ def initialize(parameter_one = nil,
10
+ parameter_two = nil,
11
+ parameter_three = nil,
12
+ parameter_four = nil,
13
+ options = {})
14
+ @parameter_one = parameter_one
15
+ @parameter_two = parameter_two
16
+ @parameter_three = parameter_three
17
+ @parameter_four = parameter_four
18
+ @options = options
19
+ Utility.validate_left_right([parameter_one, parameter_two, parameter_three, parameter_four])
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
+ object.parameter_four == parameter_four &&
28
+ object.options == options
29
+ end
30
+
31
+ def to_asciimath
32
+ first_value = parameter_one&.to_asciimath || "int"
33
+ second_value = "_#{parameter_two.to_asciimath}" if parameter_two
34
+ third_value = "^#{parameter_three.to_asciimath}" if parameter_three
35
+ fourth_value = " #{parameter_four.to_asciimath}" if parameter_four
36
+ "#{first_value}#{second_value}#{third_value}#{fourth_value}"
37
+ end
38
+
39
+ def to_latex
40
+ first_value = parameter_one&.to_latex || "\\int"
41
+ second_value = "_#{parameter_two.to_latex}" if parameter_two
42
+ third_value = "^#{parameter_three.to_latex}" if parameter_three
43
+ fourth_value = "{#{parameter_four.to_latex}}" if parameter_four
44
+ "#{first_value}#{second_value}#{third_value}#{fourth_value}"
45
+ end
46
+
47
+ def to_mathml_without_math_tag
48
+ tag_name = options[:type] == "undOvr" ? "munderover" : "msubsup"
49
+ subsup_tag = Utility.ox_element(tag_name)
50
+ new_arr = []
51
+ new_arr << validate_mathml_fields(parameter_one)
52
+ new_arr << validate_mathml_fields(parameter_two)
53
+ new_arr << validate_mathml_fields(parameter_three)
54
+ Utility.update_nodes(subsup_tag, new_arr)
55
+ end
56
+
57
+ def to_omml_without_math_tag(display_style)
58
+ nary_element = Utility.ox_element("nary", namespace: "m")
59
+ Utility.update_nodes(nary_element, omml_nary_tag(display_style))
60
+ Array(nary_element)
61
+ end
62
+
63
+ protected
64
+
65
+ def chr_value(narypr)
66
+ first_value = Utility.html_entity_to_unicode(parameter_one&.nary_attr_value)
67
+ narypr << Utility.ox_element("chr", namespace: "m", attributes: { "m:val": first_value }) unless first_value == "∫"
68
+
69
+ narypr << Utility.ox_element("limLoc", namespace: "m", attributes: { "m:val": options[:type].to_s })
70
+ hide_tags(narypr, parameter_two, "sub")
71
+ hide_tags(narypr, parameter_three, "sup")
72
+ narypr
73
+ end
74
+
75
+ def hide_tags(nar, field, tag_prefix)
76
+ return nar unless field.nil?
77
+
78
+ nar << Utility.ox_element("#{tag_prefix}Hide", namespace: "m", attributes: { "m:val": "1" })
79
+ end
80
+
81
+ def omml_nary_tag(display_style)
82
+ narypr = Utility.ox_element("naryPr", namespace: "m")
83
+ chr_value(narypr)
84
+ [
85
+ (narypr << Utility.pr_element("ctrl", true, namespace: "m")),
86
+ omml_parameter(parameter_two, display_style, tag_name: "sub"),
87
+ omml_parameter(parameter_three, display_style, tag_name: "sup"),
88
+ omml_parameter(parameter_four, display_style, tag_name: "e"),
89
+ ]
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Oint < TernaryFunction
9
+ FUNCTION = {
10
+ name: "contour integral",
11
+ first_value: "subscript",
12
+ second_value: "supscript",
13
+ }
14
+
9
15
  def to_asciimath
10
16
  first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
17
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Over < BinaryFunction
9
+ FUNCTION = {
10
+ name: "over",
11
+ first_value: "numerator",
12
+ second_value: "denominator",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  first_value = wrapped(parameter_one)
11
17
  second_value = wrapped(parameter_two)
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Overset < BinaryFunction
9
+ FUNCTION = {
10
+ name: "overset",
11
+ first_value: "base",
12
+ second_value: "supscript",
13
+ }.freeze
14
+
9
15
  def to_mathml_without_math_tag
10
16
  first_value = parameter_one&.to_mathml_without_math_tag
11
17
  second_value = parameter_two&.to_mathml_without_math_tag
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Power < BinaryFunction
9
+ FUNCTION = {
10
+ name: "superscript",
11
+ first_value: "base",
12
+ second_value: "script",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
11
17
  "#{parameter_one.to_asciimath}#{second_value}"
@@ -14,8 +20,8 @@ module Plurimath
14
20
  def to_mathml_without_math_tag
15
21
  tag_name = (["ubrace", "obrace"].include?(parameter_one&.class_name) ? "over" : "sup")
16
22
  sup_tag = Utility.ox_element("m#{tag_name}")
17
- mathml_value = [parameter_one.to_mathml_without_math_tag]
18
- mathml_value << parameter_two&.to_mathml_without_math_tag
23
+ mathml_value = [validate_mathml_fields(parameter_one)]
24
+ mathml_value << validate_mathml_fields(parameter_two)
19
25
  Utility.update_nodes(sup_tag, mathml_value)
20
26
  end
21
27
 
@@ -6,12 +6,19 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class PowerBase < TernaryFunction
9
+ FUNCTION = {
10
+ name: "subsup",
11
+ first_value: "base",
12
+ second_value: "subscript",
13
+ third_value: "supscript",
14
+ }.freeze
15
+
9
16
  def to_mathml_without_math_tag
10
17
  subsup_tag = Utility.ox_element("m#{parameter_one.tag_name}")
11
18
  new_arr = []
12
- new_arr << parameter_one.to_mathml_without_math_tag
13
- new_arr << parameter_two&.to_mathml_without_math_tag
14
- new_arr << parameter_three&.to_mathml_without_math_tag
19
+ new_arr << validate_mathml_fields(parameter_one)
20
+ new_arr << validate_mathml_fields(parameter_two)
21
+ new_arr << validate_mathml_fields(parameter_three)
15
22
  Utility.update_nodes(subsup_tag, new_arr)
16
23
  end
17
24
 
@@ -29,23 +36,6 @@ module Plurimath
29
36
  "#{first_value}#{second_value}#{third_value}"
30
37
  end
31
38
 
32
- def omml_nary_tag(display_style)
33
- narypr = Utility.ox_element("naryPr", namespace: "m")
34
- chr_value(narypr)
35
- narypr << Utility.ox_element(
36
- "limLoc",
37
- namespace: "m",
38
- attributes: { "m:val": parameter_one.omml_tag_name },
39
- )
40
- hide_tags(narypr)
41
- narypr << Utility.pr_element("ctrl", true, namespace: "m")
42
- [
43
- narypr,
44
- omml_parameter(parameter_two, display_style, tag_name: "sub"),
45
- omml_parameter(parameter_three, display_style, tag_name: "sup"),
46
- ]
47
- end
48
-
49
39
  def to_omml_without_math_tag(display_style)
50
40
  return underover(display_style) if parameter_one.omml_tag_name == "undOvr"
51
41
 
@@ -68,17 +58,6 @@ module Plurimath
68
58
 
69
59
  protected
70
60
 
71
- def chr_value(narypr)
72
- first_value = Utility.html_entity_to_unicode(parameter_one&.nary_attr_value)
73
- return narypr if first_value == "∫"
74
-
75
- narypr << Utility.ox_element(
76
- "chr",
77
- namespace: "m",
78
- attributes: { "m:val": first_value },
79
- )
80
- end
81
-
82
61
  def hide_tags(nar)
83
62
  attr = { "m:val": "1" }
84
63
  if parameter_two.nil?
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Prod < TernaryFunction
9
+ FUNCTION = {
10
+ name: "prod",
11
+ first_value: "subscript",
12
+ second_value: "supscript",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
17
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
@@ -55,24 +61,19 @@ module Plurimath
55
61
  end
56
62
 
57
63
  def to_omml_without_math_tag(display_style)
58
- if all_values_exist?
59
- nary = Utility.ox_element("nary", namespace: "m")
60
- Utility.update_nodes(
61
- nary,
62
- [
63
- narypr("∏"),
64
- omml_parameter(parameter_one, display_style, tag_name: "sub"),
65
- omml_parameter(parameter_two, display_style, tag_name: "sup"),
66
- omml_parameter(parameter_three, display_style, tag_name: "e"),
67
- ],
68
- )
69
- [nary]
70
- else
71
- r_tag = Utility.ox_element("r", namespace: "m")
72
- t_tag = Utility.ox_element("t", namespace: "m")
73
- r_tag << (t_tag << "&#x220f;")
74
- [r_tag]
75
- end
64
+ return r_element("&#x220f;", rpr_tag: false) unless all_values_exist?
65
+
66
+ nary = Utility.ox_element("nary", namespace: "m")
67
+ Utility.update_nodes(
68
+ nary,
69
+ [
70
+ narypr(""),
71
+ omml_parameter(parameter_one, display_style, tag_name: "sub"),
72
+ omml_parameter(parameter_two, display_style, tag_name: "sup"),
73
+ omml_parameter(parameter_three, display_style, tag_name: "e"),
74
+ ],
75
+ )
76
+ [nary]
76
77
  end
77
78
 
78
79
  def nary_attr_value
@@ -30,13 +30,31 @@ module Plurimath
30
30
  end
31
31
 
32
32
  def to_latex
33
- "\\right #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'}"
33
+ "\\right #{latex_paren}"
34
34
  end
35
35
 
36
36
  def validate_function_formula
37
37
  false
38
38
  end
39
39
 
40
+ def to_asciimath_math_zone(spacing = "", _, _)
41
+ "#{spacing}\"#{latex_paren}\" right\n"
42
+ end
43
+
44
+ def to_latex_math_zone(spacing = "", _, _)
45
+ "#{spacing}\"#{latex_paren}\" right\n"
46
+ end
47
+
48
+ def to_mathml_math_zone(spacing = "", _, _)
49
+ mo_tag = (Utility.ox_element("mo") << right_paren)
50
+ "#{spacing}\"#{dump_ox_nodes(mo_tag).gsub(/\s+/, "")}\" right\n"
51
+ end
52
+
53
+ def to_omml_math_zone(spacing = "", _, _, display_style:)
54
+ t_tag = (Utility.ox_element("t", namespace: "m") << right_paren)
55
+ "#{spacing}\"#{dump_ox_nodes(t_tag).gsub(/\s+/, "")}\" right\n"
56
+ end
57
+
40
58
  protected
41
59
 
42
60
  def right_paren
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Root < BinaryFunction
9
+ FUNCTION = {
10
+ name: "root",
11
+ first_value: "radicand",
12
+ second_value: "index",
13
+ }.freeze
14
+
9
15
  def to_mathml_without_math_tag
10
16
  first_value = parameter_one&.to_mathml_without_math_tag
11
17
  second_value = parameter_two&.to_mathml_without_math_tag
@@ -5,6 +5,13 @@ module Plurimath
5
5
  module Math
6
6
  module Function
7
7
  class Rule < TernaryFunction
8
+ FUNCTION = {
9
+ name: "rule",
10
+ first_value: "first argument",
11
+ second_value: "second argument",
12
+ third_value: "third argument",
13
+ }.freeze
14
+
8
15
  def to_asciimath
9
16
  ""
10
17
  end
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Semantics < BinaryFunction
9
+ FUNCTION = {
10
+ name: "semantics",
11
+ first_value: "first argument",
12
+ second_value: "second argument",
13
+ }.freeze
14
+
9
15
  def to_mathml_without_math_tag
10
16
  first_value = parameter_one&.to_mathml_without_math_tag
11
17
  second_value = other_tags(parameter_two)
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Stackrel < BinaryFunction
9
+ FUNCTION = {
10
+ name: "stackrel",
11
+ first_value: "above",
12
+ second_value: "below",
13
+ }.freeze
14
+
9
15
  def to_asciimath
10
16
  first_value = wrapped(parameter_one)
11
17
  second_value = wrapped(parameter_two)
@@ -6,6 +6,12 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Substack < BinaryFunction
9
+ FUNCTION = {
10
+ name: "substack",
11
+ first_value: "above",
12
+ second_value: "below",
13
+ }.freeze
14
+
9
15
  def to_latex
10
16
  first_value = parameter_one.to_latex if parameter_one
11
17
  second_value = "\\\\#{parameter_two.to_latex}" if parameter_two
@@ -6,6 +6,13 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Sum < TernaryFunction
9
+ FUNCTION = {
10
+ name: "summation",
11
+ first_value: "subscript",
12
+ second_value: "supscript",
13
+ third_value: "term",
14
+ }.freeze
15
+
9
16
  def to_asciimath
10
17
  first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
18
  second_value = "^#{wrapped(parameter_two)}" if parameter_two
@@ -20,32 +27,26 @@ module Plurimath
20
27
 
21
28
  def to_mathml_without_math_tag
22
29
  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
- return munderover_tag if parameter_three.nil?
30
+ return first_value unless parameter_one || parameter_two
38
31
 
39
- Utility.update_nodes(
40
- Utility.ox_element("mrow"),
41
- [
42
- munderover_tag,
43
- parameter_three&.to_mathml_without_math_tag,
44
- ].flatten.compact,
45
- )
46
- else
47
- first_value
48
- end
32
+ value_array = [parameter_one&.to_mathml_without_math_tag]
33
+ value_array << parameter_two&.to_mathml_without_math_tag
34
+ tag_name = if parameter_two && parameter_one
35
+ "underover"
36
+ else
37
+ parameter_one ? "under" : "over"
38
+ end
39
+ munderover_tag = Utility.ox_element("m#{tag_name}")
40
+ Utility.update_nodes(munderover_tag, value_array.insert(0, first_value))
41
+ return munderover_tag if parameter_three.nil?
42
+
43
+ Utility.update_nodes(
44
+ Utility.ox_element("mrow"),
45
+ [
46
+ munderover_tag,
47
+ parameter_three&.to_mathml_without_math_tag,
48
+ ].flatten.compact,
49
+ )
49
50
  end
50
51
 
51
52
  def to_html