plurimath 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) 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 +4 -0
  6. data/Rakefile +11 -0
  7. data/lib/plurimath/asciimath/parse.rb +3 -2
  8. data/lib/plurimath/asciimath/transform.rb +47 -5
  9. data/lib/plurimath/latex/constants.rb +5 -1
  10. data/lib/plurimath/latex/parse.rb +20 -11
  11. data/lib/plurimath/latex/transform.rb +32 -14
  12. data/lib/plurimath/math/core.rb +212 -10
  13. data/lib/plurimath/math/formula.rb +154 -40
  14. data/lib/plurimath/math/function/abs.rb +28 -15
  15. data/lib/plurimath/math/function/bar.rb +5 -0
  16. data/lib/plurimath/math/function/base.rb +22 -2
  17. data/lib/plurimath/math/function/binary_function.rb +38 -12
  18. data/lib/plurimath/math/function/ceil.rb +24 -9
  19. data/lib/plurimath/math/function/color.rb +14 -0
  20. data/lib/plurimath/math/function/ddot.rb +6 -1
  21. data/lib/plurimath/math/function/deg.rb +4 -1
  22. data/lib/plurimath/math/function/det.rb +4 -1
  23. data/lib/plurimath/math/function/dim.rb +4 -1
  24. data/lib/plurimath/math/function/dot.rb +5 -0
  25. data/lib/plurimath/math/function/exp.rb +4 -1
  26. data/lib/plurimath/math/function/fenced.rb +51 -15
  27. data/lib/plurimath/math/function/floor.rb +24 -14
  28. data/lib/plurimath/math/function/font_style.rb +63 -8
  29. data/lib/plurimath/math/function/frac.rb +38 -18
  30. data/lib/plurimath/math/function/gcd.rb +4 -1
  31. data/lib/plurimath/math/function/glb.rb +8 -1
  32. data/lib/plurimath/math/function/hat.rb +16 -5
  33. data/lib/plurimath/math/function/hom.rb +4 -1
  34. data/lib/plurimath/math/function/inf.rb +16 -0
  35. data/lib/plurimath/math/function/int.rb +35 -9
  36. data/lib/plurimath/math/function/ker.rb +4 -1
  37. data/lib/plurimath/math/function/lcm.rb +17 -1
  38. data/lib/plurimath/math/function/left.rb +20 -2
  39. data/lib/plurimath/math/function/lg.rb +4 -1
  40. data/lib/plurimath/math/function/lim.rb +16 -0
  41. data/lib/plurimath/math/function/liminf.rb +4 -1
  42. data/lib/plurimath/math/function/limits.rb +29 -9
  43. data/lib/plurimath/math/function/limsup.rb +4 -1
  44. data/lib/plurimath/math/function/linebreak.rb +95 -0
  45. data/lib/plurimath/math/function/ln.rb +4 -1
  46. data/lib/plurimath/math/function/log.rb +27 -12
  47. data/lib/plurimath/math/function/longdiv.rb +19 -0
  48. data/lib/plurimath/math/function/lub.rb +4 -1
  49. data/lib/plurimath/math/function/max.rb +4 -1
  50. data/lib/plurimath/math/function/mbox.rb +8 -7
  51. data/lib/plurimath/math/function/menclose.rb +6 -0
  52. data/lib/plurimath/math/function/merror.rb +12 -3
  53. data/lib/plurimath/math/function/min.rb +4 -1
  54. data/lib/plurimath/math/function/mod.rb +48 -15
  55. data/lib/plurimath/math/function/msgroup.rb +32 -0
  56. data/lib/plurimath/math/function/msline.rb +10 -0
  57. data/lib/plurimath/math/function/multiscript.rb +27 -0
  58. data/lib/plurimath/math/function/nary.rb +128 -0
  59. data/lib/plurimath/math/function/norm.rb +24 -15
  60. data/lib/plurimath/math/function/obrace.rb +5 -0
  61. data/lib/plurimath/math/function/oint.rb +48 -20
  62. data/lib/plurimath/math/function/over.rb +29 -10
  63. data/lib/plurimath/math/function/overset.rb +19 -10
  64. data/lib/plurimath/math/function/phantom.rb +24 -6
  65. data/lib/plurimath/math/function/power.rb +19 -4
  66. data/lib/plurimath/math/function/power_base.rb +34 -33
  67. data/lib/plurimath/math/function/prod.rb +43 -23
  68. data/lib/plurimath/math/function/right.rb +20 -2
  69. data/lib/plurimath/math/function/root.rb +6 -0
  70. data/lib/plurimath/math/function/rule.rb +8 -1
  71. data/lib/plurimath/math/function/scarries.rb +14 -0
  72. data/lib/plurimath/math/function/semantics.rb +15 -0
  73. data/lib/plurimath/math/function/sqrt.rb +5 -0
  74. data/lib/plurimath/math/function/stackrel.rb +14 -0
  75. data/lib/plurimath/math/function/substack.rb +18 -51
  76. data/lib/plurimath/math/function/sum.rb +36 -12
  77. data/lib/plurimath/math/function/sup.rb +11 -2
  78. data/lib/plurimath/math/function/table/array.rb +1 -1
  79. data/lib/plurimath/math/function/table/matrix.rb +4 -0
  80. data/lib/plurimath/math/function/table.rb +62 -26
  81. data/lib/plurimath/math/function/td.rb +42 -4
  82. data/lib/plurimath/math/function/ternary_function.rb +48 -10
  83. data/lib/plurimath/math/function/text.rb +25 -3
  84. data/lib/plurimath/math/function/tilde.rb +5 -0
  85. data/lib/plurimath/math/function/tr.rb +29 -1
  86. data/lib/plurimath/math/function/ubrace.rb +5 -0
  87. data/lib/plurimath/math/function/unary_function.rb +115 -29
  88. data/lib/plurimath/math/function/underover.rb +27 -58
  89. data/lib/plurimath/math/function/underset.rb +25 -9
  90. data/lib/plurimath/math/function/vec.rb +45 -0
  91. data/lib/plurimath/math/function.rb +7 -5
  92. data/lib/plurimath/math/number.rb +12 -8
  93. data/lib/plurimath/math/symbol.rb +25 -13
  94. data/lib/plurimath/math.rb +1 -3
  95. data/lib/plurimath/mathml/parser.rb +6 -4
  96. data/lib/plurimath/mathml/transform.rb +26 -19
  97. data/lib/plurimath/omml/parser.rb +3 -3
  98. data/lib/plurimath/omml/transform.rb +34 -21
  99. data/lib/plurimath/setup/oga.rb +5 -0
  100. data/lib/plurimath/setup/opal.rb.erb +8 -0
  101. data/lib/plurimath/setup/ox.rb +5 -0
  102. data/lib/plurimath/unitsml.rb +2 -1
  103. data/lib/plurimath/utility.rb +77 -41
  104. data/lib/plurimath/version.rb +1 -1
  105. data/lib/plurimath/xml_engine/oga.rb +246 -0
  106. data/lib/plurimath/xml_engine/ox.rb +29 -0
  107. data/lib/plurimath/xml_engine.rb +6 -0
  108. data/lib/plurimath.rb +12 -2
  109. metadata +12 -3
  110. data/lib/plurimath/math/function/scarry.rb +0 -12
