asciimath2unitsml 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciimath2unitsml/parse.rb +5 -5
- data/lib/asciimath2unitsml/version.rb +1 -1
- data/lib/unitsdb/units.yaml +2 -2
- data/spec/conv_spec.rb +62 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2279898112af9b3602b0f7ed1a713adc4130015a3f616767d364952fb87b8ff
|
4
|
+
data.tar.gz: 2bf900fe40159a836fed5bbbcdc7f76c7911083242e12962949b269fafe2e92d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d3c8c4ca3db1208f5764ddd0cf2ab221548dceb3ac99d69a14778bd05dc4aec07a54064ae408908aacf27f5dbdd456fbca6eb42f29cc626527d518f03ae831f
|
7
|
+
data.tar.gz: 3b1d4a11f5db9225b20802ab261ba67099f977a66af680a1aaa19ffe2fdb6f6bbf78f0088f5473fe7b1e23083a72a32f9e130a9fe71abe240f9f306610bdef64
|
@@ -156,16 +156,16 @@ module Asciimath2UnitsML
|
|
156
156
|
text = x.text.sub(%r{^unitsml\((.+)\)$}m, "\\1")
|
157
157
|
units, origtext, normtext, quantity, name, symbol = parse(text)
|
158
158
|
rendering = symbol ? embeddedmathml(asciimath2mathml(symbol)) : mathmlsymbol(units, false)
|
159
|
-
|
160
|
-
x.replace("#{delim}<mrow xref='#{unit_id(origtext)}'>#{rendering}</mrow>\n"\
|
159
|
+
x.replace("#{delimspace(rendering, x)}<mrow xref='#{unit_id(origtext)}'>#{rendering}</mrow>\n"\
|
161
160
|
"#{unitsml(units, origtext, normtext, quantity, name)}")
|
162
161
|
end
|
163
162
|
dedup_ids(xml)
|
164
163
|
end
|
165
164
|
|
166
|
-
def delimspace(
|
167
|
-
|
168
|
-
|
165
|
+
def delimspace(rendering, elem)
|
166
|
+
return "" if elem&.previous_element && elem&.previous_element.name != "mn"
|
167
|
+
text = HTMLEntities.new.encode(Nokogiri::XML("<mrow>#{rendering}</mrow>").text.strip)
|
168
|
+
/\p{L}|\p{N}/.match(text) ?
|
169
169
|
"<mo rspace='thickmathspace'>⁢</mo>" : "<mo>⁢</mo>"
|
170
170
|
end
|
171
171
|
|
data/lib/unitsdb/units.yaml
CHANGED
@@ -4340,8 +4340,8 @@
|
|
4340
4340
|
unit_symbols:
|
4341
4341
|
- id: "deg"
|
4342
4342
|
ascii: "deg"
|
4343
|
-
html: "&#
|
4344
|
-
mathml: "<mi mathvariant='normal'>&#
|
4343
|
+
html: "°"
|
4344
|
+
mathml: "<mi mathvariant='normal'>°</mi>"
|
4345
4345
|
latex: \ensuremath{\mathrm{^{\circ}}}
|
4346
4346
|
unicode: "º"
|
4347
4347
|
root_units:
|
data/spec/conv_spec.rb
CHANGED
@@ -106,7 +106,7 @@ RSpec.describe Asciimath2UnitsML do
|
|
106
106
|
OUTPUT
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
it "does not insert space before non-alphabetic units" do
|
110
110
|
expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
|
111
111
|
1 "unitsml(degK)" + 1 "unitsml(prime)"
|
112
112
|
INPUT
|
@@ -163,6 +163,67 @@ INPUT
|
|
163
163
|
OUTPUT
|
164
164
|
end
|
165
165
|
|
166
|
+
it "does not insert space before operators" do
|
167
|
+
expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
|
168
|
+
8 "unitsml(kg)" cdot "unitsml(m)"
|
169
|
+
INPUT
|
170
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML'>
|
171
|
+
<mn>8</mn>
|
172
|
+
<mo rspace='thickmathspace'>⁢</mo>
|
173
|
+
<mrow xref='U_NISTu2'>
|
174
|
+
<mi mathvariant='normal'>kg</mi>
|
175
|
+
</mrow>
|
176
|
+
<Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu2' dimensionURL='#NISTd2'>
|
177
|
+
<UnitSystem name='SI' type='SI_base' xml:lang='en-US'/>
|
178
|
+
<UnitName xml:lang='en'>kilogram</UnitName>
|
179
|
+
<UnitSymbol type='HTML'>kg</UnitSymbol>
|
180
|
+
<UnitSymbol type='MathML'>
|
181
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML'>
|
182
|
+
<mrow>
|
183
|
+
<mi mathvariant='normal'>kg</mi>
|
184
|
+
</mrow>
|
185
|
+
</math>
|
186
|
+
</UnitSymbol>
|
187
|
+
<RootUnits>
|
188
|
+
<EnumeratedRootUnit unit='gram' prefix='k'/>
|
189
|
+
</RootUnits>
|
190
|
+
</Unit>
|
191
|
+
<Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
|
192
|
+
<PrefixName xml:lang='en'>kilo</PrefixName>
|
193
|
+
<PrefixSymbol type='ASCII'>k</PrefixSymbol>
|
194
|
+
<PrefixSymbol type='unicode'>k</PrefixSymbol>
|
195
|
+
<PrefixSymbol type='LaTeX'>k</PrefixSymbol>
|
196
|
+
<PrefixSymbol type='HTML'>k</PrefixSymbol>
|
197
|
+
</Prefix>
|
198
|
+
<Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd2'>
|
199
|
+
<Mass symbol='M' powerNumerator='1'/>
|
200
|
+
</Dimension>
|
201
|
+
<Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq2' dimensionURL='#NISTd2' quantityType='base'>
|
202
|
+
<QuantityName xml:lang='en-US'>mass</QuantityName>
|
203
|
+
</Quantity>
|
204
|
+
<mo>⋅</mo>
|
205
|
+
<mrow xref='U_NISTu1'>
|
206
|
+
<mi mathvariant='normal'>m</mi>
|
207
|
+
</mrow>
|
208
|
+
<Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu1' dimensionURL='#NISTd1'>
|
209
|
+
<UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
|
210
|
+
<UnitName xml:lang='en'>meter</UnitName>
|
211
|
+
<UnitSymbol type='HTML'>m</UnitSymbol>
|
212
|
+
<UnitSymbol type='MathML'>
|
213
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML'>
|
214
|
+
<mrow>
|
215
|
+
<mi mathvariant='normal'>m</mi>
|
216
|
+
</mrow>
|
217
|
+
</math>
|
218
|
+
</UnitSymbol>
|
219
|
+
</Unit>
|
220
|
+
<Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd1'>
|
221
|
+
<Length symbol='L' powerNumerator='1'/>
|
222
|
+
</Dimension>
|
223
|
+
</math>
|
224
|
+
OUTPUT
|
225
|
+
end
|
226
|
+
|
166
227
|
it "deals with sqrt units" do
|
167
228
|
expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
|
168
229
|
1 "unitsml(sqrt(Hz))"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciimath2unitsml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciimath
|