plurimath 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc53f153a22d8b615db765dda8d7b22c72d8cf42ee522a678649d52b3eed66b6
4
- data.tar.gz: d31664e4104fe46e1361adc6b4e1a38d189590d181cf04e668c6d5d8f3a5f1d5
3
+ metadata.gz: 1b189635567597c62c87de4beda13072f0be78d12993bbf8fb88d5a62447c0d9
4
+ data.tar.gz: 87960dc1944b7328585f44e8d8605dd5d94d00c2e29522ceebbf6e2f09936e18
5
5
  SHA512:
6
- metadata.gz: 6e8b0ececc1885c1751a0a9753a548f775c4cf740173c423dddbcf76dbfec8bb42db60773f744344402ea83e46e2c6bd99d43f85c54a12386383f0d83448f535
7
- data.tar.gz: 4313751a9dde187e15adfbf6faa8f0c6fe015a753e286c84c2ea5cb7d5dd57c81c3e2c2e8bdaacffd1db58ff90f08fe82c5803983fe6a4027c9aade374190e8a
6
+ metadata.gz: 4525b775b5ceb63822c1e4a0777604684b80b3c85403df64a8443d405a6e93bd3c8f354a905788558224f163caaf8a73eaca52f03f6042e409eae112f26d9805
7
+ data.tar.gz: b41b71415e9908bdd5bade1be722f48155473e556b050ecaebf097a21aaec1b478f63a2d72f60ead47b1a972f2c3b13623e6eb4837d426b489b39e7952bf4e0f
@@ -86,8 +86,6 @@
86
86
  * `sec`
87
87
  * `ln`
88
88
  * `ul`
89
- * `g`
90
- * `f`
91
89
 
92
90
 
93
91
  == Symbols
@@ -1588,10 +1586,10 @@
1588
1586
  | `Lbrack` | ⟦
1589
1587
  | `rBrack` | ⟧
1590
1588
  | `Rbrack` | ⟧
1591
- | `langle` | ⟨
1589
+ | `langle` | 〈
1592
1590
  | `lAngle` | ⟪
1593
1591
  | `rAngle` | ⟫
1594
- | `rangle` | ⟩
1592
+ | `rangle` | 〉
1595
1593
  | `lgroup` | ⟮
1596
1594
  | `rgroup` | ⟯
1597
1595
  | `Mapsto` | ⤇
@@ -72,8 +72,6 @@
72
72
  * `sec`
73
73
  * `ln`
74
74
  * `ul`
75
- * `g`
76
- * `f`
77
75
 
78
76
 
79
77
  === Tags
@@ -214,8 +212,8 @@
214
212
  | `\⊨` | ⊨
215
213
  | `\〈` | 〈
216
214
  | `\〉` | 〉
217
- | `\⟨` | ⟨
218
- | `\⟩` | ⟩
215
+ | `\〈` | 〈
216
+ | `\〉` | 〉
219
217
  | `\∫` | ∫
220
218
  | `\∮` | ∮
221
219
  | `\∂` | ∂
@@ -4,13 +4,13 @@ module Plurimath
4
4
  class Asciimath
5
5
  class Constants
6
6
  TABLE_PARENTHESIS = {
7
- "(:": ":)",
7
+ "": "",
8
8
  "ℒ": "ℛ",
9
9
  "[": "]",
10
10
  "(": ")",
11
11
  }.freeze
12
12
  PARENTHESIS = {
13
- "(:": ":)",
13
+ "": "",
14
14
  "ℒ": "ℛ",
15
15
  "(": ")",
16
16
  "{": "}",
@@ -286,8 +286,6 @@ module Plurimath
286
286
  vec
287
287
  ul
288
288
  ln
289
- f
290
- g
291
289
  ].freeze