@@ -0,0 +1,128 @@
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 = ox_element(tag_name)
50
+ new_arr = [
51
+ validate_mathml_fields(parameter_one),
52
+ validate_mathml_fields(parameter_two),
53
+ validate_mathml_fields(parameter_three),
54
+ ]
55
+ Utility.update_nodes(subsup_tag, new_arr)
56
+ return subsup_tag unless parameter_four
57
+
58
+ Utility.update_nodes(
59
+ ox_element("mrow"),
60
+ [
61
+ subsup_tag,
62
+ parameter_four&.to_mathml_without_math_tag,
63
+ ],
64
+ )
65
+ end
66
+
67
+ def to_omml_without_math_tag(display_style)
68
+ nary_element = Utility.ox_element("nary", namespace: "m")
69
+ Utility.update_nodes(nary_element, omml_nary_tag(display_style))
70
+ Array(nary_element)
71
+ end
72
+
73
+ def line_breaking(obj)
74
+ parameter_one&.line_breaking(obj)
75
+ if obj.value_exist?
76
+ obj.update(self.class.new(Utility.filter_values(obj.value), self.parameter_two, self.parameter_three, self.parameter_four))
77
+ self.parameter_two = nil
78
+ self.parameter_three = nil
79
+ self.parameter_four = nil
80
+ return
81
+ end
82
+
83
+ parameter_two&.line_breaking(obj)
84
+ if obj.value_exist?
85
+ obj.update(self.class.new(nil, Utility.filter_values(obj.value), self.parameter_three, self.parameter_four))
86
+ self.parameter_three = nil
87
+ self.parameter_four = nil
88
+ return
89
+ end
90
+
91
+ parameter_four&.line_breaking(obj)
92
+ if obj.value_exist?
93
+ obj.update(Utility.filter_values(obj.value))
94
+ end
95
+ end
96
+
97
+ protected
98
+
99
+ def chr_value(narypr)
100
+ first_value = Utility.html_entity_to_unicode(parameter_one&.nary_attr_value)
101
+ narypr << Utility.ox_element("chr", namespace: "m", attributes: { "m:val": first_value }) unless first_value == "∫"
102
+
103
+ narypr << Utility.ox_element("limLoc", namespace: "m", attributes: { "m:val": options[:type].to_s })
104
+ hide_tags(narypr, parameter_two, "sub")
105
+ hide_tags(narypr, parameter_three, "sup")
106
+ narypr
107
+ end
108
+
109
+ def hide_tags(nar, field, tag_prefix)
110
+ return nar unless field.nil?
111
+
112
+ nar << Utility.ox_element("#{tag_prefix}Hide", namespace: "m", attributes: { "m:val": "1" })
113
+ end
114
+
115
+ def omml_nary_tag(display_style)
116
+ narypr = Utility.ox_element("naryPr", namespace: "m")
117
+ chr_value(narypr)
118
+ [
119
+ (narypr << Utility.pr_element("ctrl", true, namespace: "m")),
120
+ omml_parameter(parameter_two, display_style, tag_name: "sub"),
121
+ omml_parameter(parameter_three, display_style, tag_name: "sup"),
122
+ omml_parameter(parameter_four, display_style, tag_name: "e"),
123
+ ]
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -6,6 +6,8 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Norm < UnaryFunction
9
+ attr_accessor :open_paren, :close_paren
10
+
9
11
  def to_asciimath
