plurimath 0.2.8 → 0.2.9

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: 10dc48ba50b0b3ace7230a0dc8c55ea8fa208e1b8e124cbbf19e2b081ddb6918
4
- data.tar.gz: 36aa56b4193aa367343195e33160d5213dbd3efe9655b110a387b5fa84374e22
3
+ metadata.gz: 8c97fcf3901a7da18bbac329563b358490117e3ec3103f6c5c9e4e8ad7b5d3c8
4
+ data.tar.gz: abe2849aa2d81cb246b2b703576c6ae0df283b323e27433a9af95d07c1dd9932
5
5
  SHA512:
6
- metadata.gz: 59b85358ee2f0de5f345a0179aca97243483aa5d31e0a7a858ef4c9421ce546d9a9ee72094a4306c704b350d7caa80315bc331b7e8d500ffbf0175a0d1c859b5
7
- data.tar.gz: c3ada4b68b411110f533dfb2297f9d0f9cad47200a5b39475b300c9f1687b18ed5e199fd12b5d8d0f3ff971ae1790187d28629e162eba14edd575aafeab1ee74
6
+ metadata.gz: 2ac0c52f647ba6ff70bbf2fd0d9af2a33df8176c287699e8e99aa3478eaa44fe9b8fabcb54d115de5116f6823f2cdcda0f53965bbde806f47b948f3ca5d2a81c
7
+ data.tar.gz: ba854ed8ecd87cd3fb30e2c80508abfaa0d900a22f3492d531f0b592272d692d9886203db73d81da1dbe0b3402831c2164f8c32472d69926f8976f069eab3718
@@ -109,7 +109,7 @@ module Plurimath
109
109
 
110
110
  rule(:sequence) do
111
111
  (lparen.as(:lparen) >> space.maybe >> expression.maybe.as(:expr) >> space.maybe >> rparen.maybe.as(:rparen)).as(:intermediate_exp) |
112
- (str("text") >> lparen.capture(:paren).as(:lparen) >> read_text.as(:text) >> rparen.maybe.as(:rparen)).as(:intermediate_exp) |
112
+ (str("text") >> lparen.capture(:paren) >> read_text.as(:text) >> rparen.maybe).as(:intermediate_exp) |
113
113
  symbol_text_or_integer
114
114
  end
115
115
 
@@ -1089,15 +1089,11 @@ module Plurimath
1089
1089
  [expr]
1090
1090
  end
1091
1091
  right_paren = rparen.to_s.empty? ? "" : rparen
1092
- if expr.is_a?(Math::Function::Text)
1093
- expr
1094
- else
1095
- Math::Function::Fenced.new(
1096
- Utility.symbol_object(lparen),
1097
- form_value&.flatten&.compact,
1098
- Utility.symbol_object(right_paren),
1099
- )
1100
- end
1092
+ Math::Function::Fenced.new(
1093
+ Utility.symbol_object(lparen),
1094
+ form_value&.flatten&.compact,
1095
+ Utility.symbol_object(right_paren),
1096
+ )
1101
1097
  end
1102
1098
 