292
290
  BINARY_CLASSES = %i[
293
291
  underset
@@ -58,8 +58,8 @@ module Plurimath
58
58
  end
59
59
 
60
60
  rule(:quoted_text) do
61
- str('"') >> match("[^\"]").repeat.as(:text) >> str('"') |
62
- str('"') >> str("").as(:text)
61
+ (str('"') >> match("[^\"]").repeat.as(:text) >> str('"')) |
62
+ (str('"') >> str("").as(:text))
63
63
  end
64
64
 
65
65
  rule(:symbol_text_or_integer) do
@@ -70,7 +70,7 @@ module Plurimath
70
70
  quoted_text |
71
71
  (str("d").as(:d) >> str("x").as(:x)).as(:intermediate_exp) |
72
72
  match["a-zA-Z"].as(:symbol) |
73
- match(/[^\[{(\\\/@;:.,'"|\]})0-9a-zA-Z\-><$%^&*_=+!`~\s?ℒℛ]/).as(:symbol) |
73
+ match(/[^\[{(\\\/@;:.,'"|\]})0-9a-zA-Z\-><$%^&*_=+!`~\s?ℒℛᑕᑐ]/).as(:symbol) |
74
74
  number
75
75
  end
76
76
 
@@ -89,16 +89,15 @@ module Plurimath
89
89
  end
90
90
 
91
91
  rule(:table) do
92
- (open_table.as(:table_left) >> tr >> close_table.as(:table_right)) |
93
- (open_table.as(:table_left) >> tr >> str("}").as(:table_right)) |
94
- (str("norm").as(:norm) >> open_table.as(:table_left) >> tr >> close_table.as(:table_right)) |
95
- (str("{").as(:table_left) >> tr >> close_table.as(:table_right)) |
96
- (str("|").as(:table_left) >> tr >> str("|").as(:table_right)) |
97
- (str("left") >> left_right_open_paren.as(:left) >> tr >> str("right") >> left_right_close_paren.as(:right))
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))
98
97
  end
99
98
 
100
99
  rule(:tr) do
101
- ((left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row) >> comma >> tr.as(:expr)) |
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)) |
102
101
  (left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row)
103
102
  end
104
103
 
@@ -13,6 +13,8 @@ module Plurimath
13
13
  &.gsub(/(\|:|:\|)/, "|")
14
14
  &.gsub(/(\{:)/, "ℒ")
15
15
  &.gsub(/(:\})/, "ℛ")
16
+ &.gsub(/(\(:)/, "ᑕ")
17
+ &.gsub(/(:\))/, "ᑐ")
16
18
  end
17
19
 
18
20
  def parse
@@ -407,7 +407,7 @@ module Plurimath
407
407
  rule(power_base: simple(:power_base),
408
408
  base: simple(:base)) do
409
409
  if base.is_a?(Math::Formula) && base.value.any? { |value| Utility.symbol_value(value, ",") }
410
- sliced = base.value.slice_before { |object| Utility.symbol_value(object, ",") }.to_a
410
+ sliced = base.value.slice_before { |object| Utility.symbol_value(object, ",") }.to_a
411
411
  base_object = Math::Function::Base.new(
412
412
  power_base,
413
413
  Utility.filter_values(
@@ -34,8 +34,6 @@ module Plurimath
34
34
  det
35
35
  ln
36
36
  lg
37
- g
38
- f
39
37
  ].freeze
40
38
  SUB_SUP_CLASSES = {
41
39
  "&prod;": :prod,
@@ -36,6 +36,11 @@ module Plurimath
36
36
  [sequence, expr]
37
37
  end
38
38
 
39
+ rule(sequence: simple(:sequence),
40
+ parse_parenthesis: simple(:parse_paren)) do
41
+ [sequence, parse_paren]
42
+ end
43
+
39
44
  rule(sequence: simple(:sequence),
40
45
  expression: sequence(:expr)) do
41
46
  expr.insert(0, sequence)
@@ -72,6 +77,13 @@ module Plurimath
72
77
  )
73
78
  end
74
79
 
80
+ rule(unary_function: simple(:unary_function),
81
+ sequence: sequence(:sequence)) do
82
+ Math::Formula.new(
83
+ ([unary_function] + sequence),
84
+ )
85
+ end
86
+
75
87
  rule(text: simple(:text),
76
88
  expression: simple(:expr)) do
77
89
  [
@@ -250,6 +262,16 @@ module Plurimath
250
262
  end
251
263
  end
252
264
 
265
+ rule(sub_sup: simple(:sub_sup),
266
+ sup_value: sequence(:sup_value),
267
+ expression: simple(:expression)) do
268
+ power = Math::Function::Power.new(
269
+ sub_sup,
270
+ Math::Formula.new(sup_value),
271
+ )
272
+ [power, expression]
273
+ end
274
+
253
275
  rule(lparen: simple(:lparen),
254
276
  text: simple(:text),
255
277
  rparen: simple(:rparen)) do
@@ -270,6 +292,18 @@ module Plurimath
270
292
  ])
271
293
  end
272
294
 
295
+ rule(lparen: simple(:lparen),
296
+ sequence: simple(:sequence),
297
+ parse_parenthesis: simple(:parse_paren),
298
+ rparen: simple(:rparen)) do
299
+ Math::Formula.new([
300
+ Math::Symbol.new(lparen),
301
+ sequence,
302
+ parse_paren,
303
+ Math::Symbol.new(rparen),
304
+ ])
305
+ end
306
+
273
307
  rule(lparen: simple(:lparen),
274
308
  sequence: sequence(:sequence),
275
309
  rparen: simple(:rparen)) do
@@ -1311,8 +1311,8 @@ module Plurimath
1311
1311
  Lbrack: "&#x27e6;",
1312
1312
  rBrack: "&#x27e7;",
1313
1313
  Rbrack: "&#x27e7;",
1314
- langle: "&#x27e8;",
1315
- rangle: "&#x27e9;",
1314
+ langle: "&#x2329;",
1315
+ rangle: "&#x232a;",
1316
1316
  lAngle: "&#x27ea;",
1317
1317
  rAngle: "&#x27eb;",
1318
1318
  lgroup: "&#x27ee;",
@@ -3787,8 +3787,8 @@ module Plurimath
3787
3787
  ].freeze
3788
3788
  LEFT_RIGHT_PARENTHESIS = {
3789
3789
  "\\backslash": "&#x5c;",
3790
- "\\langle": "&#x27e8;",
3791
- "\\rangle": "&#x27e9;",
3790
+ "\\langle": "&#x2329;",
3791
+ "\\rangle": "&#x232a;",
3792
3792
  "\\lfloor": "&#x230a;",
3793
3793
  "\\rfloor": "&#x230b;",
3794
3794
  "\\lceil": "&#x2308;",
@@ -3828,7 +3828,7 @@ module Plurimath
3828
3828
  |
3829
3829
  }
3830
3830
  {
3831
- ]
3831
+ ].freeze
3832
3832
  end
3833
3833
  end
3834
3834
  end
@@ -90,7 +90,7 @@ module Plurimath
90
90
  (slash >> math_operators_classes) |
91
91
  match["a-zA-Z"].as(:symbols) |
92
92
  match(/\d+(\.[0-9]+)|\d/).repeat(1).as(:number) |
93
- str("\\\\").as("\\\\") >> match(/\s/).repeat |
93
+ (str("\\\\").as("\\\\") >> match(/\s/).repeat) |
94
94
  str("\\ ").as(:space)
95
95
  end
96
96
 
@@ -140,10 +140,10 @@ module Plurimath
140
140
  (expression.repeat.as(:dividend) >> str("\\over") >> expression.repeat.as(:divisor)) |
141
141
  expression.as(:expression).maybe
142
142
  ) >>
143
- (
144
- str("\\right").as(:right).maybe >> (right_parens | str(".").maybe)
145
- )
146
- )
143
+ (
144
+ str("\\right").as(:right).maybe >> (right_parens | str(".").maybe)
145
+ )
146
+ )
147
147
  end
148
148
 
149
149
  rule(:over_class) do
@@ -156,7 +156,7 @@ module Plurimath
156
156
 
157
157
  rule(:iteration) do
158
158
  (sequence.as(:sequence) >> iteration.as(:expression)) |
159
- sequence >> expression.maybe
159
+ (sequence >> expression.maybe)
160
160
  end
161
161
 
162
162
  rule(:expression) do
@@ -204,7 +204,7 @@ module Plurimath
204
204
  when :binary
205
205
  (slashed_value(first_value, :binary) >> intermediate_exp.as(:first_value) >> intermediate_exp.as(:second_value)).as(:binary)
206
206
  when :text
207
- (slashed_value(first_value, :text) >> (str("{") >> (match("[^\}]").repeat).as(:first_value) >> str("}")))
207
+ (slashed_value(first_value, :text) >> (str("{") >> match("[^}]").repeat.as(:first_value) >> str("}")))
208
208
  end
209
209
  end
210
210
 
@@ -6,6 +6,11 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Fenced < TernaryFunction
9
+ def initialize(parameter_one = nil, parameter_two = nil, parameter_three = nil)
10
+ super
11
+ circular_parens
12
+ end
13
+
9
14
  def to_asciimath
10
15
  first_value = parameter_one ? parameter_one.to_asciimath : "("
11
16
  third_value = parameter_three ? parameter_three.to_asciimath : ")"
@@ -33,8 +38,8 @@ module Plurimath
33
38
  open_paren = parameter_one ? parameter_one.value : "("
34
39
  fenced_value = parameter_two&.map(&:to_latex)&.join(" ")
35
40
  close_paren = parameter_three ? parameter_three.value : ")"
36
- first_value = latex_paren(open_paren, false)
37
- second_value = latex_paren(close_paren, true)
41
+ first_value = latex_paren(open_paren)
42
+ second_value = latex_paren(close_paren)
38
43
  "#{first_value} #{fenced_value} #{second_value}"
39
44
  end
40
45
 
@@ -52,25 +57,6 @@ module Plurimath
52
57
 
53
58
  protected
54
59
 
55
- def second_value
56
- class_names = ["number", "symbol"].freeze
57
- parameter_two&.map do |object|
58
- e_tag = Utility.ox_element("e", namespace: "m")
59
- e_tag << if class_names.include?(object.class_name)
60
- fenced_omml_value(object)
61
- else
62
- object&.to_omml_without_math_tag
63
- end
64
- end
65
- end
66
-
67
- def fenced_omml_value(object)
68
- r_tag = Utility.ox_element("r", namespace: "m")
69
- t_tag = Utility.ox_element("t", namespace: "m")
70
- t_tag << object&.value
71
- r_tag << t_tag
72
- end
73
-
74
60
  def first_value(dpr)
75
61
  first_value = parameter_one&.value
76
62
  return dpr if first_value.nil? || first_value.empty?
@@ -83,6 +69,18 @@ module Plurimath
83
69
  )
84
70
  end
85
71
 
72
+ def second_value
73
+ class_names = ["number", "symbol"].freeze
74
+ parameter_two&.map do |object|
75
+ e_tag = Utility.ox_element("e", namespace: "m")
76
+ e_tag << if class_names.include?(object.class_name)
77
+ fenced_omml_value(object)
78
+ else
79
+ object&.to_omml_without_math_tag
80
+ end
81
+ end
82
+ end
83
+
86
84
  def third_value(dpr)
87
85
  third_value = parameter_three&.value
88
86
  return dpr if third_value.nil? || third_value.empty?
@@ -95,11 +93,19 @@ module Plurimath
95
93
  )
