asciimath2unitsml 0.2.3 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 161503157f4b3622c8bcae6ece418ed5f675a95f409d60017287017c923f7749
4
- data.tar.gz: 48571d4a30ea4ade2f864178dcb473c9a636d71d5088b64a2356e3cbfa5f2886
3
+ metadata.gz: a2279898112af9b3602b0f7ed1a713adc4130015a3f616767d364952fb87b8ff
4
+ data.tar.gz: 2bf900fe40159a836fed5bbbcdc7f76c7911083242e12962949b269fafe2e92d
5
5
  SHA512:
6
- metadata.gz: a50f75b036f2a19dcd1925965f192d1652ddabc242ce22c33efcfaf0d03c0ee5118c46021f22ee02237f93e5e32492c922466fd7f3206a20713c7a2bf749e6ef
7
- data.tar.gz: 279f88fb13d2ed6961b42fec192312b52b82d993daf4efa2750de21b2e240b2b63702d82dac831e4dc3a0b86bd6b797cbbca057809d4c971eb27bf71548f9010
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
- delim = x&.previous_element ? delimspace(rendering) : ""
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(x)
167
- text = HTMLEntities.new.encode(Nokogiri::XML("<mrow>#{x}</mrow>").text.strip)
168
- /[[:alnum:]]/.match(text) ?
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'>&#x2062;</mo>" : "<mo>&#x2062;</mo>"
170
170
  end
171
171
 
@@ -1,3 +1,3 @@
1
1
  module Asciimath2UnitsML
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.2.4'.freeze
3
3
  end
@@ -4340,8 +4340,8 @@
4340
4340
  unit_symbols:
4341
4341
  - id: "deg"
4342
4342
  ascii: "deg"
4343
- html: "&#186;"
4344
- mathml: "<mi mathvariant='normal'>&#186;</mi>"
4343
+ html: "&#176;"
4344
+ mathml: "<mi mathvariant='normal'>&#176;</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
- it "does not insert space before non-alphabetic units" do
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'>&#x2062;</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>&#x22C5;</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.3
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-16 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath