Difference between revisions of "Command/ unit"

From Wiki
Jump to navigation Jump to search
Tags: Mobile web edit Mobile edit
 
Line 1: Line 1:
<?xml version='1.0'?>
 
<!-- this file was generated on 2020-08-20T09:05 -->
 
 
<cd:commandgroup generated="yes" name="unit" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807">
 
<cd:commandgroup generated="yes" name="unit" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807">
<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 typesetting physical units.
 
The instances of  <tt>\<i>unit</i></tt> are used for typesetting physical units.
 
</cd:shortdesc>
 
</cd:shortdesc>
Line 19: Line 16:
 
   </cd:command>
 
   </cd:command>
 
</cd:variants>
 
</cd:variants>
<cd:description>
+
<cd:description>The {{cmd|unit}} command typesets physical units, with or without 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 {{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.
 
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.
Line 46: Line 42:
  
 
</cd:description>
 
</cd:description>
<cd:examples>
+
<cd:examples><cd:example title="">Various ways to write a unit:
<cd:example title="">
 
Various ways to write a unit:
 
 
<context source="yes">
 
<context source="yes">
 
\startlines
 
\startlines
Line 65: Line 59:
 
\stoplines
 
\stoplines
 
</context>
 
</context>
</cd:example>
+
</cd:example><cd:example title="">Units automatically have a space put in front of them.
<cd:example title="">
 
Units automatically have a space put in front of them.
 
 
<context source="yes">
 
<context source="yes">
 
[\unit{micro ohm}]\par    %  space before unit
 
[\unit{micro ohm}]\par    %  space before unit
Line 75: Line 67:
 
[\unit{10 micro ohm}]\par %  space before unit
 
[\unit{10 micro ohm}]\par %  space before unit
 
</context>
 
</context>
</cd:example>
+
</cd:example><cd:example title="">There are various ways put separators in numbers:
<cd:example title="">
 
There are various ways put separators in numbers:
 
 
<context source="yes">
 
<context source="yes">
 
\starttabulate[|l|l|l|]
 
\starttabulate[|l|l|l|]
Line 97: Line 87:
 
\stoptabulate
 
\stoptabulate
 
</context>
 
</context>
</cd:example>
+
</cd:example><cd:example title="">Since mid-May 2020 it is possible to directly input ranges or measures of uncertainty in {{cmd|unit}}:
<cd:example title="">
 
Since mid-May 2020 it is possible to directly input ranges or measures of uncertainty in {{cmd|unit}}:
 
 
<context source="yes">
 
<context source="yes">
 
\startlines
 
\startlines
Line 131: Line 119:
 
</context>
 
</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="[[User:Taco|Taco]] ([[User talk:Taco|talk]])" date="12:35, 21 August 2020 (CEST)">
</cd:note>
+
The last example (&squo;unitless&squo;) does not work with 20200630 LMTX.
</cd:notes>
+
 
 +
</cd:note></cd:notes>
 
<cd:seealso>
 
<cd:seealso>
<!-- one or more of these:
 
<cd:commandref name="xx"></cd:commandref>
 
<cd:wikipage  page="xx"></cd:wikipage>
 
<cd:url        url="https://xx"></cd:url>
 
<cd:manual    pdf="xx"></cd:manual>
 
<cd:source    file="xx"></cd:source>
 
-->
 
 
<cd:commandref name="defineunit" originator="system"></cd:commandref>
 
<cd:commandref name="defineunit" originator="system"></cd:commandref>
 
<cd:commandref name="setupunit" originator="system"></cd:commandref>
 
<cd:commandref name="setupunit" originator="system"></cd:commandref>
<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="digits"></cd:commandref>
 
<cd:commandref name="registerunit"></cd:commandref>
 
<cd:commandref name="registerunit"></cd:commandref>
<cd:commandref name="setupunittext"></cd:commandref>
+
<cd:commandref name="setupunittext"></cd:commandref></cd:seealso>
</cd:seealso>
 
 
</cd:commandgroup>
 
</cd:commandgroup>

Latest revision as of 16:11, 3 June 2023


\unit

Summary

The instances of \unit are used for typesetting physical units.

Instances

\unit

Settings instance

\UNIT{...}
{...}content

OptionExplanation
{...} See #Description for content specification

Description

The \unit command typesets physical units, with or without 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

  • By Taco (talk) on 12:35, 21 August 2020 (CEST):
The last example ('unitless') does not work with 20200630 LMTX.

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: