plurimath 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/lib/plurimath/asciimath/constants.rb +5 -3
  3. data/lib/plurimath/asciimath/parse.rb +41 -28
  4. data/lib/plurimath/asciimath/transform.rb +111 -0
  5. data/lib/plurimath/latex/constants.rb +2 -2
  6. data/lib/plurimath/latex/parse.rb +3 -0
  7. data/lib/plurimath/latex/transform.rb +37 -0
  8. data/lib/plurimath/math/core.rb +43 -0
  9. data/lib/plurimath/math/formula.rb +33 -25
  10. data/lib/plurimath/math/function/abs.rb +19 -0
  11. data/lib/plurimath/math/function/arccos.rb +3 -0
  12. data/lib/plurimath/math/function/arcsin.rb +3 -0
  13. data/lib/plurimath/math/function/arctan.rb +3 -0
  14. data/lib/plurimath/math/function/bar.rb +2 -1
  15. data/lib/plurimath/math/function/base.rb +5 -7
  16. data/lib/plurimath/math/function/binary_function.rb +11 -61
  17. data/lib/plurimath/math/function/cos.rb +3 -0
  18. data/lib/plurimath/math/function/cosh.rb +3 -0
  19. data/lib/plurimath/math/function/cot.rb +3 -0
  20. data/lib/plurimath/math/function/coth.rb +3 -0
  21. data/lib/plurimath/math/function/csc.rb +3 -0
  22. data/lib/plurimath/math/function/csch.rb +3 -0
  23. data/lib/plurimath/math/function/ddot.rb +13 -0
  24. data/lib/plurimath/math/function/deg.rb +3 -0
  25. data/lib/plurimath/math/function/det.rb +3 -0
  26. data/lib/plurimath/math/function/dim.rb +3 -0
  27. data/lib/plurimath/math/function/exp.rb +3 -0
  28. data/lib/plurimath/math/function/fenced.rb +9 -31
  29. data/lib/plurimath/math/function/font_style.rb +7 -1
  30. data/lib/plurimath/math/function/frac.rb +5 -7
  31. data/lib/plurimath/math/function/gcd.rb +3 -0
  32. data/lib/plurimath/math/function/glb.rb +3 -0
  33. data/lib/plurimath/math/function/hat.rb +4 -0
  34. data/lib/plurimath/math/function/int.rb +36 -6
  35. data/lib/plurimath/math/function/left.rb +10 -3
  36. data/lib/plurimath/math/function/lg.rb +3 -0
  37. data/lib/plurimath/math/function/lim.rb +5 -14
  38. data/lib/plurimath/math/function/limits.rb +8 -0
  39. data/lib/plurimath/math/function/ln.rb +3 -0
  40. data/lib/plurimath/math/function/log.rb +40 -22
  41. data/lib/plurimath/math/function/lub.rb +3 -0
  42. data/lib/plurimath/math/function/max.rb +3 -0
  43. data/lib/plurimath/math/function/mbox.rb +1 -3
  44. data/lib/plurimath/math/function/menclose.rb +2 -1
  45. data/lib/plurimath/math/function/min.rb +3 -0
  46. data/lib/plurimath/math/function/msgroup.rb +1 -4
  47. data/lib/plurimath/math/function/multiscript.rb +4 -9
  48. data/lib/plurimath/math/function/obrace.rb +8 -0
  49. data/lib/plurimath/math/function/overset.rb +3 -16
  50. data/lib/plurimath/math/function/power.rb +5 -8
  51. data/lib/plurimath/math/function/power_base.rb +9 -39
  52. data/lib/plurimath/math/function/prod.rb +34 -4
  53. data/lib/plurimath/math/function/right.rb +10 -3
  54. data/lib/plurimath/math/function/root.rb +6 -4
  55. data/lib/plurimath/math/function/rule.rb +1 -1
  56. data/lib/plurimath/math/function/sec.rb +3 -0
  57. data/lib/plurimath/math/function/sech.rb +3 -0
  58. data/lib/plurimath/math/function/sin.rb +3 -0
  59. data/lib/plurimath/math/function/sinh.rb +3 -0
  60. data/lib/plurimath/math/function/sqrt.rb +4 -3
  61. data/lib/plurimath/math/function/sum.rb +31 -27
  62. data/lib/plurimath/math/function/table.rb +54 -8
  63. data/lib/plurimath/math/function/tan.rb +3 -0
  64. data/lib/plurimath/math/function/tanh.rb +3 -0
  65. data/lib/plurimath/math/function/td.rb +4 -1
  66. data/lib/plurimath/math/function/ternary_function.rb +34 -17
  67. data/lib/plurimath/math/function/text.rb +11 -0
  68. data/lib/plurimath/math/function/tr.rb +1 -0
  69. data/lib/plurimath/math/function/ubrace.rb +8 -0
  70. data/lib/plurimath/math/function/ul.rb +2 -1
  71. data/lib/plurimath/math/function/unary_function.rb +10 -9
  72. data/lib/plurimath/math/function/underover.rb +10 -27
  73. data/lib/plurimath/math/function/underset.rb +3 -16
  74. data/lib/plurimath/math/number.rb +17 -3
  75. data/lib/plurimath/math/symbol.rb +20 -2
  76. data/lib/plurimath/math.rb +1 -1
  77. data/lib/plurimath/mathml/constants.rb +0 -2
  78. data/lib/plurimath/mathml/parser.rb +9 -1
  79. data/lib/plurimath/mathml/transform.rb +21 -1
  80. data/lib/plurimath/omml/parser.rb +8 -1
  81. data/lib/plurimath/omml/transform.rb +27 -13
  82. data/lib/plurimath/utility.rb +20 -8
  83. data/lib/plurimath/version.rb +1 -1
  84. metadata +3 -3
  85. data/lib/plurimath/math/base.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b189635567597c62c87de4beda13072f0be78d12993bbf8fb88d5a62447c0d9
