plurimath 0.3.5 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) 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 +43 -30
  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 -21
  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 +48 -6
  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/parser.rb +13 -3
  78. data/lib/plurimath/mathml/transform.rb +21 -1
  79. data/lib/plurimath/omml/parser.rb +8 -1
  80. data/lib/plurimath/omml/transform.rb +27 -13
  81. data/lib/plurimath/utility.rb +18 -8
  82. data/lib/plurimath/version.rb +1 -1
  83. metadata +3 -3
  84. data/lib/plurimath/math/base.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18df410d2655f777a8bf6379ec49334cc4d595e73b100e61287e5c385674a7b3
4
- data.tar.gz: ae5bcfd6527302f5811b80ab02d61c4f25027c9526720402467736d2d4ccdf10
3
+ metadata.gz: 39522e32ac4e62af9eb862173a64e6e8650a9531bae27f321f25c6a1bc594e95
4
+ data.tar.gz: df5419195046dcf270cd4561c8cf3f9657536217a370d7a9aef150d7ca6aec72
5
5
  SHA512:
6
- metadata.gz: 671778813a9f27fc1911226f587c93ee156591abf54acba8f922dc620caa8fd13019c72ce40695a659ba8455745ddd007a19d6fc1444cafd1744946d97ae7f1d
7
- data.tar.gz: 522d01abb0c1d7482fd3d1ff598891007540559f8031d9ad0f53379d9eac577c89e666f827225325df4a10c8ea504479fbb523c11e171cbd7cbc2b96000afaa1
6
+ metadata.gz: 0a2c7880f03ba5d70c508b61f9c272be5a4780cbc5a30f56e142f7aa6798b5a8059051c6ecaf80ac9c209ab2cda977d55d7354f28e06e42c3dd439e3e96c0349
7
+ data.tar.gz: f2c0962524dc14232b0a48a4cd92015551f39603087bc42b08e73d0a3e66952ae2ab260f13166d159de378bd1757c24b0039a58d5b0fd129fb7be431f523e6a1
@@ -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,13 +2,18 @@
2
2
 
3
3
  module Plurimath
4
4
  module Math
5
- class Formula
6
- attr_accessor :value, :left_right_wrapper
7
-
8
- def initialize(value = [], left_right_wrapper = true)
5
+ class Formula < Core
6
+ attr_accessor :value, :left_right_wrapper, :displaystyle
7
+
8
+ def initialize(
9
+ value = [],
10
+ left_right_wrapper = true,
11
+ displaystyle: true
12
+ )
9
13
  @value = value.is_a?(Array) ? value : [value]
10
14
  left_right_wrapper = false if @value.first.is_a?(Function::Left)
11
15
  @left_right_wrapper = left_right_wrapper
16
+ @displaystyle = displaystyle
12
17
  end
13
18
 
14
19
  def ==(object)
@@ -20,12 +25,12 @@ module Plurimath
20
25
  value.map(&:to_asciimath).join(" ")
21
26
  end
22
27
 
23
- def to_mathml
28
+ def to_mathml(display_style: displaystyle)
24
29
  math_attrs = {
25
30
  xmlns: "http://www.w3.org/1998/Math/MathML",
26
31
  display: "block",
27
32
  }
28
- style_attrs = { displaystyle: "true" }
33
+ style_attrs = { displaystyle: display_style }
29
34
  math = Utility.ox_element("math", attributes: math_attrs)
30
35
  style = Utility.ox_element("mstyle", attributes: style_attrs)
31
36
  Utility.update_nodes(style, mathml_content)
@@ -85,49 +90,57 @@ module Plurimath
85
90
  )
86
91
  math_element = Utility.ox_element("oMath", namespace: "m")
87
92
  Utility.update_nodes(math_element, omml_content)
88
- para_element << math_element
89
- Ox.dump(para_element, indent: 2).gsub("&amp;", "&")
93
+ Utility.update_nodes(para_element, Array(math_element))
94
+ Ox.dump(para_element, indent: 2).gsub("&amp;", "&").lstrip
90
95
  end
91
96
 
92
97
  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
98
+ value&.map(&:insert_t_tag)
101
99
  end
102
100
 
103
101
  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
102
+ return nary_tag if nary_tag_able?
103
+
104
+ omml_content
113
105
  end
114
106
 
115
107
  def nary_tag
116
108
  nary_tag = Utility.ox_element("nary", namespace: "m")
117
109
  e_tag = Utility.ox_element("e", namespace: "m")
118
- e_tag << value&.last&.to_omml_without_math_tag
110
+ Utility.update_nodes(e_tag, value.last.insert_t_tag)
119
111
  Utility.update_nodes(
120
112
  nary_tag,
121
- [
122
- value.first.omml_nary_tag,
123
- e_tag,
124
- ].flatten.compact,
113
+ (value.first.omml_nary_tag << e_tag),
125
114
  )
115
+ [nary_tag]
126
116
  end
127
117
 
128
118
  def class_name
129
119
  self.class.name.split("::").last.downcase
130
120
  end
121
+
122
+ def extract_class_from_text
123
+ return false unless (value.length < 2 && value&.first&.is_a?(Function::Text))
124
+
125
+ value.first.parameter_one
126
+ end
127
+
128
+ def nary_attr_value
129
+ value.first.nary_attr_value
130
+ end
131
+
132
+ def nary_tag_able?
133
+ value.length == 2 &&
134
+ ["underover", "powerbase"].include?(value&.first&.class_name) &&
135
+ (
136
+ value&.first&.parameter_one&.to_omml_without_math_tag&.length == 1 ||
137
+ value&.first&.parameter_one.to_omml_without_math_tag.match?(/^&#x\w*\d*;$/)
138
+ )
139
+ end
140
+
141
+ def validate_function_formula
142
+ (value.none?(Function::Left) || value.none?(Function::Right))
143
+ end
131
144
  end
132
145
  end
133
146
  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