1103
1099
  rule(lparen: simple(:lparen),
@@ -42,11 +42,11 @@ module Plurimath
42
42
  end
43
43
 
44
44
  def to_latex
45
- value.map(&:to_latex).join(" ")
45
+ value&.map(&:to_latex)&.join(" ")
46
46
  end
47
47
 
48
48
  def to_html
49
- value.map(&:to_html).join(" ")
49
+ value&.map(&:to_html)&.join(" ")
50
50
  end
51
51
 
52
52
  def omml_math_attrs
@@ -13,8 +13,7 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_mathml_without_math_tag
16
- under_classes = ["ubrace", "obrace"] + Utility::UNARY_CLASSES
17
- tag_name = (under_classes.include?(parameter_one&.class_name) ? "under" : "sub")
16
+ tag_name = (Utility::MUNDER_CLASSES.include?(parameter_one&.class_name) ? "under" : "sub")
18
17
  sub_tag = Utility.ox_element("m#{tag_name}")
19
18
  mathml_value = []
20
19
  mathml_value << parameter_one&.to_mathml_without_math_tag
@@ -46,7 +46,7 @@ module Plurimath
46
46
  dpr << Utility.pr_element("ctrl", true, namespace: "m")
47
47
  Utility.update_nodes(
48
48
  d,
49
- [dpr] + second_value,
49
+ [dpr] + Array(second_value),
50
50
  )
51
51
  end
52
52
 
@@ -54,12 +54,12 @@ module Plurimath
54
54
 
55
55
  def second_value
56
56
  class_names = ["number", "symbol"].freeze
57
- parameter_two.map do |object|
57
+ parameter_two&.map do |object|
58
58
  e_tag = Utility.ox_element("e", namespace: "m")
59
59
  e_tag << if class_names.include?(object.class_name)
60
60
  fenced_omml_value(object)
61
61
  else
62
- object.to_omml_without_math_tag
62
+ object&.to_omml_without_math_tag
63
63
  end
64
64
  end
65
65
  end
@@ -67,7 +67,7 @@ module Plurimath
67
67
  def fenced_omml_value(object)
68
68
  r_tag = Utility.ox_element("r", namespace: "m")
69
69
  t_tag = Utility.ox_element("t", namespace: "m")
70
- t_tag << object.value
70
+ t_tag << object&.value
71
71
  r_tag << t_tag
72
72
  end
73
73
 
@@ -97,16 +97,16 @@ module Plurimath
97
97
 
98
98
  def latex_paren(paren, right)
99
99
  paren_side = right ? "\\right" : "\\left"
100
- return "#{paren_side} ." if paren.include?(":")
100
+ return "#{paren_side} ." if paren&.include?(":")
101
101
 
102
102
  paren = %w[{ }].include?(paren) ? "\\#{paren}" : paren
103
103
  " #{paren_side} #{paren} "
104
104
  end
105
105
 
106
106
  def mathml_paren(field)
107
- return "" if field.value.include?(":")
107
+ return "" if field&.value&.include?(":")
108
108
 
109
- field.value
109
+ field&.value
110
110
  end
111
111
  end
112
112
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "mathbf(#{parameter_one.to_asciimath})"
16
+ "mathbf(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathbf{#{first_value}}"
20
+ "\\mathbf{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "bold" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "mathbb(#{parameter_one.to_asciimath})"
16
+ "mathbb(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathbb{#{first_value}}"
20
+ "\\mathbb{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "double-struck" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "mathfrak(#{parameter_one.to_asciimath})"
16
+ "mathfrak(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathfrak{#{first_value}}"
20
+ "\\mathfrak{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "fraktur" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "ii(#{parameter_one.to_asciimath})"
16
+ "ii(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathit{#{first_value}}"
20
+ "\\mathit{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "italic" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "mathtt(#{parameter_one.to_asciimath})"
16
+ "mathtt(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathtt{#{first_value}}"
20
+ "\\mathtt{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "monospace" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "rm(#{parameter_one.to_asciimath})"
16
+ "rm(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathrm{#{first_value}}"
20
+ "\\mathrm{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "normal" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "mathsf(#{parameter_one.to_asciimath})"
16
+ "mathsf(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathsf{#{first_value}}"
20
+ "\\mathsf{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "sans-serif" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -13,12 +13,11 @@ module Plurimath
13
13
  end
14
14
 
15
15
  def to_asciimath
16
- "mathcal(#{parameter_one.to_asciimath})"
16
+ "mathcal(#{parameter_one&.to_asciimath})"
17
17
  end
18
18
 
19
19
  def to_latex
20
- first_value = parameter_one.to_latex if parameter_one
21
- "\\mathcal{#{first_value}}"
20
+ "\\mathcal{#{parameter_one&.to_latex}}"
22
21
  end
23
22
 
24
23
  def to_mathml_without_math_tag
@@ -27,7 +26,7 @@ module Plurimath
27
26
  "mstyle",
28
27
  attributes: { mathvariant: "script" },
29
28
  ),
30
- [parameter_one.to_mathml_without_math_tag],
29
+ [parameter_one&.to_mathml_without_math_tag],
31
30
  )
32
31
  end
33
32
  end
@@ -48,16 +48,15 @@ module Plurimath
48
48
  def to_omml_without_math_tag
49
49
  limupp = Utility.ox_element("limLow", namespace: "m")
50
50
  limupppr = Utility.ox_element("limUppPr", namespace: "m")
51
- sum << Utility.pr_element("e", true, namespace: "m")
52
- me = (Utility.ox_element("e", namespace: "m") << omml_first_value)
53
- lim = (Utility.ox_element("lim", namespace: "m") << omml_second_value)
51
+ me = (Utility.ox_element("e", namespace: "m") << omml_first_value) if parameter_one
52
+ lim = (Utility.ox_element("lim", namespace: "m") << omml_second_value) if parameter_two
54
53
  Utility.update_nodes(limupp, [limupppr, me, lim])
55
54
  end
56
55
 
57
56
  protected
58
57
 
59
58
  def omml_first_value
60
- return parameter_one.to_omml_without_math_tag unless parameter_one.is_a?(Math::Symbol)
59
+ return parameter_one&.to_omml_without_math_tag unless parameter_one&.is_a?(Math::Symbol)
61
60
 
62
61
  mt = Utility.ox_element("t", namespace: "m")
63
62
  mt << parameter_one.to_omml_without_math_tag if parameter_one
@@ -65,7 +64,7 @@ module Plurimath
65
64
  end
66
65
 
67
66
  def omml_second_value
68
- return parameter_two.to_omml_without_math_tag unless parameter_two.is_a?(Math::Symbol)
67
+ return parameter_two&.to_omml_without_math_tag unless parameter_two&.is_a?(Math::Symbol)
69
68
 
70
69
  mt = Utility.ox_element("t", namespace: "m")
71
70
  mt << parameter_two.to_omml_without_math_tag if parameter_two
@@ -41,6 +41,14 @@ module Plurimath
41
41
 
42
42
  klass = VALID_TYPES[type.to_sym]
43
43
  klass.new(text).to_formula
44
+ rescue => ee
45
+ message = <<~MESSAGE
46
+ An error occurred while processing the input. Please check your input to ensure it is valid or open an issue on Github If you believe the input is correct.
47
+ ---- INPUT START ----
48
+ #{text}
49
+ ---- INPUT END ----
50
+ MESSAGE
51
+ raise Math::Error.new(message), cause: nil
44
52
  end
45
53
 
46
54
  private
@@ -67,6 +67,13 @@ module Plurimath
67
67
  f
68
68
  g
69
69
  ].freeze
70
+ MUNDER_CLASSES = %w[
71
+ ubrace
72
+ obrace
73
+ right
74
+ max
75
+ min
76
+ ].freeze
70
77
 
71
78
  class << self
72
79
  def organize_table(array, column_align: nil, options: nil)
@@ -187,7 +194,7 @@ module Plurimath
187
194
  element
188
195
  end
189
196
 
190
- def pr_element(main_tag, wi_tag, namespace: "")
197
+ def pr_element(main_tag, wi_tag = false, namespace: "")
191
198
  tag_name = "#{main_tag}Pr"
192
199
  ox_element(
193
200
  tag_name,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.2.8"
4
+ VERSION = "0.2.9"
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.2.8
4
+ version: 0.2.9
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-04-16 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet