Difference between revisions of "Units"

From Wiki
Jump to navigation Jump to search
m
(One intermediate revision by one other user not shown)
Line 56: Line 56:
  
 
External link:  
 
External link:  
[[https://www.easyunitconverter.com/]]
+
[[https://www.easyunitconverter.com/ Easy Unit Converter]]
  
 
* Prefixes: <cmd>Atto</cmd> a, <cmd>Femto</cmd> f, <cmd>Pico</cmd> p, <cmd>Nano</cmd> n, <cmd>Micro</cmd> μ, <cmd>Milli</cmd> m, <cmd>Centi</cmd> c, <cmd>Deci</cmd> d, <cmd>Hecto</cmd> h, <cmd>Kilo</cmd> k, <cmd>Mega</cmd> M, <cmd>Giga</cmd> G, <cmd>Tera</cmd> T, <cmd>Peta</cmd> P, <cmd>Exa</cmd> E (missing: <cmd>Zetta</cmd> Z, <cmd>Yotta</cmd> Y, <cmd>Zepto</cmd> z, <cmd>Yocto</cmd> y)
 
* Prefixes: <cmd>Atto</cmd> a, <cmd>Femto</cmd> f, <cmd>Pico</cmd> p, <cmd>Nano</cmd> n, <cmd>Micro</cmd> μ, <cmd>Milli</cmd> m, <cmd>Centi</cmd> c, <cmd>Deci</cmd> d, <cmd>Hecto</cmd> h, <cmd>Kilo</cmd> k, <cmd>Mega</cmd> M, <cmd>Giga</cmd> G, <cmd>Tera</cmd> T, <cmd>Peta</cmd> P, <cmd>Exa</cmd> E (missing: <cmd>Zetta</cmd> Z, <cmd>Yotta</cmd> Y, <cmd>Zepto</cmd> z, <cmd>Yocto</cmd> y)
Line 100: Line 100:
 
\unit{123.22e-3 km/s}
 
\unit{123.22e-3 km/s}
 
</texcode>
 
</texcode>
 +
 +
ConTeXt will take care of spacing and formatting. The parser is fairly flexible, and the following all work and give the same output.
 +
 +
{|
 +
! width="45%"|
 +
! width="10%"|
 +
! width="45%"|
 +
|-
 +
| <texcode>
 +
\unit{10 kg}
 +
\unit{10kg}
 +
\unit{10 kilo gram}
 +
\unit{10 kilogram}
 +
\unit{10 Kilo Gram}
 +
\unit{10 KiloGram}
 +
</texcode>
 +
|
 +
|<context mode=mkiv>
 +
\starttext
 +
\startlines
 +
\unit{10 kg}
 +
\unit{10kg}
 +
\unit{10 kilo gram}
 +
\unit{10 kilogram}
 +
\unit{10 Kilo Gram}
 +
\unit{10 KiloGram}
 +
\stoplines
 +
\stoptext
 +
</context>
 +
|}
  
 
The command works in text as well as in math mode and spaces are normally ignored. You can define your own command:  
 
The command works in text as well as in math mode and spaces are normally ignored. You can define your own command:  

Revision as of 16:33, 28 May 2020

< Math Physics >

The units module comes with ConTeXt's default distribution, and can be accessed via \usemodule[units].

However, in MkIV we have integrated an upgrade to this mechanism so if you're using that version you might want to skip this first part.

Additional documentation about units in MkIV is available from the [Units manual]

The following is copied from the source file m-units.tex and only slightly modified:


  • Scientific units can be typeset in math mode pretty well, but occasionally one has to take care of spacing.

Furthermore, entering these units is not that natural as wanted. Therefore this module presents a more natural way of doing things, like:

\usemodule[units]
1.23 \Cubic \Meter \Per \Second

This example shows that we use the order in which we say things, instead of typeset things. There is no dedicated manual for this module, but an article (in dutch) has been published in [Maps#21], the journal of the NTG.


  • This runtime loadable module implements a way of defining units. The core macro is \dimension, a rather clever one that is able to cooperate with some other dimension related macros. As said, this module enables user to enter:
\usemodule[units]
Some 10 \Square \Meter \Per \Second\ or more.

(Note that the space after \Second needs to be explicitly specified; otherwise, it will get eaten.)


  • Units act upon signals that they insert in the text, in case no quantity is given you need to start the unit sequence using \Unit
\usemodule[units]
Units of measurement is \Unit \Milli \Meter

The units itself are implemented as synonyms.

\definesynonyms [unit] [units] [\unitmeaning]
\setupsynonyms [unit] [textstyle=\dimension]

This definition means that we can ask for the meaning of a unit using \unitmeaning and get a list of used units by saying \placelistofunits.

We have to use the command \unitmeaning instead of \meaning, simply because the latter is a TeX primitive we don't want to lose. We use the label text mechanism for translations.


Macros defined in units

External link: [Easy Unit Converter]

Define a new unit

\usemodule[units]
\unit[Mynewunit]{Nu}{New Unit}

10 \Mynewunit

Using the built-in command

In MkIV you can use the built-in \unit command. This time we don't use commands, if only because it is somewhat cumbersome. Let's give a few examples:

10 \unit{km/h}
\unit{10 km/h}
\unit{~1 km/h}
\unit{KiloMeter/Hour}
\unit{10 cubic meter / second}
\unit{kilo pascal square meter / second}
\unit{kilo pascal square meter / kelvin second }$
\unit{10 AC}
$\frac{10 \unit{m/s}}{20 \unit{m/s}}$
{\ss 30 \unit{kilo pascal square meter / second kelvin}}
\unit{123.22^-3 km/s}
\unit{123.22e-3 km/s}

ConTeXt will take care of spacing and formatting. The parser is fairly flexible, and the following all work and give the same output.

\unit{10 kg}
\unit{10kg}
\unit{10 kilo gram}
\unit{10 kilogram}
\unit{10 Kilo Gram}
\unit{10 KiloGram}

The command works in text as well as in math mode and spaces are normally ignored. You can define your own command:

\defineunits[un][alternative=text,separator=medium]

Valid separators are cdot, big, medium, and space with the first being the default. You can later tune the rendering with

\setupunits[un][separator=cdot]

In due time there will be a few more options. Numbers are formatted cf the digits mechanism (not discussed here).