asciimath2unitsml 0.3.2 → 0.3.3
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/.github/workflows/rake.yml +2 -23
- data/.hound.yml +5 -0
- data/.rubocop.yml +3 -7
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/asciimath2unitsml.gemspec +13 -16
- data/bin/rspec +1 -2
- data/lib/asciimath2unitsml.rb +0 -1
- data/lib/asciimath2unitsml/conv.rb +13 -13
- data/lib/asciimath2unitsml/parse.rb +27 -15
- data/lib/asciimath2unitsml/render.rb +22 -16
- data/lib/asciimath2unitsml/unit.rb +21 -17
- data/lib/asciimath2unitsml/validate.rb +14 -14
- data/lib/asciimath2unitsml/version.rb +1 -1
- data/lib/unitsdb_ruby/unitsdb.rb +21 -11
- data/spec/conv_spec.rb +1232 -1230
- data/spec/spec_helper.rb +10 -10
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829d573c90a88f5d26b2310d69f5ea575084df208cd3f441342435b0a6a3d353
|
4
|
+
data.tar.gz: 534c2ea7485b1de1c126de112a1ad8c9b10683797034e99313fda199c5f7e572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6eec2cb24fff7931d236a9a14a6d4ae1a938fe348d1e1d02a4d2f9be8e7f72e124e633ef0ef4b0f1e476ee8a2dee900210e60010600e0b082eb95237d2c70d2
|
7
|
+
data.tar.gz: e6943596be90a3bd1e6336b7bfa395cee4aa41e88ab6e5b2d003216a2271fc72249a018218d65c4ef446f4d246412e2b9fa0ac0d9721095abd4d9baa95515389
|
data/.github/workflows/rake.yml
CHANGED
@@ -16,21 +16,11 @@ jobs:
|
|
16
16
|
strategy:
|
17
17
|
fail-fast: false
|
18
18
|
matrix:
|
19
|
-
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
19
|
+
ruby: [ '3.0', '2.7', '2.6', '2.5', '2.4' ]
|
20
20
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
21
|
experimental: [ false ]
|
22
|
-
include:
|
23
|
-
- ruby: '3.0'
|
24
|
-
os: 'ubuntu-latest'
|
25
|
-
experimental: true
|
26
|
-
- ruby: '3.0'
|
27
|
-
os: 'windows-latest'
|
28
|
-
experimental: true
|
29
|
-
- ruby: '3.0'
|
30
|
-
os: 'macos-latest'
|
31
|
-
experimental: true
|
32
22
|
steps:
|
33
|
-
- uses: actions/checkout@
|
23
|
+
- uses: actions/checkout@v2
|
34
24
|
with:
|
35
25
|
submodules: true
|
36
26
|
|
@@ -40,14 +30,3 @@ jobs:
|
|
40
30
|
bundler-cache: true
|
41
31
|
|
42
32
|
- run: bundle exec rake
|
43
|
-
|
44
|
-
tests-passed:
|
45
|
-
needs: rake
|
46
|
-
runs-on: ubuntu-latest
|
47
|
-
steps:
|
48
|
-
- uses: peter-evans/repository-dispatch@v1
|
49
|
-
with:
|
50
|
-
token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
|
51
|
-
repository: ${{ github.repository }}
|
52
|
-
event-type: notify
|
53
|
-
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
data/.hound.yml
ADDED
data/.rubocop.yml
CHANGED
@@ -1,14 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# https://github.com/
|
3
|
-
# All project-specific additions and overrides should be specified in this file.
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
4
3
|
inherit_from:
|
5
4
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
6
5
|
|
7
6
|
# local repo-specific modifications
|
7
|
+
# ...
|
8
8
|
|
9
9
|
AllCops:
|
10
|
-
DisplayCopNames: false
|
11
|
-
StyleGuideCopsOnly: false
|
12
10
|
TargetRubyVersion: 2.4
|
13
|
-
Rails:
|
14
|
-
Enabled: true
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/asciimath2unitsml.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
lib = File.expand_path("
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require "asciimath2unitsml/version"
|
6
6
|
|
@@ -29,25 +29,23 @@ Gem::Specification.new do |spec|
|
|
29
29
|
.split("\n")
|
30
30
|
.map { |kv_str| kv_str.split(" ") }
|
31
31
|
.each do |(_, submodule_path)|
|
32
|
+
# for each submodule, change working directory to that submodule
|
33
|
+
Dir.chdir(submodule_path) do
|
34
|
+
# issue git ls-files in submodule's directory
|
35
|
+
submodule_files = `git ls-files | grep -i '.yaml$'`.split($\)
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
# issue git ls-files in submodule's directory
|
37
|
-
submodule_files = `git ls-files | grep -i '.yaml$'`.split($\)
|
38
|
-
|
39
|
-
submodule_files_paths = submodule_files.map do |filename|
|
40
|
-
File.join submodule_path, filename
|
41
|
-
end
|
42
|
-
|
43
|
-
# add relative paths to gem.files
|
44
|
-
spec.files += submodule_files_paths
|
37
|
+
submodule_files_paths = submodule_files.map do |filename|
|
38
|
+
File.join submodule_path, filename
|
45
39
|
end
|
40
|
+
|
41
|
+
# add relative paths to gem.files
|
42
|
+
spec.files += submodule_files_paths
|
43
|
+
end
|
46
44
|
end
|
47
45
|
|
48
46
|
spec.add_dependency "asciimath"
|
49
47
|
spec.add_dependency "htmlentities"
|
50
|
-
spec.add_dependency "nokogiri", "~> 1.
|
48
|
+
spec.add_dependency "nokogiri", "~> 1.11"
|
51
49
|
spec.add_dependency "rsec", "~> 1.0.0"
|
52
50
|
|
53
51
|
spec.add_development_dependency "bundler"
|
@@ -56,10 +54,9 @@ Gem::Specification.new do |spec|
|
|
56
54
|
spec.add_development_dependency "guard", "~> 2.14"
|
57
55
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
58
56
|
spec.add_development_dependency "rake", "~> 12.0"
|
57
|
+
spec.add_development_dependency "rexml"
|
59
58
|
spec.add_development_dependency "rspec", "~> 3.6"
|
60
59
|
spec.add_development_dependency "rubocop", "~> 1.5.2"
|
61
60
|
spec.add_development_dependency "simplecov", "~> 0.15"
|
62
61
|
spec.add_development_dependency "timecop", "~> 0.9"
|
63
|
-
spec.add_development_dependency "rexml"
|
64
62
|
end
|
65
|
-
|
data/bin/rspec
CHANGED
data/lib/asciimath2unitsml.rb
CHANGED
@@ -46,7 +46,7 @@ module Asciimath2UnitsML
|
|
46
46
|
|
47
47
|
def prefix(units)
|
48
48
|
units.map { |u| u[:prefix] }.reject(&:nil?).uniq.map do |p|
|
49
|
-
<<~
|
49
|
+
<<~XML
|
50
50
|
<Prefix xmlns='#{UNITSML_NS}' prefixBase='#{@prefixes[p].base}'
|
51
51
|
prefixPower='#{@prefixes[p].power}' xml:id='#{@prefixes[p].id}'>
|
52
52
|
<PrefixName xml:lang="en">#{@prefixes[p].name}</PrefixName>
|
@@ -55,18 +55,18 @@ module Asciimath2UnitsML
|
|
55
55
|
<PrefixSymbol type="LaTeX">#{@prefixes[p].latex}</PrefixSymbol>
|
56
56
|
<PrefixSymbol type="HTML">#{htmlent @prefixes[p].html}</PrefixSymbol>
|
57
57
|
</Prefix>
|
58
|
-
|
58
|
+
XML
|
59
59
|
end.join("\n")
|
60
60
|
end
|
61
61
|
|
62
62
|
def dimension_components(dims)
|
63
63
|
return if dims.nil? || dims.empty?
|
64
64
|
|
65
|
-
<<~
|
65
|
+
<<~XML
|
66
66
|
<Dimension xmlns='#{UNITSML_NS}' xml:id="#{dim_id(dims)}">
|
67
67
|
#{dims.map { |u| dimension1(u) }.join("\n")}
|
68
68
|
</Dimension>
|
69
|
-
|
69
|
+
XML
|
70
70
|
end
|
71
71
|
|
72
72
|
U2D = {
|
@@ -98,9 +98,9 @@ module Asciimath2UnitsML
|
|
98
98
|
end.sort { |a, b| U2D[a[:unit]][:order] <=> U2D[b[:unit]][:order] }
|
99
99
|
end
|
100
100
|
|
101
|
-
def dimension1(
|
102
|
-
%(<#{
|
103
|
-
powerNumerator="#{float_to_display(
|
101
|
+
def dimension1(dim)
|
102
|
+
%(<#{dim[:dimension]} symbol="#{dim[:symbol]}"
|
103
|
+
powerNumerator="#{float_to_display(dim[:exponent])}"/>)
|
104
104
|
end
|
105
105
|
|
106
106
|
def dim_id(dims)
|
@@ -188,11 +188,11 @@ module Asciimath2UnitsML
|
|
188
188
|
id = quantity || @units[normtext].quantities.first
|
189
189
|
@units[normtext]&.dimension and
|
190
190
|
dim = %( dimensionURL="##{@units[normtext].dimension}")
|
191
|
-
<<~
|
191
|
+
<<~XML
|
192
192
|
<Quantity xmlns='#{UNITSML_NS}' xml:id="#{id}"#{dim} quantityType="base">
|
193
193
|
#{quantityname(id)}
|
194
194
|
</Quantity>
|
195
|
-
|
195
|
+
XML
|
196
196
|
end
|
197
197
|
|
198
198
|
def dimid2dimensions(normtext)
|
@@ -207,22 +207,22 @@ module Asciimath2UnitsML
|
|
207
207
|
return unless @units[normtext]&.dimension
|
208
208
|
|
209
209
|
dims = dimid2dimensions(@units[normtext]&.dimension)
|
210
|
-
<<~
|
210
|
+
<<~XML
|
211
211
|
<Dimension xmlns='#{UNITSML_NS}' xml:id="#{@units[normtext]&.dimension}">
|
212
212
|
#{dims.map { |u| dimension1(u) }.join("\n")}
|
213
213
|
</Dimension>
|
214
|
-
|
214
|
+
XML
|
215
215
|
end
|
216
216
|
|
217
217
|
def unitsml(units, origtext, normtext, quantity, name)
|
218
218
|
dims = units2dimensions(units)
|
219
|
-
<<~
|
219
|
+
<<~XML
|
220
220
|
#{unit(units, origtext, normtext, dims, name)}
|
221
221
|
#{prefix(units)}
|
222
222
|
#{dimension(normtext)}
|
223
223
|
#{dimension_components(dims)}
|
224
224
|
#{quantity(normtext, quantity)}
|
225
|
-
|
225
|
+
XML
|
226
226
|
end
|
227
227
|
end
|
228
228
|
end
|
@@ -67,8 +67,8 @@ module Asciimath2UnitsML
|
|
67
67
|
parser = units.eof
|
68
68
|
end
|
69
69
|
|
70
|
-
def parse(
|
71
|
-
text = Array(
|
70
|
+
def parse(expr)
|
71
|
+
text = Array(expr.split(/,\s*/))
|
72
72
|
units = @parser.parse!(text[0])
|
73
73
|
if !units || Rsec::INVALID[units]
|
74
74
|
raise Rsec::SyntaxError.new "error parsing UnitsML expression", x, 1, 0
|
@@ -80,10 +80,18 @@ module Asciimath2UnitsML
|
|
80
80
|
|
81
81
|
def postprocess(units, text)
|
82
82
|
units = postprocess1(units.flatten)
|
83
|
-
quantity = text[1..-1]&.select
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
quantity = text[1..-1]&.select do |x|
|
84
|
+
/^quantity:/.match(x)
|
85
|
+
end&.first&.sub(/^quantity:\s*/, "")
|
86
|
+
name = text[1..-1]&.select do |x|
|
87
|
+
/^name:/.match(x)
|
88
|
+
end&.first&.sub(/^name:\s*/, "")
|
89
|
+
symbol = text[1..-1]&.select do |x|
|
90
|
+
/^symbol:/.match(x)
|
91
|
+
end&.first&.sub(/^symbol:\s*/, "")
|
92
|
+
multiplier = text[1..-1]&.select do |x|
|
93
|
+
/^multiplier:/.match(x)
|
94
|
+
end&.first&.sub(/^multiplier:\s*/, "")
|
87
95
|
normtext = units_only(units).each.map do |u|
|
88
96
|
exp = u[:exponent] && u[:exponent] != "1" ? "^#{u[:exponent]}" : ""
|
89
97
|
"#{u[:prefix]}#{u[:unit]}#{exp}"
|
@@ -110,14 +118,16 @@ module Asciimath2UnitsML
|
|
110
118
|
MathML2UnitsML(xml).to_xml
|
111
119
|
end
|
112
120
|
|
113
|
-
# https://www.w3.org/TR/mathml-units/ section 2:
|
121
|
+
# https://www.w3.org/TR/mathml-units/ section 2:
|
122
|
+
# delimit number Invisible-Times unit
|
114
123
|
def MathML2UnitsML(xml)
|
115
124
|
xml.is_a? String and xml = Nokogiri::XML(xml)
|
116
125
|
xml.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
|
117
|
-
next unless %r{^unitsml\(.+\)$}.match(x.text)
|
126
|
+
next unless %r{^unitsml\(.+\)$}.match?(x.text)
|
118
127
|
|
119
128
|
text = x.text.sub(%r{^unitsml\((.+)\)$}m, "\\1")
|
120
|
-
units, origtext, normtext, quantity, name, symbol, multiplier =
|
129
|
+
units, origtext, normtext, quantity, name, symbol, multiplier =
|
130
|
+
parse(text)
|
121
131
|
rendering = symbol ? embeddedmathml(asciimath2mathml(symbol)) :
|
122
132
|
mathmlsymbol(units, false, multiplier)
|
123
133
|
x.replace("#{delimspace(rendering, x)}"\
|
@@ -127,11 +137,13 @@ module Asciimath2UnitsML
|
|
127
137
|
dedup_ids(xml)
|
128
138
|
end
|
129
139
|
|
130
|
-
# if previous sibling's last descendent non-whitespace is MathML and
|
140
|
+
# if previous sibling's last descendent non-whitespace is MathML and
|
141
|
+
# mn or mi, no space
|
131
142
|
def delimspace(rendering, elem)
|
132
143
|
prec_text_elem =
|
133
144
|
elem.xpath("./preceding-sibling::*[namespace-uri() = '#{MATHML_NS}']/"\
|
134
|
-
"descendant::text()[normalize-space()!='']
|
145
|
+
"descendant::text()[normalize-space()!='']"\
|
146
|
+
"[last()]/parent::*").last
|
135
147
|
return "" if prec_text_elem.nil? ||
|
136
148
|
!%w(mn mi).include?(prec_text_elem&.name)
|
137
149
|
|
@@ -157,8 +169,8 @@ module Asciimath2UnitsML
|
|
157
169
|
|
158
170
|
def asciimath2mathml(expression)
|
159
171
|
AsciiMath::MathMLBuilder.new(:msword => true).append_expression(
|
160
|
-
AsciiMath.parse(HTMLEntities.new.decode(expression)).ast
|
161
|
-
|
172
|
+
AsciiMath.parse(HTMLEntities.new.decode(expression)).ast
|
173
|
+
).to_s.gsub(/<math>/, "<math xmlns='#{MATHML_NS}'>")
|
162
174
|
end
|
163
175
|
|
164
176
|
def embeddedmathml(mathml)
|
@@ -185,13 +197,13 @@ module Asciimath2UnitsML
|
|
185
197
|
def render_ambig_units(u)
|
186
198
|
maxcols = 0
|
187
199
|
u.each { |_, v| maxcols = v.size if maxcols < v.size }
|
188
|
-
puts %([cols="#{maxcols + 1}*"]\n|===\n|Symbol | Unit + ID #{
|
200
|
+
puts %([cols="#{maxcols + 1}*"]\n|===\n|Symbol | Unit + ID #{'| ' * (maxcols - 1)}\n)
|
189
201
|
puts "\n\n"
|
190
202
|
u.keys.sort_by { |a| [-u[a].size, a.gsub(%r{\&[^;]+;}, "")
|
191
203
|
.gsub(/[^A-Za-z]/, "").downcase] }.each do |k|
|
192
204
|
print "| #{html2adoc(k)} "
|
193
205
|
u[k].sort_by(&:size).each { |v1| print "| #{@units[v1].name}: `#{v1}` " }
|
194
|
-
puts "#{'| ' * (maxcols - u[k].size)
|
206
|
+
puts "#{'| ' * (maxcols - u[k].size)}\n"
|
195
207
|
end
|
196
208
|
puts "|===\n"
|
197
209
|
end
|
@@ -7,7 +7,8 @@ module Asciimath2UnitsML
|
|
7
7
|
when :nospace
|
8
8
|
{ html: "", mathml: "<mo>⁢</mo>" }
|
9
9
|
else
|
10
|
-
{ html: HTMLEntities.new.encode(x),
|
10
|
+
{ html: HTMLEntities.new.encode(x),
|
11
|
+
mathml: "<mo>#{HTMLEntities.new.encode(x)}</mo>" }
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -15,18 +16,21 @@ module Asciimath2UnitsML
|
|
15
16
|
@symbols[unit][style] || unit
|
16
17
|
end
|
17
18
|
|
18
|
-
def htmlent(
|
19
|
-
HTMLEntities.new.decode(
|
20
|
-
|
19
|
+
def htmlent(xml)
|
20
|
+
HTMLEntities.new.decode(xml).split(/([<>&])/).map do |c|
|
21
|
+
/[<>'"]/.match?(c) ? c : HTMLEntities.new.encode(c, :hexadecimal)
|
22
|
+
end.join
|
21
23
|
end
|
22
24
|
|
23
25
|
def htmlsymbol(units, normalise)
|
24
26
|
units.map do |u|
|
25
|
-
if u[:multiplier]
|
27
|
+
if u[:multiplier]
|
28
|
+
u[:multiplier] == "*" ? @multiplier[:html] : u[:multiplier]
|
26
29
|
elsif u[:unit].nil? && u[:prefix]
|
27
30
|
@prefixes[u[:prefix]].html
|
28
31
|
else
|
29
|
-
base = (u[:prefix] || "") +
|
32
|
+
base = (u[:prefix] || "") +
|
33
|
+
render(normalise ? @units[u[:unit]].symbolid : u[:unit], :html)
|
30
34
|
htmlsymbol_exponent(u, base)
|
31
35
|
end
|
32
36
|
end.join("")
|
@@ -36,7 +40,7 @@ module Asciimath2UnitsML
|
|
36
40
|
if u[:display_exponent] == "0.5"
|
37
41
|
base = "√#{base}"
|
38
42
|
elsif u[:display_exponent]
|
39
|
-
exp = "<sup>#{u[:display_exponent].sub(/-/,
|
43
|
+
exp = "<sup>#{u[:display_exponent].sub(/-/, '−')}</sup>"
|
40
44
|
base += exp
|
41
45
|
end
|
42
46
|
base
|
@@ -44,8 +48,9 @@ module Asciimath2UnitsML
|
|
44
48
|
|
45
49
|
def mathmlsymbol(units, normalise, multiplier = nil)
|
46
50
|
multiplier = multiplier ? "<mo>#{multiplier}</mo>" : @multiplier[:mathml]
|
47
|
-
|
48
|
-
if u[:multiplier]
|
51
|
+
units.map do |u|
|
52
|
+
if u[:multiplier]
|
53
|
+
u[:multiplier] == "*" ? multiplier : "<mo>#{u[:multiplier]}</mo>"
|
49
54
|
elsif u[:unit].nil? && u[:prefix]
|
50
55
|
%(<mi mathvariant='normal'>#{htmlent(@prefixes[u[:prefix]].html)}</mi>)
|
51
56
|
else
|
@@ -65,20 +70,21 @@ module Asciimath2UnitsML
|
|
65
70
|
mathmlsymbol_exponent(u, base)
|
66
71
|
end
|
67
72
|
|
68
|
-
def mathmlsymbol_exponent(
|
69
|
-
if
|
73
|
+
def mathmlsymbol_exponent(unit, base)
|
74
|
+
if unit[:display_exponent] == "0.5"
|
70
75
|
base = "<msqrt>#{base}</msqrt>"
|
71
|
-
elsif
|
72
|
-
exp = "<mn>#{
|
76
|
+
elsif unit[:display_exponent]
|
77
|
+
exp = "<mn>#{unit[:display_exponent]}</mn>"
|
78
|
+
.sub(/<mn>-/, "<mo>−</mo><mn>")
|
73
79
|
base = "<msup><mrow>#{base}</mrow><mrow>#{exp}</mrow></msup>"
|
74
80
|
end
|
75
81
|
base
|
76
82
|
end
|
77
83
|
|
78
84
|
def mathmlsymbolwrap(units, normalise)
|
79
|
-
<<~
|
80
|
-
|
81
|
-
|
85
|
+
<<~XML
|
86
|
+
<math xmlns='#{MATHML_NS}'><mrow>#{mathmlsymbol(units, normalise)}</mrow></math>
|
87
|
+
XML
|
82
88
|
end
|
83
89
|
end
|
84
90
|
end
|
@@ -12,16 +12,17 @@ module Asciimath2UnitsML
|
|
12
12
|
|
13
13
|
def unit(units, origtext, normtext, dims, name)
|
14
14
|
return if units_only(units).any? { |x| x[:unit].nil? }
|
15
|
+
|
15
16
|
dimid = dim_id(dims)
|
16
17
|
norm_units = normalise_units(units)
|
17
|
-
<<~
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
<<~XML
|
19
|
+
<Unit xmlns='#{UNITSML_NS}' xml:id='#{unit_id(normtext)}'#{dimid ? " dimensionURL='##{dimid}'" : ""}>
|
20
|
+
#{unitsystem(units)}
|
21
|
+
#{unitname(norm_units, normtext, name)}
|
22
|
+
#{unitsymbol(norm_units)}
|
23
|
+
#{rootunits(units)}
|
24
|
+
</Unit>
|
25
|
+
XML
|
25
26
|
end
|
26
27
|
|
27
28
|
def normalise_units(units)
|
@@ -36,6 +37,7 @@ module Asciimath2UnitsML
|
|
36
37
|
# kg exception
|
37
38
|
def unitsystem(units)
|
38
39
|
return if units_only(units).any? { |x| x[:unit].nil? }
|
40
|
+
|
39
41
|
ret = []
|
40
42
|
units = units_only(units)
|
41
43
|
units.any? { |x| @units[x[:unit]].system_name != "SI" } and
|
@@ -43,7 +45,7 @@ module Asciimath2UnitsML
|
|
43
45
|
if units.any? { |x| @units[x[:unit]].system_name == "SI" }
|
44
46
|
base = units.size == 1 && @units[units[0][:unit]].system_type == "SI-base"
|
45
47
|
base = true if units.size == 1 && units[0][:unit] == "g" && units[0][:prefix] == "k"
|
46
|
-
ret << "<UnitSystem name='SI' type='#{base ?
|
48
|
+
ret << "<UnitSystem name='SI' type='#{base ? 'SI_base' : 'SI_derived'}' xml:lang='en-US'/>"
|
47
49
|
end
|
48
50
|
ret.join("\n")
|
49
51
|
end
|
@@ -59,23 +61,25 @@ module Asciimath2UnitsML
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def unitsymbol(units)
|
62
|
-
<<~
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
<<~XML
|
65
|
+
<UnitSymbol type="HTML">#{htmlsymbol(units, true)}</UnitSymbol>
|
66
|
+
<UnitSymbol type="MathML">#{mathmlsymbolwrap(units, true)}</UnitSymbol>
|
67
|
+
XML
|
66
68
|
end
|
67
69
|
|
68
70
|
def rootunits(units)
|
69
71
|
return if units_only(units).any? { |x| x[:unit].nil? }
|
70
72
|
return if units.size == 1 && !units[0][:prefix]
|
73
|
+
|
71
74
|
exp = units_only(units).map do |u|
|
72
75
|
prefix = " prefix='#{u[:prefix]}'" if u[:prefix]
|
73
|
-
|
76
|
+
u[:exponent] && u[:exponent] != "1" and
|
77
|
+
exponent = " powerNumerator='#{u[:exponent]}'"
|
74
78
|
"<EnumeratedRootUnit unit='#{@units[u[:unit]].name}'#{prefix}#{exponent}/>"
|
75
79
|
end.join("\n")
|
76
|
-
<<~
|
77
|
-
|
78
|
-
|
80
|
+
<<~XML
|
81
|
+
<RootUnits>#{exp}</RootUnits>
|
82
|
+
XML
|
79
83
|
end
|
80
84
|
end
|
81
85
|
end
|