10
12
  parameter_one.is_a?(Table) ? "norm#{parameter_one.to_asciimath}" : super
11
13
  end
@@ -15,24 +17,31 @@ module Plurimath
15
17
  end
16
18
 
17
19
  def to_mathml_without_math_tag
18
- first_value = parameter_one&.to_mathml_without_math_tag
19
- norm = Utility.ox_element("mo") << "&#x2225;"
20
- Utility.update_nodes(
21
- Utility.ox_element("mrow"),
22
- [
23
- norm,
24
- first_value,
25
- norm,
26
- ],
27
- )
20
+ first_value = Array(parameter_one&.to_mathml_without_math_tag)
21
+ norm = ox_element("mo") << "&#x2225;"
22
+ first_value = first_value.insert(0, norm) unless open_paren
23
+ first_value = first_value << norm unless close_paren
24
+ Utility.update_nodes(ox_element("mrow"), first_value)
28
25
  end
29
26
 
30
27
  def to_omml_without_math_tag(display_style)
31
- [
32
- r_element("∥"),
33
- omml_value(display_style),
34
- r_element("∥"),
35
- ]
28
+ array = []
29
+ array << r_element("∥") unless open_paren
30
+ array += Array(omml_value(display_style))
31
+ array << r_element("∥") unless close_paren
32
+ array
33
+ end
34
+
35
+ def line_breaking(obj)
36
+ parameter_one.line_breaking(obj)
37
+ if obj.value_exist?
38
+ norm_object = self.class.new(Utility.filter_values(obj.value))
39
+ norm_object.open_paren = true
40
+ norm_object.close_paren = false
41
+ obj.update(norm_object)
42
+ self.close_paren = true
43
+ self.open_paren = false unless open_paren
44
+ end
36
45
  end
