plurimath 0.8.15 → 0.8.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/plurimath/formatter/numeric_formatter.rb +1 -6
- data/lib/plurimath/formatter/standard.rb +3 -1
- data/lib/plurimath/formatter.rb +14 -0
- data/lib/plurimath/latex/parse.rb +2 -1
- data/lib/plurimath/math/formula.rb +16 -3
- data/lib/plurimath/math.rb +1 -0
- data/lib/plurimath/number_formatter.rb +5 -5
- data/lib/plurimath/unitsml.rb +3 -1
- data/lib/plurimath/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9de48dbb937f65122d95415947e417692fc0d5a11d48e7a1caa1b54f3c4465bf
|
4
|
+
data.tar.gz: 2f1e748929a2569b2e7b291381624648fc11a3fc2b93d44406a9a92c2fa21068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8054b884f09d830a6b7a1e98d1c5679434540f6ad018c4135654f3ea4495336aa4971e43be842def4ad0fc139664ffa477c12407cef5553c55c46f9d0f2037d
|
7
|
+
data.tar.gz: 852c85f6edab822fc8e880ceded6913283be3e65300069be0fd7a898b6d057bb1143fee9f1e5b182a9dee36213c564e11038cb38040b58586c5acbd16b0d063d
|
@@ -1,9 +1,4 @@
|
|
1
|
-
|
2
|
-
require_relative "numbers/base"
|
3
|
-
require_relative "numbers/integer"
|
4
|
-
require_relative "numbers/fraction"
|
5
|
-
require_relative "numbers/significant"
|
6
|
-
require_relative "number_formatter"
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
3
|
module Plurimath
|
9
4
|
module Formatter
|
@@ -14,6 +14,7 @@ module Plurimath
|
|
14
14
|
group_digits: 3,
|
15
15
|
significant: 0,
|
16
16
|
digit_count: 0,
|
17
|
+
precision: 0,
|
17
18
|
decimal: ".",
|
18
19
|
group: ",",
|
19
20
|
times: "x",
|
@@ -21,16 +22,17 @@ module Plurimath
|
|
21
22
|
}.freeze
|
22
23
|
|
23
24
|
def initialize(locale: "en", string_format: nil, options: {}, precision: nil)
|
24
|
-
@precision = precision
|
25
25
|
super(
|
26
26
|
locale,
|
27
27
|
localize_number: string_format,
|
28
28
|
localizer_symbols: set_default_options(options),
|
29
|
+
precision: precision,
|
29
30
|
)
|
30
31
|
end
|
31
32
|
|
32
33
|
def set_default_options(options)
|
33
34
|
default_options = self.class::DEFAULT_OPTIONS
|
35
|
+
self.precision ||= default_options[:precision]
|
34
36
|
options ||= default_options
|
35
37
|
options[:fraction_group_digits] ||= default_options[:fraction_group_digits]
|
36
38
|
options[:fraction_group] ||= default_options[:fraction_group]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "formatter/numeric_formatter"
|
4
|
+
require_relative "formatter/supported_locales"
|
5
|
+
require_relative "formatter/numbers/base"
|
6
|
+
require_relative "formatter/numbers/integer"
|
7
|
+
require_relative "formatter/numbers/fraction"
|
8
|
+
require_relative "formatter/numbers/significant"
|
9
|
+
require_relative "formatter/number_formatter"
|
10
|
+
|
11
|
+
module Plurimath
|
12
|
+
module Formatter
|
13
|
+
end
|
14
|
+
end
|
@@ -97,7 +97,8 @@ module Plurimath
|
|
97
97
|
rparen.absent? >> symbol_class_commands |
|
98
98
|
(slash >> math_operators_classes) |
|
99
99
|
match["a-zA-Z"].as(:symbols) |
|
100
|
-
match
|
100
|
+
(match["0-9"].repeat(0) >> str(".").maybe >> match["0-9"].repeat(1)).as(:number) |
|
101
|
+
match["0-9"].repeat(1).as(:number) |
|
101
102
|
(str("\\\\").as("\\\\") >> match(/\s/).repeat) |
|
102
103
|
str("\\ ").as(:space) |
|
103
104
|
(str("\\operatorname{") >> match("[^}]").repeat.as(:symbols) >> str("}"))
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Plurimath
|
4
4
|
module Math
|
5
5
|
class Formula < Core
|
6
|
-
attr_accessor :value, :left_right_wrapper, :displaystyle, :input_string, :unitsml
|
6
|
+
attr_accessor :value, :left_right_wrapper, :displaystyle, :input_string, :unitsml, :unitsml_xml
|
7
7
|
|
8
8
|
MATH_ZONE_TYPES = %i[
|
9
9
|
omml
|
@@ -48,8 +48,14 @@ module Plurimath
|
|
48
48
|
parse_error!(:asciimath)
|
49
49
|
end
|
50
50
|
|
51
|
-
def to_mathml(
|
52
|
-
|
51
|
+
def to_mathml(
|
52
|
+
intent: false,
|
53
|
+
formatter: nil,
|
54
|
+
unitsml_xml: nil,
|
55
|
+
split_on_linebreak: false,
|
56
|
+
display_style: displaystyle
|
57
|
+
)
|
58
|
+
options = { formatter: formatter, unitsml_xml: unitsml_xml }
|
53
59
|
return line_breaked_mathml(display_style, intent, options: options) if split_on_linebreak
|
54
60
|
|
55
61
|
math_attrs = {
|
@@ -80,6 +86,7 @@ module Plurimath
|
|
80
86
|
attributes = intent_attribute(mathml_value) if intent
|
81
87
|
mrow = ox_element("mrow", attributes: attributes)
|
82
88
|
mrow[:unitsml] = true if unitsml
|
89
|
+
mathml_value += wrapped_unitsml_xml(mrow) if unitsml_xml && options[:unitsml_xml]
|
83
90
|
Utility.update_nodes(mrow, mathml_value)
|
84
91
|
end
|
85
92
|
|
@@ -329,6 +336,12 @@ module Plurimath
|
|
329
336
|
end
|
330
337
|
end
|
331
338
|
|
339
|
+
def wrapped_unitsml_xml(mrow)
|
340
|
+
node = Plurimath.xml_engine.load("<mrow>#{unitsml_xml}</mrow>")
|
341
|
+
mrow.attributes[:xref] = node.locate("*/@id").first if node.locate("*/@id").any?
|
342
|
+
node.nodes
|
343
|
+
end
|
344
|
+
|
332
345
|
def space_element(node)
|
333
346
|
element = (ox_element("mo") << "⁢")
|
334
347
|
element[:rspace] = "thickmathspace" if text_in_tag?(node.xml_nodes.nodes)
|
data/lib/plurimath/math.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require_relative "formatter
|
2
|
-
require_relative "formatter/supported_locales"
|
1
|
+
require_relative "formatter"
|
3
2
|
|
4
3
|
module Plurimath
|
5
4
|
class NumberFormatter
|
6
|
-
attr_accessor :locale, :localize_number, :localizer_symbols
|
5
|
+
attr_accessor :locale, :localize_number, :localizer_symbols, :precision
|
7
6
|
|
8
|
-
def initialize(locale = "en", localize_number: nil, localizer_symbols: {})
|
7
|
+
def initialize(locale = "en", localize_number: nil, localizer_symbols: {}, precision: nil)
|
9
8
|
@locale = supported_locale(locale)
|
10
9
|
@localize_number = localize_number
|
11
10
|
@localizer_symbols = localizer_symbols
|
11
|
+
@precision = precision
|
12
12
|
end
|
13
13
|
|
14
|
-
def localized_number(number_string, locale: @locale, precision:
|
14
|
+
def localized_number(number_string, locale: @locale, precision: @precision, format: {})
|
15
15
|
prev_symbols = symbols(locale).dup
|
16
16
|
Formatter::NumericFormatter.new(
|
17
17
|
supported_locale(locale),
|
data/lib/plurimath/unitsml.rb
CHANGED
@@ -11,9 +11,11 @@ module Plurimath
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def to_formula
|
14
|
-
|
14
|
+
unitsml = ::Unitsml.parse(text)
|
15
|
+
formula = unitsml.to_plurimath
|
15
16
|
formula.unitsml = true
|
16
17
|
formula.input_string = text
|
18
|
+
formula.unitsml_xml = unitsml.to_xml
|
17
19
|
formula
|
18
20
|
end
|
19
21
|
|
data/lib/plurimath/version.rb
CHANGED
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.8.
|
4
|
+
version: 0.8.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/plurimath/asciimath/parser.rb
|
103
103
|
- lib/plurimath/asciimath/transform.rb
|
104
104
|
- lib/plurimath/cli.rb
|
105
|
+
- lib/plurimath/formatter.rb
|
105
106
|
- lib/plurimath/formatter/number_formatter.rb
|
106
107
|
- lib/plurimath/formatter/numbers/base.rb
|
107
108
|
- lib/plurimath/formatter/numbers/fraction.rb
|