Skip to main content

The PreTeXt Guide

Section 4.35 Units of Measure

This section expands on Section 3.29. A physical quantity is authored with the <quantity> element, so that PreTeXt can typeset the magnitude and its units consistently—with correct spacing and upright symbols—in every output format. Authoring units this way, rather than as ordinary text or as mathematics, also lets them migrate correctly to print, HTML, and braille.

Subsection 4.35.1 Building a Quantity

A <quantity> holds at most one <mag> (its magnitude, a number), followed by any number of <unit> and <per> elements. A <unit> contributes a factor to the numerator and a <per> a factor to the denominator. Each requires a @base (such as meter or gram), and may add a @prefix (such as kilo or micro) and an integer @exp for a power.
<quantity>
    <mag>9.8</mag>
    <unit base="meter"/>
    <per base="second" exp="2"/>
</quantity>
This renders as 9.8 ms2. Every part is optional and independent. A <quantity> may be unitless, holding only a <mag>, which helps keep a plain number typographically consistent with neighboring quantities that do carry units. It may equally have units but no magnitude, as when a table explains what a unit means (a natural use within a <tabular>, see Section 4.19).
The content of a <mag> may include simple syntax, so a magnitude such as 2\pi is recognized and rendered consistently in both and HTML output. See Section 4.9 for more on authoring mathematics.

Subsection 4.35.2 Prefixes and Base Units

The @prefix and @base attributes draw on a fixed, extensive vocabulary. The prefixes are the full range of SI multipliers, from yocto through yotta. The bases include the SI base and derived units—among them meter, gram, second, ampere, kelvin, mole, candela, newton, pascal, joule, watt, hertz, and radian—together with a selection of non-SI and customary units such as minute, hour, degreeCelsius, degreeFahrenheit, foot, pound, and gallon.
Because this vocabulary is large, and is revised from time to time, we do not reproduce it in full here. A prefix or base that PreTeXt does not recognize is reported to you when you process your document, so the safest course is to try the unit you have in mind.