37
46
  end
38
47
  end
@@ -53,6 +53,11 @@ module Plurimath
53
53
  end
54
54
  end
55
55
 
56
+ def line_breaking(obj)
57
+ parameter_one&.line_breaking(obj)
58
+ obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
59
+ end
60
+
56
61
  protected
57
62
 
58
63
  def acc_tag(display_style)
@@ -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
@@ -19,28 +25,33 @@ module Plurimath
19
25
  end
20
26
 
21
27
  def to_mathml_without_math_tag
22
- mo_tag = Utility.ox_element("mo") << invert_unicode_symbols.to_s
28
+ mo_tag = ox_element("mo")
29
+ mo_tag << invert_unicode_symbols.to_s unless hide_function_name
23
30
  return mo_tag unless all_values_exist?
24
31
 
25
- value_array = [mo_tag]
26
- value_array << parameter_one&.to_mathml_without_math_tag
27
- value_array << parameter_two&.to_mathml_without_math_tag
28
- tag_name = if parameter_one && parameter_two
29
- "subsup"
30
- else
31
- parameter_one ? "sub" : "sup"
32
- end
33
- msubsup_tag = Utility.ox_element("m#{tag_name}")
34
- Utility.update_nodes(msubsup_tag, value_array)
35
- return msubsup_tag if parameter_three.nil?
32
+ if parameter_one || parameter_two
33
+ value_array = [
34
+ mo_tag,
35
+ parameter_one&.to_mathml_without_math_tag,
36
+ parameter_two&.to_mathml_without_math_tag,
37
+ ]
38
+ tag_name = if parameter_one && parameter_two
39
+ "subsup"
40
+ else
41
+ parameter_one ? "sub" : "sup"
42
+ end
43
+ msubsup_tag = ox_element("m#{tag_name}")
44
+ Utility.update_nodes(msubsup_tag, value_array)
45
+ return msubsup_tag unless parameter_three
36
46
 
37
- Utility.update_nodes(
38
- Utility.ox_element("mrow"),
39
- [
40
- msubsup_tag,
41
- parameter_three&.to_mathml_without_math_tag,
42
- ].compact,
43
- )
47
+ Utility.update_nodes(
48
+ ox_element("mrow"),
49
+ [
50
+ msubsup_tag,
51
+ parameter_three&.to_mathml_without_math_tag,
52
+ ],
53
+ )
54
+ end
44
55
  end
45
56
 
46
57
  def to_omml_without_math_tag(display_style)
