units.sty
-- Josselin
units.sty, SIunits.sty
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
units.sty solved the problem of italicizing units, but it did not
solve the problem of spacing. To clarify, sometimes my units consist
of an SI unit and the name of a chemical compound and I need a space
between the name of the compound and the chemical compound (for
example, "mol NaOH"). Any suggestions?
Well, that has not clarified things. What did you type, what did you
get, and what did you want to get?
I think to \unit[1.0]{mol NaOH} give space between mol and NaOH, but
bigger space than between 1.0 and mol.
Using SIunits, you can control the space between value and unit, and
in between compound units. If you want equal spacing, this should work
\usepackage[thinqspace,thinspace]{SIunits}
\unit{1.0}{\mole \usk NaOH}
The problem of units in latex has been raised many times. Even though
existing packages are good, I still think the most simple and elegant
solution is to define a command like this one
%% APS recommends full intra-word space between number and unit
\newcommand{\un}[1]{\ensuremath{\ \mathrm{#1}}}
Usage:
for units with roman alphabet letters, in paragraph mode, no need for
extra command:
...velocity is 30~m/s...
units with greek letters or other symbols, in paragraph mode
...resistance is 1\un{M\Omega}...
in math mode
...\( 1\un{V} = (1\un{\Omega}) \cdot (1\un{A}) \)
subscripts and superscripts have the right size
...our funky law is \( V = I^{1\un{M\Omega}} \)...
if your unit is awkward to write every time, just define a shorthand
command
\newcommand{\molNaOH}{\ensuremath{\mathrm{mol\;NaOH}}}
or similar.
Hope this is helpful.
-Giulio
> theresabo...@yahoo.com (gilbert) wrote in message news:<7eba5997.02120...@posting.google.com>...
> > I often have to write documents in LaTeX including calculations which
> > include units.
>
> The problem of units in latex has been raised many times. Even though
> existing packages are good, I still think the most simple and elegant
> solution is to define a command like this one
>
> %% APS recommends full intra-word space between number and unit
> \newcommand{\un}[1]{\ensuremath{\ \mathrm{#1}}}
Yes, I also like a command like that. Below is my favourite code for
producing units. It is based upon a posting of one of the TeX gurus a
number of years back (sorry, I've forgotten who first posted it), but I've
modified it and added my own little niceties. Usage is:
The speed of light is 2.9979\E{8}\un{m s^{-1}}.
or in its starred form:
The units of flux are~\un*{J m^{-2} s^{-1}}.
Notice the little extras of the \E{} for scientific notation and the
renaming of \deg (better duck - the LaTeX police are on the way) to be a
degree symbol (the LaTeX defn of \deg is put into \olddeg). The \un{}
command even knows the \deg command and does not put in a small space after
the number if the units are degrees.
Code follows (put into .sty file or surround with \makeatletter,
\makeatother.):
\DeclareMathSymbol{\circx}{\mathord}{symbols}{"0E}
\let\olddeg=\deg
\renewcommand\deg{\ensuremath{^\circx}}
\DeclareMathSymbol{\timesx}{\mathord}{symbols}{"02}
\newcommand{\etimes}{\mskip1.1mu\timesx\mskip0.9mu\relax}
\newcommand{\E}[1]{\ensuremath{\etimes10^{#1}}}
\newmuskip\unitmuskip
\newmuskip\unitpreskip
\unitmuskip=1mu plus 0.3mu % Change this to suit your preference
\unitpreskip=4mu plus 1mu minus 1mu % Change this to suit your preference
\def\unitmskip{\penalty10000 \mskip\unitmuskip}%
\DeclareRobustCommand\un{\@ifstar{\@unstar}{\@un}}
\newcommand\@unstar[1]{\leavevmode
\ensuremath{%
\begingroup \fam\z@
\let\,\unitmskip \unit@PreserveSpaces\@empty #1 \unit@PreserveSpaces
\endgroup}}%
\newcommand\@un[1]{\leavevmode
\unskip\penalty1000
\ensuremath{%
\@checkfordeg #1\@empty
\begingroup \fam\z@
\let\,\unitmskip \unit@PreserveSpaces\@empty #1 \unit@PreserveSpaces
\endgroup}}%
\def\unit@PreserveSpaces#1 {#1\@ifnextchar\unit@PreserveSpaces{\@gobble}%
{\unitmskip \unit@PreserveSpaces\@empty}}%
\def\@checkfordeg{\@ifnextchar\deg{\@junkrest}{\mskip\unitpreskip\@junkrest}}%
\def\@junkrest#1\@empty{}%
Michael.