96
94
  end
97
95
 
98
- def latex_paren(paren, right)
96
+ def fenced_omml_value(object)
97
+ r_tag = Utility.ox_element("r", namespace: "m")
98
+ t_tag = Utility.ox_element("t", namespace: "m")
99
+ t_tag << object&.value
100
+ r_tag << t_tag
101
+ end
102
+
103
+ def latex_paren(paren)
99
104
  return "" if paren.nil? || paren.empty?
100
105
 
101
106
  paren = %w[{ }].include?(paren) ? "\\#{paren}" : paren
102
- "#{paren}"
107
+ paren = "\\#{Latex::Constants::UNICODE_SYMBOLS.invert[paren]}" if paren.to_s.match?(/\&#x.{0,4};/)
108
+ paren.to_s
103
109
  end
104
110
 
105
111
  def mathml_paren(field)
@@ -107,6 +113,11 @@ module Plurimath
107
113
 
108
114
  field&.value
109
115
  end
116
+
117
+ def circular_parens
118
+ parameter_one&.value = "&#x2329;" if Utility.symbol_value(parameter_one, "ᑕ")
119
+ parameter_three&.value = "&#x232a;" if Utility.symbol_value(parameter_three, "ᑐ")
120
+ end
110
121
  end
111
122
  end
112
123
  end
@@ -27,7 +27,7 @@ module Plurimath
27
27
  end
28
28
 
29
29
  def to_latex
30
- "\\left #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || "."}"
30
+ "\\left #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'}"
31
31
  end
32
32
 
33
33
  protected
@@ -27,7 +27,7 @@ module Plurimath
27
27
  end
28
28
 
29
29
  def to_latex
30
- "\\right #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || "."}"
30
+ "\\right #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'}"
31
31
  end
32
32
 
33
33
  protected
@@ -71,7 +71,7 @@ module Plurimath
71
71
  end
72
72
 
73
73
  def explicit_checks(unicode)
74
- return true if [unicode, value].any?{|v| ["∣", "|"].include?(v) }
74
+ return true if [unicode, value].any? { |v| ["∣", "|"].include?(v) }
75
75
  end
76
76
 
77
77
  def specific_values
@@ -93,8 +93,8 @@ module Plurimath
93
93
  "&#x22a8;": "|==",
94
94
  "&#x2329;": "(:",
95
95
  "&#x232a;": ":)",
96
- "&#x27e8;": "<<",
97
- "&#x27e9;": ">>",
96
+ "&#x2329;": "<<",
97
+ "&#x232a;": ">>",
98
98
  "&#x222b;": "int",
99
99
  "&#x222e;": "oint",
100
100
  "&#x2202;": "del",
@@ -225,8 +225,6 @@ module Plurimath
225
225
  log
226
226
  ul
227
227
  ln
228
- f
229
- g
230
228
  ].freeze