@@ -49,7 +60,7 @@ module Plurimath
49
60
  Utility.update_nodes(
50
61
  nary,
51
62
  [
52
- narypr("∮", function_type: "subSup"),
63
+ narypr((hide_function_name ? "" : "∮"), function_type: "subSup"),
53
64
  omml_parameter(parameter_one, display_style, tag_name: "sub"),
54
65
  omml_parameter(parameter_two, display_style, tag_name: "sup"),
55
66
  omml_parameter(parameter_three, display_style, tag_name: "e"),
@@ -63,6 +74,23 @@ module Plurimath
63
74
  [r_tag]
64
75
  end
65
76
  end
77
+
78
+ def line_breaking(obj)
79
+ parameter_one&.line_breaking(obj)
80
+ if obj.value_exist?
81
+ oint = self.class.new(Utility.filter_values(obj.value), parameter_two, parameter_three)
82
+ oint.hide_function_name = true
83
+ obj.update(oint)
84
+ self.parameter_two = nil
85
+ self.parameter_three = nil
86
+ return
87
+ end
88
+
89
+ parameter_three&.line_breaking(obj)
90
+ if obj.value_exist?
91
+ obj.update(Utility.filter_values(obj.value))
92
+ end
93
+ end
66
94
  end
67
95
  end
68
96
  end
@@ -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)
@@ -13,16 +19,12 @@ module Plurimath
13
19
  end
14
20
 
15
21
  def to_mathml_without_math_tag
16
- mover_tag = Utility.ox_element("mfrac")
17
- first_value = parameter_one&.to_mathml_without_math_tag
18
- second_value = parameter_two&.to_mathml_without_math_tag
19
- Utility.update_nodes(
20
- mover_tag,
21
- [
22
- first_value,
23
- second_value,
24
- ],
25
- )
22
+ tag_name = hide_function_name ? "mrow" : "mfrac"
23
+ mathml_value = [
24
+ parameter_one&.to_mathml_without_math_tag,
25
+ parameter_two&.to_mathml_without_math_tag,
26
+ ]
27
+ Utility.update_nodes(ox_element(tag_name), mathml_value)
26
28
  end
27
29
 
28
30
  def to_latex
@@ -44,6 +46,23 @@ module Plurimath
44
46
  )
45
47
  [f_element]
46
48
  end
49
+
50
+ def line_breaking(obj)
51
+ parameter_one&.line_breaking(obj)
52
+ if obj.value_exist?
53
+ obj.update(self.class.new(Utility.filter_values(obj.value), parameter_two))
54
+ self.parameter_two = nil
55
+ self.hide_function_name = true
56
+ return
57
+ end
58
+
59
+ parameter_two&.line_breaking(obj)
60
+ if obj.value_exist?
61
+ over = self.class.new(nil, Utility.filter_values(obj.value))
62
+ over.hide_function_name = true
63
+ obj.update(over)
64
+ end
65
+ end
47
66
  end
48
67
  end
49
68
  end
@@ -6,17 +6,18 @@ 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
- first_value = parameter_one&.to_mathml_without_math_tag
11
- second_value = parameter_two&.to_mathml_without_math_tag
12
- over_tag = Utility.ox_element("mover")
13
- Utility.update_nodes(
14
- over_tag,
15
- [
16
- second_value,
17
- first_value,
18
- ],
19
- )
16
+ value_array = [
17
+ validate_mathml_fields(parameter_two),
18
+ validate_mathml_fields(parameter_one),
19
+ ]
20
+ Utility.update_nodes(ox_element("mover"), value_array)
20
21
  end
21
22
 
22
23
  def to_omml_without_math_tag(display_style)
@@ -38,6 +39,14 @@ module Plurimath
38
39
  )
39
40
  [limupp]
40
41
  end
42
+
43
+ def line_breaking(obj)
44
+ parameter_two&.line_breaking(obj)
45
+ if obj.value_exist?
46
+ obj.update(self.class.new(parameter_one, Utility.filter_values(obj.value)))
47
+ self.parameter_one = nil
48
+ end
49
+ end
41
50
  end
42
51
  end
43
52
  end
@@ -7,24 +7,42 @@ module Plurimath
7
7
  module Function
8
8
  class Phantom < UnaryFunction
9
9
  def to_asciimath
10
- "#{Array.new(parameter_one&.length, '\ ').join}"
10
+ "#{Array.new(asciimath_value&.length, '\ ').join}"
11
11
  end
12
12
 
