Difference between revisions of "Command/ unit"
(Created page with "Documentation for \<i>unit</i>") |
|||
Line 4: | Line 4: | ||
<cd:shortdesc> | <cd:shortdesc> | ||
<!-- a short command summary goes here --> | <!-- a short command summary goes here --> | ||
− | The instances of <tt>\<i>unit</i></tt> are used for | + | The instances of <tt>\<i>unit</i></tt> are used for typesetting physical units. |
</cd:shortdesc> | </cd:shortdesc> | ||
<cd:sequence> | <cd:sequence> | ||
Line 15: | Line 15: | ||
<cd:command category="symbols" file="phys-dim.mkiv" generated="yes" interfacedate="2020-07-14T09:24" interfacefile="i-unit.xml" level="document" name="unit" variant="instance" variantnumber="1"> | <cd:command category="symbols" file="phys-dim.mkiv" generated="yes" interfacedate="2020-07-14T09:24" interfacefile="i-unit.xml" level="document" name="unit" variant="instance" variantnumber="1"> | ||
<cd:arguments> | <cd:arguments> | ||
− | <cd:content ordinal="1"></cd:content> | + | <cd:content ordinal="1">See [[#Description]] for content specification</cd:content> |
</cd:arguments> | </cd:arguments> | ||
</cd:command> | </cd:command> | ||
</cd:variants> | </cd:variants> | ||
<cd:description> | <cd:description> | ||
− | < | + | The {{cmd|unit}} command typesets physical units, with or with a number preceding them. Units and their prefixes may be spelled out or abbreviated, with or without spaces or initial capitals; this will be converted to the correct abbreviated form and typeset. Any numbers that are encountered after units are assumed to be powers; one may also write e.g. <code>squared meter</code>. Multiplication is implicit; division may be written as <code>per</code>. The font automatically adapts to the environment. |
+ | |||
+ | The number before the digits is interpreted as just that, a number. There are a few special characters you can put in to format it; most importantly, <code>e123</code> is interpreted as <code>times 10^123</code>. The <code>^{...}</code> used to be interpreted as a synonym for <code>e</code>, but nowadays (since nov 2012) it functions in the normal TeX way, namely to typeset an exponent. | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | | <code>.</code> || a decimal mark (default) or a number separator | ||
+ | | <code>:</code> || an invisible decimal separator space | ||
+ | |- | ||
+ | | <code>,</code> || a number separator (default) or a decimal mark | ||
+ | | <code>;</code> || an invisible number separator space | ||
+ | |- | ||
+ | | || | ||
+ | | <code>@</code> or <code>_</code> or <code>~</code> || a number-sized space | ||
+ | |- | ||
+ | | || | ||
+ | | <code>=</code> || an inivisible space for zero padding | ||
+ | |- | ||
+ | | <code>+</code> or <code>-</code> || a sign | ||
+ | | <code>/</code> || an invisible sign space | ||
+ | |- | ||
+ | | <code>++</code> or <code>--</code> || a high sign | ||
+ | | <code>//</code> || an invisible high sign space | ||
+ | |} | ||
+ | |||
</cd:description> | </cd:description> | ||
<cd:examples> | <cd:examples> | ||
− | |||
<cd:example title=""> | <cd:example title=""> | ||
+ | Various ways to write a unit: | ||
+ | <context source="yes"> | ||
+ | \startlines | ||
+ | 1: 10 \unit{km/h} | ||
+ | 2: 10 \unit{KiloMeter/Hour} | ||
+ | 3: 10 \unit{kilometer/hour} | ||
+ | 4: 10 \unit{kilometer per hour} | ||
+ | 5: 10 \unit{km / h} | ||
+ | 6: 10 \unit{ km / h } | ||
+ | 7: 10 \unit{km/h2} | ||
+ | 8: \unit{123.22^-3 km/s} | ||
+ | 9: \unit{123.22e-3 km/s} | ||
+ | 10: {\ss 30 \unit{kilo pascal square meter / second kelvin}} | ||
+ | 11: $\frac{10 \unit{m/s}}{20 \unit{m/s}} $ | ||
+ | 12: $\frac{\unit{10 m/s}}{\unit{20 m/s}} $ | ||
+ | \stoplines | ||
+ | </context> | ||
+ | </cd:example> | ||
+ | <cd:example title=""> | ||
+ | Units automatically have a space put in front of them. | ||
+ | <context source="yes"> | ||
+ | [\unit{micro ohm}]\par % space before unit | ||
+ | [10\unit {micro ohm}]\par % space before unit | ||
+ | [10 \unit{micro ohm}]\par % space before unit | ||
+ | [ \unit {micro ohm}]\par % space before unit | ||
+ | [\unit{10 micro ohm}]\par % space before unit | ||
+ | </context> | ||
+ | </cd:example> | ||
+ | <cd:example title=""> | ||
+ | There are various ways put separators in numbers: | ||
+ | <context source="yes"> | ||
+ | \starttabulate[|l|l|l|] | ||
+ | \HL | ||
+ | \NC \unit{10 kilo gram} \NC \digits{10} \NC \unit{10} \NC \NR | ||
+ | \NC \unit{1 kilogram} \NC \digits{1} \NC \unit{1} \NC \NR | ||
+ | \NC \unit{0.1 kilogram} \NC \digits{0.1} \NC \unit{0.1} \NC \NR | ||
+ | \NC \unit{1.1 kilogram} \NC \digits{1.1} \NC \unit{1.1} \NC \NR | ||
+ | \NC \unit{11 kilogram} \NC \digits{11} \NC \unit{11} \NC \NR | ||
+ | \HL | ||
+ | \NC \unit{00,000.10 kilogram} \NC \digits{00,000.10} \NC \unit{00,000.10} \NC \NR | ||
+ | \NC \unit{@@,@@0.10 kilogram} \NC \digits{@@,@@0.10} \NC \unit{@@,@@0.10} \NC \NR | ||
+ | \NC \unit{__,___.10 kilogram} \NC \digits{__,___.10} \NC \unit{__,___.10} \NC \NR | ||
+ | \NC \unit{__,__0:10 kilogram} \NC \digits{__,__0:10} \NC \unit{__,__0:10} \NC \NR | ||
+ | \NC \unit{__,___:10 kilogram} \NC \digits{__,___:10} \NC \unit{__,___:10} \NC \NR | ||
+ | \NC \unit{__,__0:== kilogram} \NC \digits{__,__0:==} \NC \unit{__,__0:==} \NC \NR | ||
+ | \NC \unit{__,__0.1= kilogram} \NC \digits{__,__0.1=} \NC \unit{__,__0.1=} \NC \NR % works since mid-May 2020 | ||
+ | \HL | ||
+ | \stoptabulate | ||
+ | </context> | ||
+ | </cd:example> | ||
+ | <cd:example title=""> | ||
+ | Since mid-May 2020 it is possible to directly input ranges or measures of uncertainty in {{cmd|unit}}: | ||
+ | <context source="yes"> | ||
+ | \startlines | ||
+ | \type{1 } : \unit {30^2 meter per second} | ||
+ | \type{1a} : \unit {±10} | ||
+ | \type{1b} : \unit {-10 meter per second} | ||
+ | \type{2 } : \unit {20 – 40 meter per second} % long dash! | ||
+ | \type{2a} : \unit {30 pm 10 meter per second} | ||
+ | \type{2b} : \unit {30 to 10 meter per second} | ||
+ | \type{3a} : \unit {30^2 pm 10^2 meter per second} | ||
+ | \type{3b} : \unit {30^2 to 10^2 meter per second} | ||
+ | \type{4 } : \unit {30 (10) meter per second} | ||
+ | \type{5a} : \unit {30 (pm 10) meter per second} | ||
+ | \type{5b} : \unit {30^2 (pm 10^2) meter per second} | ||
+ | \type{6a} : \unit {(30 pm 10) meter per second} | ||
+ | \type{6b} : \unit {(30^2 pm 10^2) meter per second} | ||
+ | \type{6c} : \unit {(30^2 to 10^2) meter per second} | ||
+ | \type{7a} : \unit {(30 pm 10)^2 meter per second} | ||
+ | \type{7b} : \unit {(30 to 10)e2 meter per second} | ||
+ | \type{7c} : \unit {(30e2 to 10e3)^5 meter per second} | ||
+ | \stoplines | ||
+ | </context> | ||
+ | |||
+ | The above doesn't work when no unit is specified (and neither in {{cmd|digits}}). In that case | ||
+ | <context source="yes"> | ||
+ | \registerunit[unitless=unitless] | ||
+ | \setupunittext[unitless=\strut] | ||
+ | |||
+ | \unit{10 (30) unitless}\par | ||
+ | \unit{10 ± 3 unitless} | ||
+ | </context> | ||
+ | |||
</cd:example> | </cd:example> | ||
− | |||
</cd:examples> | </cd:examples> | ||
<cd:notes> | <cd:notes> | ||
− | + | <cd:note author="[[User:Taco|Taco]] ([[User talk:Taco|talk]])" date="12:35, 21 August 2020 (CEST)">The last example ('unitless') does not work with 20200630 LMTX. | |
− | <cd:note author=" | ||
</cd:note> | </cd:note> | ||
− | |||
</cd:notes> | </cd:notes> | ||
<cd:seealso> | <cd:seealso> | ||
Line 46: | Line 149: | ||
<cd:source file="phys-dim.mkiv" originator="system"></cd:source> | <cd:source file="phys-dim.mkiv" originator="system"></cd:source> | ||
<cd:wikipage originator="system" page="Category:Symbols"></cd:wikipage> | <cd:wikipage originator="system" page="Category:Symbols"></cd:wikipage> | ||
+ | <cd:commandref name="digits"></cd:commandref> | ||
+ | <cd:commandref name="registerunit"></cd:commandref> | ||
+ | <cd:commandref name="setupunittext"></cd:commandref> | ||
</cd:seealso> | </cd:seealso> | ||
</cd:commandgroup> | </cd:commandgroup> |
Revision as of 10:37, 21 August 2020
Contents
\unit
Summary
The instances of \unit are used for typesetting physical units.
Instances
\unit |
Settings instance
Description
The \unit command typesets physical units, with or with a number preceding them. Units and their prefixes may be spelled out or abbreviated, with or without spaces or initial capitals; this will be converted to the correct abbreviated form and typeset. Any numbers that are encountered after units are assumed to be powers; one may also write e.g. squared meter
. Multiplication is implicit; division may be written as per
. The font automatically adapts to the environment.
The number before the digits is interpreted as just that, a number. There are a few special characters you can put in to format it; most importantly, e123
is interpreted as times 10^123
. The ^{...}
used to be interpreted as a synonym for e
, but nowadays (since nov 2012) it functions in the normal TeX way, namely to typeset an exponent.
. |
a decimal mark (default) or a number separator | : |
an invisible decimal separator space |
, |
a number separator (default) or a decimal mark | ; |
an invisible number separator space |
@ or _ or ~ |
a number-sized space | ||
= |
an inivisible space for zero padding | ||
+ or - |
a sign | / |
an invisible sign space |
++ or -- |
a high sign | // |
an invisible high sign space |
Examples
Example 1
Various ways to write a unit:
\startlines 1: 10 \unit{km/h} 2: 10 \unit{KiloMeter/Hour} 3: 10 \unit{kilometer/hour} 4: 10 \unit{kilometer per hour} 5: 10 \unit{km / h} 6: 10 \unit{ km / h } 7: 10 \unit{km/h2} 8: \unit{123.22^-3 km/s} 9: \unit{123.22e-3 km/s} 10: {\ss 30 \unit{kilo pascal square meter / second kelvin}} 11: $\frac{10 \unit{m/s}}{20 \unit{m/s}} $ 12: $\frac{\unit{10 m/s}}{\unit{20 m/s}} $ \stoplines
Example 2
Units automatically have a space put in front of them.
[\unit{micro ohm}]\par % space before unit [10\unit {micro ohm}]\par % space before unit [10 \unit{micro ohm}]\par % space before unit [ \unit {micro ohm}]\par % space before unit [\unit{10 micro ohm}]\par % space before unit
Example 3
There are various ways put separators in numbers:
\starttabulate[|l|l|l|] \HL \NC \unit{10 kilo gram} \NC \digits{10} \NC \unit{10} \NC \NR \NC \unit{1 kilogram} \NC \digits{1} \NC \unit{1} \NC \NR \NC \unit{0.1 kilogram} \NC \digits{0.1} \NC \unit{0.1} \NC \NR \NC \unit{1.1 kilogram} \NC \digits{1.1} \NC \unit{1.1} \NC \NR \NC \unit{11 kilogram} \NC \digits{11} \NC \unit{11} \NC \NR \HL \NC \unit{00,000.10 kilogram} \NC \digits{00,000.10} \NC \unit{00,000.10} \NC \NR \NC \unit{@@,@@0.10 kilogram} \NC \digits{@@,@@0.10} \NC \unit{@@,@@0.10} \NC \NR \NC \unit{__,___.10 kilogram} \NC \digits{__,___.10} \NC \unit{__,___.10} \NC \NR \NC \unit{__,__0:10 kilogram} \NC \digits{__,__0:10} \NC \unit{__,__0:10} \NC \NR \NC \unit{__,___:10 kilogram} \NC \digits{__,___:10} \NC \unit{__,___:10} \NC \NR \NC \unit{__,__0:== kilogram} \NC \digits{__,__0:==} \NC \unit{__,__0:==} \NC \NR \NC \unit{__,__0.1= kilogram} \NC \digits{__,__0.1=} \NC \unit{__,__0.1=} \NC \NR % works since mid-May 2020 \HL \stoptabulate
Example 4
Since mid-May 2020 it is possible to directly input ranges or measures of uncertainty in \unit:
\startlines \type{1 } : \unit {30^2 meter per second} \type{1a} : \unit {±10} \type{1b} : \unit {-10 meter per second} \type{2 } : \unit {20 – 40 meter per second} % long dash! \type{2a} : \unit {30 pm 10 meter per second} \type{2b} : \unit {30 to 10 meter per second} \type{3a} : \unit {30^2 pm 10^2 meter per second} \type{3b} : \unit {30^2 to 10^2 meter per second} \type{4 } : \unit {30 (10) meter per second} \type{5a} : \unit {30 (pm 10) meter per second} \type{5b} : \unit {30^2 (pm 10^2) meter per second} \type{6a} : \unit {(30 pm 10) meter per second} \type{6b} : \unit {(30^2 pm 10^2) meter per second} \type{6c} : \unit {(30^2 to 10^2) meter per second} \type{7a} : \unit {(30 pm 10)^2 meter per second} \type{7b} : \unit {(30 to 10)e2 meter per second} \type{7c} : \unit {(30e2 to 10e3)^5 meter per second} \stoplines
The above doesn't work when no unit is specified (and neither in \digits). In that case
\registerunit[unitless=unitless] \setupunittext[unitless=\strut] \unit{10 (30) unitless}\par \unit{10 ± 3 unitless}
Notes
- The last example ('unitless') does not work with 20200630 LMTX.