231
229
  OPERATORS = [
232
230
  "&#x00a0;&#x00a0;&#x00a0;&#x00a0;",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plurimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-06 00:00:00.000000000 Z
11
+ date: 2023-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -101,7 +101,6 @@ files:
101
101
  - lib/plurimath/math/function/dim.rb
102
102
  - lib/plurimath/math/function/dot.rb
103
103
  - lib/plurimath/math/function/exp.rb
104
- - lib/plurimath/math/function/f.rb
105
104
  - lib/plurimath/math/function/fenced.rb
106
105
  - lib/plurimath/math/function/floor.rb
107
106
  - lib/plurimath/math/function/font_style.rb
@@ -114,7 +113,6 @@ files:
114
113
  - lib/plurimath/math/function/font_style/sans-serif.rb
115
114
  - lib/plurimath/math/function/font_style/script.rb
116
115
  - lib/plurimath/math/function/frac.rb
117
- - lib/plurimath/math/function/g.rb
118
116
  - lib/plurimath/math/function/gcd.rb
119
117
  - lib/plurimath/math/function/glb.rb
120
118
  - lib/plurimath/math/function/hat.rb
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "unary_function"
4
-
5
- module Plurimath
6
- module Math
7
- module Function
8
- class F < UnaryFunction
9
- def to_asciimath
10
- "f#{parameter_one&.to_asciimath}"
11
- end
12
-
13
- def to_latex
14
- first_value = latex_value if parameter_one
15
- "f#{first_value}"
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "unary_function"
4
-
5
- module Plurimath
6
- module Math
7
- module Function
8
- class G < UnaryFunction
9
- def to_asciimath
10
- "g#{parameter_one&.to_asciimath}"
11
- end
12
-
13
- def to_latex
14
- "g#{parameter_one&.to_latex}"
15
- end
16
- end
17
- end
18
- end
19
- end