13
13
  def to_html
14
- "<i>#{Array.new(parameter_one&.length, '&nbsp;').join}</i>"
14
+ "<i style='visibility: hidden;'>#{parameter_one&.to_html}</i>"
15
15
  end
16
16
 
17
17
  def to_latex
18
- Array.new(parameter_one&.length, '\\ ').join
18
+ "\\#{class_name}{#{latex_value}}"
19
19
  end
20
20
 
21
21
  def to_mathml_without_math_tag
22
- phantom = Utility.ox_element("mphantom")
23
22
  Utility.update_nodes(
24
- phantom,
25
- parameter_one&.map(&:to_mathml_without_math_tag),
23
+ Utility.ox_element("mphantom"),
24
+ Array(mathml_value),
26
25
  )
27
26
  end
27
+
28
+ def to_omml_without_math_tag(display_style)
29
+ phant = Utility.ox_element("phant", namespace: "m")
30
+ e_tag = Utility.ox_element("e", namespace: "m")
31
+ Utility.update_nodes(e_tag, Array(omml_value(display_style)))
32
+ Utility.update_nodes(phant, [phant_pr, e_tag])
33
+ end
34
+
35
+ def line_breaking(obj)
36
+ custom_array_line_breaking(obj)
37
+ end
38
+
39
+ protected
40
+
41
+ def phant_pr
42
+ attributes = { val: "m:off" }
43
+ phant = Utility.ox_element("phant", namespace: "m")
44
+ phant << Utility.ox_element("show", namespace: "m", attributes: attributes)
45
+ end
28
46
  end
29
47
  end
30
48
  end
@@ -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}"
@@ -13,10 +19,11 @@ module Plurimath
13
19
 
14
20
  def to_mathml_without_math_tag
15
21
  tag_name = (["ubrace", "obrace"].include?(parameter_one&.class_name) ? "over" : "sup")
16
- 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
19
- Utility.update_nodes(sup_tag, mathml_value)
22
+ value_array = [
23
+ validate_mathml_fields(parameter_one),
24
+ validate_mathml_fields(parameter_two),
25
+ ]
26
+ Utility.update_nodes(ox_element("m#{tag_name}"), value_array)
20
27
  end
21
28
 
22
29
  def to_latex
@@ -45,6 +52,14 @@ module Plurimath
45
52
  )
46
53
  [ssup_element]
47
54
  end
55
+
56
+ def line_breaking(obj)
57
+ parameter_one&.line_breaking(obj)
58
+ if obj.value_exist?
59
+ obj.update(self.class.new(Utility.filter_values(obj.value), parameter_two))
60
+ self.parameter_two = nil
61
+ end
62
+ end
48
63
  end
49
64
  end
50
65
  end
@@ -6,12 +6,21 @@ 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
- subsup_tag = Utility.ox_element("m#{parameter_one.tag_name}")
11
- 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
17
+ tag_name = parameter_one&.tag_name || "subsup"
18
+ subsup_tag = ox_element("m#{tag_name}")
19
+ new_arr = [
20
+ validate_mathml_fields(parameter_one),
21
+ validate_mathml_fields(parameter_two),
22
+ validate_mathml_fields(parameter_three),
23
+ ]
15
24
  Utility.update_nodes(subsup_tag, new_arr)
16
25
  end
17
26
 
@@ -29,25 +38,8 @@ module Plurimath
29
38
  "#{first_value}#{second_value}#{third_value}"
30
39
  end
31
40
 
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
41
  def to_omml_without_math_tag(display_style)
50
- return underover(display_style) if parameter_one.omml_tag_name == "undOvr"
42
+ return underover(display_style) if parameter_one&.omml_tag_name == "undOvr"
51
43
 
52
44
  ssubsup = Utility.ox_element("sSubSup", namespace: "m")
53
45
  ssubsuppr = Utility.ox_element("sSubSupPr", namespace: "m")