4
- data.tar.gz: 87960dc1944b7328585f44e8d8605dd5d94d00c2e29522ceebbf6e2f09936e18
3
+ metadata.gz: 10711816eed513eb42250bdc90628a5ed3c9847cb33546e7df19ea29ca56b85e
4
+ data.tar.gz: 872e488b9b856e55c6e00ac6c19e089853950ec8a58fb4057abe601efee88604
5
5
  SHA512:
6
- metadata.gz: 4525b775b5ceb63822c1e4a0777604684b80b3c85403df64a8443d405a6e93bd3c8f354a905788558224f163caaf8a73eaca52f03f6042e409eae112f26d9805
7
- data.tar.gz: b41b71415e9908bdd5bade1be722f48155473e556b050ecaebf097a21aaec1b478f63a2d72f60ead47b1a972f2c3b13623e6eb4837d426b489b39e7952bf4e0f
6
+ metadata.gz: b916d733033785acb282ffe2544e05387b65b54f53e83ba7f28cbb7e73ea71f8766129adb8d369560cb3b2df46de6f5215d68bb85755c3bb1b3d35e44963403e
7
+ data.tar.gz: 07204d723d30656e42791e79d954864da64acc41dbf84dff936e8fc88a51ca4a22d40b8fd426bd81f523a829837d5c0e8f7fcd5569a12025eb5128dc00cda0de
@@ -310,13 +310,15 @@ module Plurimath
310
310
  tt
311
311
  ii
312
312
  ].freeze
