= asciimath2unitsml
Convert Units expressions via MathML to UnitsML

This gem converts 
MathML incorporating UnitsML expressions (based on the Ascii representation provided by NIST)
into MathML complying with https://www.w3.org/TR/mathml-units/[], with
UnitsML markup embedded in it, and with unique identifiers for each distinct unit and dimension. 
Units expressions are identified in MathML as `<mtext>unitsml(...)</mtext>`, which in turn
can be identified in AsciiMath  as `"unitsml(...)"`. 
The consuming document is meant to deduplicate the instances of UnitsML markup
with the same identifier, and potentially remove them to elsewhere in the document
or another document.

The conventions used for writing units are:

* `^` for exponents, e.g. `m^-2`
* `*` to combine two units by multiplication; e.g. `m*s^-2`. Division is not supported, use negative exponents instead
* `u` for μ (micro-)

The gem follows the MathML Units convention of inserting a spacing invisible times operator
(`<mo rspace='thickmathspace'>&#x2062;</mo>`) between any numbers (`<mn>`) and unit expressions
in MathML, and representing units in MathML as non-italic variables (`<mi mathvariant='normal'>`).

So:

[source]
----
9 "unitsml(C^3*A)"
----

is converted into:

[source,xml]
----
<math xmlns='http://www.w3.org/1998/Math/MathML'>
  <mrow>
    <mn>9</mn>
         <mo rspace='thickmathspace'>&#x2062;</mo>
         <mrow xref='U_C3.A'>
           <msup>
             <mrow>
               <mi mathvariant='normal'>C</mi>
             </mrow>
             <mrow>
               <mn>3</mn>
             </mrow>
           </msup>
           <mo>&#xB7;</mo>
           <mi mathvariant='normal'>A</mi>
         </mrow>

         <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_C3.A' dimensionURL='#D_T3I4'>
           <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
           <UnitName xml:lang='en'>C^3*A</UnitName>
           <UnitSymbol type='HTML'>C<sup>3</sup> &#xB7; A</UnitSymbol>
           <UnitSymbol type='MathML'>
             <math xmlns='http://www.w3.org/1998/Math/MathML'>
               <mrow>
                 <msup>
                   <mrow>
                     <mi mathvariant='normal'>C</mi>
                   </mrow>
                   <mrow>
                     <mn>3</mn>
                   </mrow>
                 </msup>
                 <mo>&#xB7;</mo>
                 <mi mathvariant='normal'>A</mi>
               </mrow>
             </math>
           </UnitSymbol>
           <RootUnits>
             <EnumeratedRootUnit unit='coulomb' powerNumerator='3'/>
             <EnumeratedRootUnit unit='ampere'/>
           </RootUnits>
         </Unit>
         <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_T3I4'>
           <Time symbol='T' powerNumerator='3'/>
           <ElectricCurrent symbol='I' powerNumerator='4'/>
         </Dimension>

  </mrow>
</math>
----

The converter is run as:

[source,ruby]
----
c = Asciimath2UnitsML::Conv.new()
c.Asciimath2UnitsML({Asciimath string containing "unitsml()"})
c.MathML2UnitsML({Nokogiri parse of MathML document containing <mtext>unitsml()</mtext>})
----

The converter class may be initialised with options:

* `multiplier` is the symbol used to represent the multiplication of units. By default,
following MathML Units, the symbol is middle dot (`&#xB7`). An arbitrary UTF-8 string can be
supplied instead; it will be encoded as XML entities. The value `:space` is rendered
as a spacing invisible times in MathML (`<mo rspace='thickmathspace'>&#x2062;</mo>`),
and as a non-breaking space in HTML. The value `:nospace` is rendered as a non-spacing
invisible times in MathML (`<mo>&#x2062;</mo>`), and is not rendered in HTML.