@@ -66,19 +58,28 @@ module Plurimath
66
58
  [ssubsup]
67
59
  end
68
60
 
69
- protected
70
-
71
- def chr_value(narypr)
72
- first_value = Utility.html_entity_to_unicode(parameter_one&.nary_attr_value)
73
- return narypr if first_value == "∫"
61
+ def line_breaking(obj)
62
+ parameter_one&.line_breaking(obj)
63
+ if obj.value_exist?
64
+ obj.update(
65
+ self.class.new(Utility.filter_values(obj.value), parameter_two, parameter_three)
66
+ )
67
+ self.parameter_two = nil
68
+ self.parameter_three = nil
69
+ return
70
+ end
74
71
 
75
- narypr << Utility.ox_element(
76
- "chr",
77
- namespace: "m",
78
- attributes: { "m:val": first_value },
79
- )
72
+ parameter_two.line_breaking(obj)
73
+ if obj.value_exist?
74
+ obj.update(
75
+ self.class.new(nil, Utility.filter_values(obj.value), parameter_three)
76
+ )
77
+ self.parameter_three = nil
78
+ end
80
79
  end
81
80
 
81
+ protected
82
+
82
83
  def hide_tags(nar)
83
84
  attr = { "m:val": "1" }
84
85
  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
@@ -19,17 +25,20 @@ module Plurimath
19
25
  end
20
26
 
21
27
  def to_mathml_without_math_tag
22
- first_value = Utility.ox_element("mo") << invert_unicode_symbols.to_s
28
+ first_value = ox_element("mo")
29
+ first_value << invert_unicode_symbols.to_s unless hide_function_name
23
30
  if parameter_one || parameter_two
24
- value_array = [first_value]
25
- value_array << parameter_one&.to_mathml_without_math_tag
26
- value_array << parameter_two&.to_mathml_without_math_tag
27
31
  tag_name = if parameter_two && parameter_one
28
32
  "underover"
29
33
  else
30
34
  parameter_one ? "under" : "over"
31
35
  end
32
- munderover_tag = Utility.ox_element("m#{tag_name}")
36
+ value_array = [
37
+ first_value,
38
+ parameter_one&.to_mathml_without_math_tag,
39
+ parameter_two&.to_mathml_without_math_tag,
40
+ ]
41
+ munderover_tag = ox_element("m#{tag_name}")
33
42
  Utility.update_nodes(
34
43
  munderover_tag,
35
44
  value_array,
@@ -55,29 +64,40 @@ module Plurimath
55
64
  end
56
65
 
57
66
  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
67
+ return r_element("&#x220f;", rpr_tag: false) unless all_values_exist?
68
+
69
+ nary = Utility.ox_element("nary", namespace: "m")
70
+ Utility.update_nodes(nary, nary_values(display_style))
71
+ [nary]
72
+ end
73
+
74
+ def nary_values(display_style)
75
+ [
76
+ narypr(hide_function_name ? "" : nary_attr_value),
77
+ omml_parameter(parameter_one, display_style, tag_name: "sub"),
78
+ omml_parameter(parameter_two, display_style, tag_name: "sup"),
79
+ omml_parameter(parameter_three, display_style, tag_name: "e"),
80
+ ]
76
81
  end
77
82
 
78
83
  def nary_attr_value
79
84
  "∏"
80
85
  end
86
+
87
+ def line_breaking(obj)
88
+ parameter_one&.line_breaking(obj)
89
+ if obj.value_exist?
90
+ prod = self.class.new(Utility.filter_values(obj.value), parameter_two, parameter_three)
91
+ prod.hide_function_name = true
92
+ obj.update(prod)
93
+ return
94
+ end
95
+
96
+ parameter_three&.line_breaking(obj)
97
+ if obj.value_exist?
98
+ obj.update(Utility.filter_values(obj.value))
99
+ end
100
+ end
81
101
  end
82
102
  end
83
103
  end