313
- SUB_SUP_CLASSES = %w[
313
+ TERNARY_CLASSES = %w[
314
314
  prod
315
+ sum
316
+ int
317
+ ].freeze
318
+ SUB_SUP_CLASSES = %w[
315
319
  oint
316
320
  lim
317
- sum
318
321
  log
319
- int
320
322
  ].freeze
321
323
  SPECIAL_BOLD_ALPHABETS = %w[
322
324
  ZZ
@@ -8,7 +8,8 @@ module Plurimath
8
8
  rule(:base) { str("_") }
9
9
  rule(:power) { str("^") }
10
10
  rule(:space) { match(/\s+/) }
11
- rule(:comma) { (str(",") >> space.maybe) }
11
+ rule(:comma) { (str(",") >> space?) }
12
+ rule(:space?) { space.maybe }
12
13
  rule(:number) do
13
14
  (match("[0-9]").repeat(1) >> str(".") >> match("[0-9]").repeat(1)).as(:number) |
14
15
  match("[0-9]").repeat(1).as(:number) |
@@ -21,6 +22,16 @@ module Plurimath
21
22
  rule(:color_left_parenthesis) { str("(") | str("[") | str("{") }
22
23
  rule(:color_right_parenthesis) { str(")") | str("]") | str("}") }
23
24
 
25
+ rule(:ternary_classes_rules) do
26
+ (str("left") >> space? >> left_right_open_paren.as(:left) >> space? >> (ternary_classes >> power_base >> space? >> iteration.as(:third_value).maybe).as(:ternary) >> space? >> str("right") >> space? >> left_right_close_paren.as(:right)) |
27
+ (ternary_classes >> power_base >> space? >> iteration.as(:third_value).maybe).as(:ternary) |
28
+ ternary_classes
29
+ end
30
+
31
+ rule(:ternary_classes) do
32
+ arr_to_expression(Constants::TERNARY_CLASSES, :ternary_class)
33
+ end
34
+
24
35
  rule(:binary_classes) do
25
36
  arr_to_expression(Constants::BINARY_CLASSES, :binary_class)
26
37
  end
@@ -52,8 +63,8 @@ module Plurimath
52
63
  end
53
64
 
54
65
  rule(:left_right) do
55
- (str("left") >> left_right_open_paren.as(:left) >> iteration.as(:left_right_value) >> str("right") >> left_right_close_paren.as(:right)) |
56
- ((table.as(:numerator) >> space.maybe >> match(/(?<!\/)\/(?!\/)/) >> space.maybe >> iteration.as(:denominator)).as(:frac) >> expression) |
66
+ (str("left") >> space? >> left_right_open_paren.as(:left) >> space? >> (iteration.maybe >> sequence.maybe).as(:left_right_value) >> space? >> str("right") >> space? >> left_right_close_paren.as(:right)) |
67
+ ((table.as(:numerator) >> space? >> match(/(?<!\/)\/(?!\/)/) >> space? >> iteration.as(:denominator)).as(:frac) >> expression) |
57
68
  (table.as(:table) >> expression.maybe)
58
69
  end
59
70
 
@@ -65,39 +76,40 @@ module Plurimath
65
76
  rule(:symbol_text_or_integer) do
66
77
  sub_sup_classes |
67
78
  binary_classes |
79
+ ternary_classes |
68
80
  hash_to_expression(Constants.precompile_constants) |
69
81
  (match(/[0-9]/).as(:number) >> comma.as(:comma)).repeat(1).as(:comma_separated) |
70
82
  quoted_text |
71
83
  (str("d").as(:d) >> str("x").as(:x)).as(:intermediate_exp) |
72
- match["a-zA-Z"].as(:symbol) |
84
+ ((str("left").absent? >> str("right").absent?) >> match["a-zA-Z"].as(:symbol)) |
73
85
  match(/[^\[{(\\\/@;:.,'"|\]})0-9a-zA-Z\-><$%^&*_=+!`~\s?ℒℛᑕᑐ]/).as(:symbol) |
74
86
  number
75
87
  end
76
88
 
77
89
  rule(:power_base) do
78
- (base >> space.maybe >> sequence.as(:base_value) >> power >> space.maybe >> sequence.as(:power_value)) |
79
- (space.maybe >> base >> space.maybe >> sequence.as(:base_value)).as(:base) |
80
- (space.maybe >> power >> space.maybe >> sequence.as(:power_value)).as(:power) |
81
- (space.maybe >> base >> space.maybe >> power.as(:symbol).as(:base_value)).as(:base) |
82
- (space.maybe >> power >> space.maybe >> base.as(:symbol).as(:power_value)).as(:power)
90
+ (base >> space? >> sequence.as(:base_value) >> power >> space? >> sequence.as(:power_value)) |
91
+ (space? >> base >> space? >> sequence.as(:base_value)).as(:base) |
92
+ (space? >> power >> space? >> sequence.as(:power_value)).as(:power) |
93
+ (space? >> base >> space? >> power.as(:symbol).as(:base_value)).as(:base) |
94
+ (space? >> power >> space? >> base.as(:symbol).as(:power_value)).as(:power)
83
95
  end
84
96
 
85
97
  rule(:power_base_rules) do
86
98
  (sub_sup_classes >> power_base).as(:power_base) |
87
- (binary_classes >> space.maybe >> sequence.as(:base_value).maybe >> space.maybe >> sequence.as(:power_value).maybe).as(:power_base) |
99
+ (binary_classes >> space? >> sequence.as(:base_value).maybe >> space? >> sequence.as(:power_value).maybe).as(:power_base) |
88
100
  (sequence.as(:power_base) >> power_base).as(:power_base)
89
101
  end
90
102
 
91
103
  rule(:table) do
92
- (str("{").as(:table_left) >> space.maybe >> tr >> space.maybe >> close_table.as(:table_right)) |
93
- (open_table.as(:table_left) >> space.maybe >> tr >> space.maybe >> close_table.as(:table_right)) |
94
- (str("norm").as(:norm) >> open_table.as(:table_left) >> space.maybe >> tr >> space.maybe >> close_table.as(:table_right)) |
95
- (str("|").as(:table_left) >> space.maybe >> tr >> space.maybe >> str("|").as(:table_right)) |
96
- (str("left") >> left_right_open_paren.as(:left) >> space.maybe >> tr >> space.maybe >> str("right") >> left_right_close_paren.as(:right))
104
+ (str("{").as(:table_left) >> space? >> tr >> space? >> close_table.as(:table_right)) |
105
+ (open_table.as(:table_left) >> space? >> tr >> space? >> close_table.as(:table_right)) |
106
+ (str("norm").as(:norm) >> open_table.as(:table_left) >> space? >> tr >> space? >> close_table.as(:table_right)) |
107
+ (str("|").as(:table_left) >> space? >> tr >> space? >> str("|").as(:table_right)) |
108
+ (str("left") >> space? >> left_right_open_paren.as(:left) >> space? >> tr >> space? >> str("right") >> space? >> left_right_close_paren.as(:right))
97
109
  end
98
110
 
99
111
  rule(:tr) do
100
- ((left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row) >> comma >> space.maybe >> tr.as(:expr)) |
112
+ ((left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row) >> comma >> space? >> tr.as(:expr)) |
101
113
  (left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row)
102
114
  end
103
115
 
@@ -107,27 +119,28 @@ module Plurimath
107
119
  end
108
120
 
109
121
  rule(:sequence) do
110
- (lparen.as(:lparen) >> space.maybe >> expression.maybe.as(:expr) >> space.maybe >> rparen.maybe.as(:rparen)).as(:intermediate_exp) |
122
+ (lparen.as(:lparen) >> space? >> expression.maybe.as(:expr) >> space? >> rparen.maybe.as(:rparen)).as(:intermediate_exp) |
111
123
  (str("text") >> lparen.capture(:paren) >> read_text.as(:text) >> rparen.maybe).as(:intermediate_exp) |
112
124
  symbol_text_or_integer
113
125
  end
114
126
 
115
127
  rule(:frac) do
116
- (sequence.as(:numerator) >> space.maybe >> match(/(?<!\/)\/(?!\/)/) >> space.maybe >> iteration.as(:denominator)).as(:frac) |
128
+ (sequence.as(:numerator) >> space? >> match(/(?<!\/)\/(?!\/)/) >> space? >> iteration.as(:denominator)).as(:frac) |
117
129
  ((power_base_rules | power_base).as(:numerator) >> match(/(?<!\/)\/(?!\/)/) >> iteration.as(:denominator)).as(:frac)
118
130
  end
119
131
 
120
132
  rule(:mod) do
121
- (sequence.as(:dividend) >> space.maybe >> str("mod").as(:mod) >> space.maybe >> iteration.as(:divisor)).as(:mod) |
122
- ((power_base_rules >> power_base).as(:dividend) >> space.maybe >> str("mod").as(:mod) >> space.maybe >> iteration.as(:divisor)).as(:mod) |
123
- (power_base_rules.as(:dividend) >> space.maybe >> str("mod").as(:mod) >> space.maybe >> iteration.as(:divisor)).as(:mod)
133
+ (sequence.as(:dividend) >> space? >> str("mod").as(:mod) >> space? >> iteration.as(:divisor)).as(:mod) |
134
+ ((power_base_rules >> power_base).as(:dividend) >> space? >> str("mod").as(:mod) >> space? >> iteration.as(:divisor)).as(:mod) |
135
+ (power_base_rules.as(:dividend) >> space? >> str("mod").as(:mod) >> space? >> iteration.as(:divisor)).as(:mod)
124
136
  end
125
137
 
126
138
  rule(:iteration) do
127
- table.as(:table) |
139
+ ternary_classes_rules |
140
+ table.as(:table) |
128
141
  comma.as(:comma) |
129
142
  mod |
130
- (sequence.as(:sequence) >> space.maybe >> str("//").as(:symbol)) |
143
+ (sequence.as(:sequence) >> space? >> str("//").as(:symbol)) |
131
144
  (str("color") >> color_value.as(:color) >> sequence.as(:color_value)) |
132
145
  frac |
133
146
  (power_base_rules >> power_base) |
@@ -138,12 +151,12 @@ module Plurimath
138
151
 
139
152
  rule(:expression) do
140
153
  left_right.as(:left_right) |
141
- (iteration >> space.maybe >> expression).as(:expr) |
154
+ (iteration >> space? >> expression).as(:expr) |
142
155
  (base.as(:symbol) >> expression.maybe).as(:expr) |
143
156
  (power.as(:symbol) >> expression.maybe).as(:expr) |
144
157
  str("") |
145
- (rparen.as(:rparen) >> space.maybe >> controversial_symbols >> comma.as(:comma).maybe >> expression).repeat(1).as(:expr) |
146
- (power.as(:symbol) >> space.maybe >> expression).as(:expr) |
158
+ (rparen.as(:rparen) >> space? >> controversial_symbols >> comma.as(:comma).maybe >> expression).repeat(1).as(:expr) |
159
+ (power.as(:symbol) >> space? >> expression).as(:expr) |
147
160
  comma.as(:comma).maybe
148
161
  end
149
162
 
@@ -176,8 +189,8 @@ module Plurimath
176
189
  first_value = str(expr.first.to_s)
177
190
  case expr.last
178
191
  when :symbol then first_value.as(:symbol)
179
- when :unary_class then (first_value.as(:unary_class) >> space.maybe >> sequence.maybe).as(:unary)
180
- when :fonts then first_value.as(:fonts_class) >> space.maybe >> sequence.as(:fonts_value)
192
+ when :unary_class then (first_value.as(:unary_class) >> space? >> sequence.maybe).as(:unary)
193
+ when :fonts then first_value.as(:fonts_class) >> space? >> sequence.as(:fonts_value)
181
194
  when :special_fonts then first_value.as(:bold_fonts)
182
195
  end
183
196
  end
@@ -12,6 +12,7 @@ module Plurimath
12
12
  rule(rparen: simple(:rparen)) { Utility.symbol_object(rparen) }
13
13
  rule(number: simple(:number)) { Math::Number.new(number) }
14
14
 
15
+ rule(ternary: simple(:ternary)) { ternary }
15
16
  rule(sequence: simple(:sequence)) { sequence }
16
17
  rule(table_row: simple(:table_row)) { table_row }
17
18
  rule(sequence: sequence(:sequence)) { sequence }
@@ -41,6 +42,10 @@ module Plurimath
41
42
  Utility.get_class(binary).new
42
43
  end
43
44
 
45
+ rule(ternary_class: simple(:ternary)) do
46
+ Utility.get_class(ternary).new
47
+ end
48
+
44
49
  rule(comma_separated: subtree(:comma_separated)) do
45
50
  comma_separated.flatten
46
51
  end
@@ -127,6 +132,11 @@ module Plurimath
127
132
  new_arr
128
133
  end
129
134
 
135
+ rule(sequence: simple(:sequence),
136
+ number: simple(:number)) do
137
+ [sequence, Math::Number.new(number.to_s)]
138
+ end
139
+
130
140
  rule(table_row: simple(:table_row),
131
141
  expr: simple(:expr)) do
132
142
  new_arr = [table_row]
@@ -680,6 +690,82 @@ module Plurimath
680
690
  )
681
691
  end
682
692
 
693
+ rule(ternary_class: simple(:function),
694
+ base_value: simple(:base),
695
+ power_value: simple(:power)) do
696
+ Utility.get_class(function).new(
697
+ Utility.unfenced_value(base),
698
+ Utility.unfenced_value(power),
699
+ )
700
+ end
701
+
702
+ rule(ternary_class: simple(:function),
703
+ base: simple(:base)) do
704
+ Utility.get_class(function).new(
705
+ Utility.unfenced_value(base),
706
+ )
707
+ end
708
+
709
+ rule(ternary_class: simple(:function),
710
+ base: simple(:base),
711
+ third_value: simple(:third)) do
712
+ third_value = third.is_a?(Slice) ? nil : third
713
+ Utility.get_class(function).new(
714
+ Utility.unfenced_value(base),
715
+ nil,
716
+ third_value,
717
+ )
718
+ end
719
+
720
+ rule(ternary_class: simple(:function),
721
+ power: simple(:power)) do
722
+ Utility.get_class(function).new(
723
+ nil,
724
+ Utility.unfenced_value(power),
725
+ )
726
+ end
727
+
728
+ rule(ternary_class: simple(:function),
729
+ expr: simple(:expr)) do
730
+ [
731
+ Utility.get_class(function).new,
732
+ expr,
733
+ ]
734
+ end
735
+
736
+ rule(ternary_class: simple(:function),
737
+ expr: sequence(:expr)) do
738
+ expr.insert(0, Utility.get_class(function).new)
739
+ end
740
+
741
+ rule(ternary: simple(:ternary),
742
+ expr: simple(:expr)) do
743
+ [ternary, expr]
744
+ end
745
+
746
+ rule(ternary_class: simple(:function),
747
+ power: simple(:power),
748
+ third_value: simple(:third)) do
749
+ third_value = third.is_a?(Slice) ? nil : third
750
+ Utility.get_class(function).new(
751
+ nil,
752
+ Utility.unfenced_value(power),
753
+ third_value,
754
+ )
755
+ end
756
+
757
+ rule(ternary_class: simple(:function),
758
+ base_value: simple(:base),
759
+ power_value: simple(:power),
760
+ third_value: simple(:third)) do
761
+ third_value = third.is_a?(Slice) ? nil : third
762
+ Utility.get_class(function).new(
763
+ Utility.unfenced_value(base),
764
+ Utility.unfenced_value(power),
765
+ third_value,
766
+ )
767
+ end
768
+
683
769
  rule(unary_class: simple(:function),
684
770
  intermediate_exp: simple(:int_exp)) do
685
771
  first_value = if Utility::UNARY_CLASSES.include?(function)
@@ -722,6 +808,19 @@ module Plurimath
722
808
  ]
723
809
  end
724
810
 
811
+ rule(unary_class: simple(:function),
812
+ ternary_class: simple(:ternary_class)) do
813
+ [
814
+ Utility.get_class(function).new,
815
+ Utility.get_class(ternary_class).new,
816
+ ]
817
+ end
818
+
819
+ rule(ternary: simple(:ternary),
820
+ expr: sequence(:expr)) do
821
+ expr.insert(0, ternary)
822
+ end
823
+
725
824
  rule(unary_class: simple(:function),
726
825
  text: simple(:text)) do
727
826
  Utility.get_class(function).new(
@@ -761,6 +860,18 @@ module Plurimath
761
860
  )
762
861
  end
763
862
 
863
+ rule(left: simple(:left),
864
+ left_right_value: sequence(:left_right),
865
+ right: simple(:right)) do
866
+ Math::Formula.new(
867
+ [
868
+ Math::Function::Left.new(left),
869
+ Math::Formula.new(left_right),
870
+ Math::Function::Right.new(right),
871
+ ],
872
+ )
873
+ end
874
+
764
875
  rule(dividend: simple(:dividend),
765
876
  mod: simple(:mod),
766
877
  divisor: simple(:divisor)) do
@@ -3430,7 +3430,7 @@ module Plurimath
3430
3430
  mbfit: :fonts,
3431
3431
  msans: :fonts,
3432
3432
  tilde: :unary,
3433
- prod: :power_base,
3433
+ prod: :ternary,
3434
3434
  zeta: :symbols,
3435
3435
  quad: :symbols,
3436
3436
  Vert: :symbols,
@@ -3563,7 +3563,7 @@ module Plurimath
3563
3563
  mbox: :unary,
3564
3564
  text: :text,
3565
3565
  '"': :symbols,
3566
- sum: :power_base,
3566
+ sum: :ternary,
3567
3567
  inf: :power_base,
3568
3568
  lim: :power_base,
3569
3569
  log: :power_base,
@@ -205,6 +205,9 @@ module Plurimath
205
205
  (slashed_value(first_value, :binary) >> intermediate_exp.as(:first_value) >> intermediate_exp.as(:second_value)).as(:binary)
206
206
  when :text
207
207
  (slashed_value(first_value, :text) >> (str("{") >> match("[^}]").repeat.as(:first_value) >> str("}")))
208
+ when :ternary
209
+ (slashed_value(first_value, :ternary_functions) >> dynamic_power_base >> sequence.as(:third_value).maybe).as(:ternary_class) |
210
+ slashed_value(first_value, :ternary)
208
211
  end
209
212
  end
210
213
 
@@ -17,8 +17,10 @@ module Plurimath
17
17
  rule("\\\\" => simple(:slash)) { Math::Symbol.new(slash) }
18
18
  rule(expression: simple(:expr)) { expr }
19
19
  rule(environment: simple(:env)) { env }
20
+ rule(ternary: simple(:ternary)) { Utility.get_class(ternary).new }
20
21
 
21
22
  rule(unary_functions: simple(:unary)) { unary }
23
+ rule(ternary_class: simple(:ternary)) { ternary }
22
24
  rule(left_right: simple(:left_right)) { left_right }
23
25
  rule(under_over: simple(:under_over)) { under_over }
24
26
  rule(power_base: simple(:power_base)) { power_base }
@@ -308,6 +310,11 @@ module Plurimath
308
310
  )
309
311
  end
310
312
 
313
+ rule(ternary_functions: simple(:ternary),
314
+ subscript: simple(:subscript)) do
315
+ Utility.get_class(ternary).new(subscript)
316
+ end
317
+
311
318
  rule(unary_functions: simple(:unary),
312
319
  supscript: simple(:supscript)) do
313
320
  unary_function = if unary.is_a?(Parslet::Slice)
@@ -321,6 +328,25 @@ module Plurimath
321
328
  )
322
329
  end
323
330
 
331
+ rule(ternary_functions: simple(:ternary),
332
+ subscript: simple(:subscript),
333
+ third_value: simple(:third_value)) do
334
+ Utility.get_class(ternary).new(
335
+ subscript,
336
+ nil,
337
+ third_value,
338
+ )
339
+ end
340
+
341
+ rule(ternary_functions: simple(:ternary),
342
+ subscript: simple(:subscript),
343
+ supscript: simple(:supscript)) do
344
+ Utility.get_class(ternary).new(
345
+ subscript,
346
+ supscript,
347
+ )
348
+ end
349
+
324
350
  rule(unary_functions: simple(:unary),
325
351
  subscript: simple(:subscript),
326
352
  supscript: simple(:supscript)) do
@@ -336,6 +362,17 @@ module Plurimath
336
362
  )
337
363
  end
338
364
 
365
+ rule(ternary_functions: simple(:ternary),
366
+ subscript: simple(:subscript),
367
+ supscript: simple(:supscript),
368
+ third_value: simple(:third_value)) do
369
+ Utility.get_class(ternary).new(
370
+ subscript,
371
+ supscript,
372
+ third_value,
373
+ )
374
+ end
375
+
339
376
  rule(fonts: simple(:fonts),
340
377
  intermediate_exp: simple(:int_exp)) do
341
378
  if Utility::FONT_STYLES[fonts.to_sym]
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ module Math
5
+ class Core
6
+ def class_name
7
+ self.class.name.split("::").last.downcase
8
+ end
9
+
10
+ def insert_t_tag
11
+ Array(to_omml_without_math_tag)
12
+ end
13
+
14
+ def tag_name
15
+ "subsup"
16
+ end
17
+
18
+ def nary_attr_value
19
+ ""
20
+ end
21
+
22
+ def empty_tag(wrapper_tag)
23
+ r_tag = Utility.ox_element("r", namespace: "m")
24
+ r_tag << (Utility.ox_element("t", namespace: "m") << "&#8203;")
25
+ wrapper_tag << r_tag
26
+ end
27
+
28
+ def omml_parameter(field, tag_name: , namespace: "m")
29
+ tag = Utility.ox_element(tag_name, namespace: namespace)
30
+ return empty_tag(tag) unless field
31
+
32
+ Utility.update_nodes(
33
+ tag,
34
+ field&.insert_t_tag,
35
+ )
36
+ end
37
+
38
+ def validate_function_formula
39
+ true
40
+ end
41
+ end
42
+ end
43
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Plurimath
4
4
  module Math
5
- class Formula
5
+ class Formula < Core
6
6
  attr_accessor :value, :left_right_wrapper
7
7
 
8
8
  def initialize(value = [], left_right_wrapper = true)
@@ -85,49 +85,57 @@ module Plurimath
85
85
  )
86
86
  math_element = Utility.ox_element("oMath", namespace: "m")
87
87
  Utility.update_nodes(math_element, omml_content)
88
- para_element << math_element
89
- Ox.dump(para_element, indent: 2).gsub("&amp;", "&")
88
+ Utility.update_nodes(para_element, Array(math_element))
89
+ Ox.dump(para_element, indent: 2).gsub("&amp;", "&").lstrip
90
90
  end
91
91
 
92
92
  def omml_content
93
- value.map do |object|
94
- if object.is_a?(Symbol)
95
- mt = Utility.ox_element("t", namespace: "m")
96
- mt << object.value
97
- else
98
- object.to_omml_without_math_tag
99
- end
100
- end
93
+ value&.map(&:insert_t_tag)
101
94
  end
102
95
 
103
96
  def to_omml_without_math_tag
104
- if value.length == 2 && ["underover", "powerbase"].include?(
105
- value&.first&.class_name,
106
- )
107
- nary_tag
108
- else
109
- r_element = Utility.ox_element("r", namespace: "m")
110
- r_element << Utility.rpr_element if ["symbol", "number", "text"].include?(value&.first&.class_name)
111
- Utility.update_nodes(r_element, omml_content)
112
- end
97
+ return nary_tag if nary_tag_able?
98
+
99
+ omml_content
113
100
  end
114
101
 
115
102
  def nary_tag
116
103
  nary_tag = Utility.ox_element("nary", namespace: "m")
117
104
  e_tag = Utility.ox_element("e", namespace: "m")
118
- e_tag << value&.last&.to_omml_without_math_tag
105
+ Utility.update_nodes(e_tag, value.last.insert_t_tag)
119
106
  Utility.update_nodes(
120
107
  nary_tag,
121
- [
122
- value.first.omml_nary_tag,
123
- e_tag,
124
- ].flatten.compact,
108
+ (value.first.omml_nary_tag << e_tag),
125
109
  )
110
+ [nary_tag]
126
111
  end
127
112
 
128
113
  def class_name
129
114
  self.class.name.split("::").last.downcase
130
115
  end
116
+
117
+ def extract_class_from_text
118
+ return false unless (value.length < 2 && value&.first&.is_a?(Function::Text))
119
+
120
+ value.first.parameter_one
121
+ end
122
+
123
+ def nary_attr_value
124
+ value.first.nary_attr_value
125
+ end
126
+
127
+ def nary_tag_able?
128
+ value.length == 2 &&
129
+ ["underover", "powerbase"].include?(value&.first&.class_name) &&
130
+ (
131
+ value&.first&.parameter_one&.to_omml_without_math_tag&.length == 1 ||
132
+ value&.first&.parameter_one.to_omml_without_math_tag.match?(/^&#x\w*\d*;$/)
133
+ )
134
+ end
135
+
136
+ def validate_function_formula
137
+ (value.none?(Function::Left) || value.none?(Function::Right))
138
+ end
131
139
  end
132
140
  end
133
141
  end
@@ -14,6 +14,25 @@ module Plurimath
14
14
  first_value << symbol,
15
15
  )
16
16
  end
17
+
18
+ def to_omml_without_math_tag
19
+ md = (Utility.ox_element("d", namespace: "m") << mdpr_tag)
20
+ me = Utility.ox_element("e", namespace: "m")
21
+ Utility.update_nodes(me, omml_value)
22
+ Utility.update_nodes(md, Array(me))
23
+ [md]
24
+ end
25
+
26
+ protected
27
+
28
+ def mdpr_tag
29
+ attribute = { "m:val": "|" }
30
+ mdpr = Utility.pr_element("d", namespace: "m")
31
+ mdpr << Utility.ox_element("begChr", namespace: "m", attributes: attribute)
32
+ mdpr << Utility.ox_element("endChr", namespace: "m", attributes: attribute)
33
+ mdpr << Utility.ox_element("sepChr", namespace: "m", attributes: { "m:val": "" })
34
+ mdpr << Utility.ox_element("grow", namespace: "m")
35
+ end
17
36
  end
18
37
  end
19
38
  end
@@ -6,6 +6,9 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Arccos < UnaryFunction
9
+ def validate_function_formula
10
+ false
11
+ end
9
12
  end
10
13
  end
11
14
  end
@@ -6,6 +6,9 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Arcsin < UnaryFunction
9
+ def validate_function_formula
10
+ false
11
+ end
9
12
  end
10
13
  end
11
14
  end
@@ -6,6 +6,9 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Arctan < UnaryFunction
9
+ def validate_function_formula
10
+ false
11
+ end
9
12
  end
10
13
  end
11
14
  end
@@ -25,7 +25,7 @@ module Plurimath
25
25
  def to_omml_without_math_tag
26
26
  bar = Utility.ox_element("bar", namespace: "m")
27
27
  me = Utility.ox_element("e", namespace: "m")
28
- me << parameter_one.to_omml_without_math_tag if parameter_one
28
+ Utility.update_nodes(me, omml_value) if parameter_one
29
29
  Utility.update_nodes(
30
30
  bar,
31
31
  [
@@ -33,6 +33,7 @@ module Plurimath
33
33
  me,
34
34
  ],
35
35
  )
36
+ [bar]
36
37
  end
37
38
 
38
39
  protected
@@ -37,18 +37,16 @@ module Plurimath
37
37
  def to_omml_without_math_tag
38
38
  ssub_element = Utility.ox_element("sSub", namespace: "m")
39
39
  subpr_element = Utility.ox_element("sSubPr", namespace: "m")
40
- e_element = Utility.ox_element("e", namespace: "m")
41
- sub_element = Utility.ox_element("sub", namespace: "m")
42
- sub_element << parameter_two.to_omml_without_math_tag if parameter_two
40
+ subpr_element << Utility.pr_element("ctrl", true, namespace: "m")
43
41
  Utility.update_nodes(
44
42
  ssub_element,
45
43
  [
46
- subpr_element << Utility.pr_element("ctrl", true, namespace: "m"),
47
- e_element << parameter_one.to_omml_without_math_tag,
48
- sub_element,
44
+ subpr_element,
45
+ omml_parameter(parameter_one, tag_name: "e"),
46
+ omml_parameter(parameter_two, tag_name: "sub"),
49
47
  ],
50
48
  )
51
- ssub_element
49
+ [ssub_element]
52
50
  end
53
51
  end
54
52
  end