Skip to main content
Logo image

Section 25 Units of Measure

View Source for section
<section label="section-units-measure">
  <title>Units of Measure</title>
  <p>
    Units of measure can be given xml treatment too with the <c>quantity</c> element.
    In <latex />, the <c>siunitx</c>
        <idx><h>siunitx package</h></idx>
        <idx><h>package</h><h>siunitx</h></idx>
        <idx><h>units</h></idx>
    package is loaded to achive unit handling.
    Since that package only offers SI units,
    some other common units will be added by <pretext /> in the preamble.
    In HTML, the capabilities of <c>siunitx</c> are simulated, weakly.
    Note that at present,
    you should not attempt to use the <c>quantity</c> element within a math environment.
  </p>
  <p>
    The value of gravitational constant <m>g</m> is
    <quantity>
      <mag>9.8</mag><unit base="meter" /><per base="second" exp="2" />
    </quantity>.
    Force is measured in
    <quantity>
      <unit prefix="kilo" base="gram" /><unit base="meter" /><per base="second" exp="2" />
    </quantity>, also known as one
    <quantity>
      <unit base="newton" />
    </quantity>.
    A quantity with rather ridiculous units is
    <quantity>
      <mag>23</mag><unit prefix="micro" base="hectare" exp="23" /><per base="degreeCelsius" /><per base="second" exp="2" />
    </quantity>.
    One
    <quantity>
      <unit base="hertz" />
    </quantity>
    is the same as
    <quantity>
      <per base="second" />
    </quantity>.
    You can have a unitless quantity, like
    <quantity>
      <mag>42</mag>
    </quantity>, which may help with consistency between such numbers and units in the <latex /> output.
    Some non-SI units are available, such as the absurd
    <quantity>
      <unit base="degreeFahrenheit" /><unit base="foot" /><unit base="pound" /><per base="gallon" />
    </quantity>.
    The <latex /> command <c>\pi</c> is recognized within <c>mag</c> in conversions to HTML, which is consistent with the behavior with a conversion to <latex />, for example there are
    <quantity>
      <mag>2\pi</mag> <unit base="radian" />
    </quantity>
    in a full circle.
    This is a similar quantity with multiple occurences of <c>\pi</c> to test a particular template used for HTML output.
    It is not meant to make any sense:
    <quantity>
      <mag>21\pi45\pi234\pi890</mag> <unit base="radian" />
    </quantity>.
  </p>
  <p>
    For a full list of the allowed units and prefixes,
    see <c>pretext-units.xsl</c>.
    If you have a need for more units,
    they need to be added to <c>pretext-units.xsl</c> in the section that deals with units which are not part of <c>siunitx</c> by default.
    Note that the <c>mag</c> element should come first,
    followed by the <c>unit</c> element,
    followed by the <c>per</c> element.
  </p>
</section>
Units of measure can be given xml treatment too with the quantity element. In , the siunitx package is loaded to achive unit handling. Since that package only offers SI units, some other common units will be added by PreTeXt in the preamble. In HTML, the capabilities of siunitx are simulated, weakly. Note that at present, you should not attempt to use the quantity element within a math environment.
The value of gravitational constant \(g\) is 9.8 ms2. Force is measured in kg·ms2, also known as one N. A quantity with rather ridiculous units is 23 µha23°C·s2. One Hz is the same as 1s. You can have a unitless quantity, like 42, which may help with consistency between such numbers and units in the output. Some non-SI units are available, such as the absurd °F·ft·lbgal. The command \pi is recognized within mag in conversions to HTML, which is consistent with the behavior with a conversion to , for example there are 2\(\pi\) rad in a full circle. This is a similar quantity with multiple occurences of \pi to test a particular template used for HTML output. It is not meant to make any sense: 21\(\pi\)45\(\pi\)234\(\pi\)890 rad.
For a full list of the allowed units and prefixes, see pretext-units.xsl. If you have a need for more units, they need to be added to pretext-units.xsl in the section that deals with units which are not part of siunitx by default. Note that the mag element should come first, followed by the unit element, followed by the per element.