| 1 |
% \iffalse |
| 2 |
% |
| 3 |
% units.dtx |
| 4 |
% Docstrip archive, run through LaTeX. |
| 5 |
% |
| 6 |
% Copyright (C) 1998 Axel Reichert |
| 7 |
% See the files README and COPYING. |
| 8 |
% |
| 9 |
% \fi |
| 10 |
% |
| 11 |
% \CheckSum{174} |
| 12 |
% |
| 13 |
% \changes{v0.9a}{1998-06-25}{First release} |
| 14 |
% \changes{v0.9b}{1998-08-04}{Documentation update} |
| 15 |
% |
| 16 |
%% \CharacterTable |
| 17 |
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 18 |
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 19 |
%% Digits \0\1\2\3\4\5\6\7\8\9 |
| 20 |
%% Exclamation \! Double quote \" Hash (number) \# |
| 21 |
%% Dollar \$ Percent \% Ampersand \& |
| 22 |
%% Acute accent \' Left paren \( Right paren \) |
| 23 |
%% Asterisk \* Plus \+ Comma \, |
| 24 |
%% Minus \- Point \. Solidus \/ |
| 25 |
%% Colon \: Semicolon \; Less than \< |
| 26 |
%% Equals \= Greater than \> Question mark \? |
| 27 |
%% Commercial at \@ Left bracket \[ Backslash \\ |
| 28 |
%% Right bracket \] Circumflex \^ Underscore \_ |
| 29 |
%% Grave accent \` Left brace \{ Vertical bar \| |
| 30 |
%% Right brace \} Tilde \~} |
| 31 |
% |
| 32 |
% \newcommand{\file}[1]{\texttt{#1}} |
| 33 |
% \newcommand{\option}[1]{\texttt{#1}} |
| 34 |
% \newcommand{\package}[1]{\texttt{#1}} |
| 35 |
% \newcommand{\person}[1]{\textsc{#1}} |
| 36 |
% \newcommand{\winkey}{\texttt{(-;}} |
| 37 |
% |
| 38 |
% \title{\file{units.sty} -- \file{nicefrac.sty}} |
| 39 |
% \author{Axel Reichert} |
| 40 |
% \date{1998-08-04} |
| 41 |
% \maketitle |
| 42 |
% \begin{abstract} |
| 43 |
% \file{units.sty} is a package for setting units in a |
| 44 |
% typographically correct way. It is based upon |
| 45 |
% \file{nicefrac.sty}, a package for nice fractions. See the |
| 46 |
% files \file{README} and \file{COPYING} for additional |
| 47 |
% information. |
| 48 |
% \end{abstract} |
| 49 |
% \section{Loading} |
| 50 |
% \begin{tabbing} |
| 51 |
% Only nice fractions: \= |\usepackage{nicefrac}| \\ |
| 52 |
% Only units or both: \> |\usepackage{units}| |
| 53 |
% \end{tabbing} |
| 54 |
% \section{Options} |
| 55 |
% \begin{tabbing} |
| 56 |
% Tight spacing for units (default): \= |
| 57 |
% |\usepackage[tight]{units}| \\ |
| 58 |
% Loose spacing for units: \> |
| 59 |
% |\usepackage[loose]{units}| \\ |
| 60 |
% ``Nice'' fractions (default): \> |
| 61 |
% |\usepackage[nice]{nicefrac}| \\ |
| 62 |
% ``Ugly'' fractions: \> |
| 63 |
% |\usepackage[ugly]{nicefrac}| |
| 64 |
% \end{tabbing} |
| 65 |
% |
| 66 |
% The options \option{nice} and \option{ugly} can also be used for |
| 67 |
% the \package{units} package, they will simply be passed to the |
| 68 |
% \package{nicefrac} package, so you can combine the options, |
| 69 |
% e.\,g.: |\usepackage[loose,ugly]{units}| |
| 70 |
% |
| 71 |
% Tight spacing means \cmd{\,} for the space between the value and the |
| 72 |
% dimension, loose spacing uses |~|, like \unit[1]{m} and 1~m. Nice |
| 73 |
% fractions look like \nicefrac{m}{s}, ugly fractions look like m/s |
| 74 |
% in text mode and $\frac{\mathrm{m}}{\mathrm{s}}$ in math mode. |
| 75 |
% \section{Commands} |
| 76 |
% \begin{tabbing} |
| 77 |
% Fractions of units: \= |
| 78 |
% |\unitfrac[|\meta{val}|]{|\meta{num}|}{|\meta{denom}|}| \kill |
| 79 |
% Units: \> |\unit[|\meta{val}|]{|\meta{dim}|}| \\ |
| 80 |
% Fractions of units: \> |
| 81 |
% |\unitfrac[|\meta{val}|]{|\meta{num}|}{|\meta{denom}|}| \\ |
| 82 |
% Nice fractions: \> |
| 83 |
% |\nicefrac[|\meta{fontcmd}|]{|\meta{num}|}{|\meta{denom}|}| |
| 84 |
% \end{tabbing} |
| 85 |
% In these list, \meta{val} and \meta{dim} denote the value and the |
| 86 |
% dimension of the unit, respectively. \meta{num} and \meta{denom} |
| 87 |
% are the numerator and denominator of the fraction, and |
| 88 |
% \meta{fontcmd} can be an author command for fonts or a math |
| 89 |
% alphabet, see \file{fntguide.dvi}. |
| 90 |
% |
| 91 |
% Typically, \meta{val} is only a number and \meta{num} and |
| 92 |
% \meta{denom} are relatively simple \LaTeX{} expressions. If you |
| 93 |
% really feel the need for putting whole paragraphs or complex |
| 94 |
% formula into such a fraction, you have misunderstood the purpose |
| 95 |
% of this package. \winkey |
| 96 |
% |
| 97 |
% A common mistake is to forget the enclosing braces when using the |
| 98 |
% optional argument of the commands inside another optional |
| 99 |
% argument. This is no package bug, but a \LaTeX{} feature. Correct |
| 100 |
% example: |\section[{\unit[1]{m}}]{...}|.\footnote{Credits go to |
| 101 |
% \person{Frank Knappe} for suggesting this documentation update.} |
| 102 |
% |
| 103 |
% It is very important to be aware of the fact that all these |
| 104 |
% commands distinguish between text mode and math mode. Within text |
| 105 |
% mode, the font of the surrounding text will be used by default, |
| 106 |
% for math mode \cmd{\mathrm} is the default. |
| 107 |
% |
| 108 |
% This is quite sensible, because you would not want your |
| 109 |
% collection of delicious recipes (typeset in a mega-cool ultra |
| 110 |
% condensed bold italic calligraphical font) contain those spindle |
| 111 |
% Computer Modern Roman just for half a litre of milk. \winkey |
| 112 |
% |
| 113 |
% Otherwise, when working on scientific papers, strict and |
| 114 |
% consistent notation is really a virtue, and, like it or not, |
| 115 |
% units are typeset with upright fonts. So take great care when |
| 116 |
% deciding about math mode or not. |
| 117 |
% \section{Examples} |
| 118 |
% \begin{tabbing} |
| 119 |
% |\sffamily\itshape$\unitfrac[1]{m}{s}$| \quad \= |
| 120 |
% \sffamily\itshape$\unitfrac[1]{m}{s}$ \kill |
| 121 |
% |\sffamily\bfseries\unit{m}| \> \sffamily\bfseries\unit{m} \\ |
| 122 |
% |\sffamily\bfseries$\unit{m}$| \> \sffamily\bfseries$\unit{m}$ \\ |
| 123 |
% |\sffamily\itshape\unit[1]{m}| \> \sffamily\itshape\unit[1]{m} \\ |
| 124 |
% |\sffamily\itshape$\unit[1]{m}$| \> \sffamily\itshape$\unit[1]{m}$ \\ |
| 125 |
% |\sffamily\bfseries\unitfrac{m}{s}| \> |
| 126 |
% \sffamily\bfseries\unitfrac{m}{s} \\ |
| 127 |
% |\sffamily\bfseries$\unitfrac{m}{s}$| \> |
| 128 |
% \sffamily\bfseries$\unitfrac{m}{s}$ \\ |
| 129 |
% |\sffamily\itshape\unitfrac[1]{m}{s}| \> |
| 130 |
% \sffamily\itshape\unitfrac[1]{m}{s} \\ |
| 131 |
% |\sffamily\itshape$\unitfrac[1]{m}{s}$| \> |
| 132 |
% \sffamily\itshape$\unitfrac[1]{m}{s}$ |
| 133 |
% \end{tabbing} |
| 134 |
% As you can see, font changes are ignored in math mode~\ldots |
| 135 |
% \begin{tabbing} |
| 136 |
% |\scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$| \quad \= |
| 137 |
% \scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$ \kill |
| 138 |
% |\scriptsize\sffamily\itshape\unitfrac[1]{m}{s}| \> |
| 139 |
% \scriptsize\sffamily\itshape\unitfrac[1]{m}{s} \\ |
| 140 |
% |\scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$| \> |
| 141 |
% \scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$ |
| 142 |
% \end{tabbing} |
| 143 |
% \ldots~except for the fontsize. |
| 144 |
% \begin{tabbing} |
| 145 |
% |\bfseries\itshape$\nicefrac{1}{2}$| \quad \= |
| 146 |
% \bfseries\itshape$\nicefrac{1}{2}$ \kill |
| 147 |
% |\bfseries\itshape\nicefrac{1}{2}| \> |
| 148 |
% \bfseries\itshape\nicefrac{1}{2} \\ |
| 149 |
% |\bfseries\itshape$\nicefrac{1}{2}$| \> |
| 150 |
% \bfseries\itshape$\nicefrac{1}{2}$ \\ |
| 151 |
% |\nicefrac[\texttt]{1}{2}| \> \nicefrac[\texttt]{1}{2} \\ |
| 152 |
% |\nicefrac[\texttt]{\textit{1}}{2}| \> |
| 153 |
% \nicefrac[\texttt]{\textit{1}}{2} \\ |
| 154 |
% |$\nicefrac[\mathcal]{A}{B}$| \> $\nicefrac[\mathcal]{A}{B}$ |
| 155 |
% \end{tabbing} |
| 156 |
% The \cmd{\nicefrac} command can deal even with quite strange font |
| 157 |
% changing commands. |
| 158 |
% \section{Typography} |
| 159 |
% Why should units be typeset in upright fonts, not in italics? |
| 160 |
% Because they have to be distinguished from normal variables: |
| 161 |
% ``\unit{m}'' is meter, ``$m$'' is a variable, for example a mass. |
| 162 |
% |
| 163 |
% Why should the space between the value and the dimension be |
| 164 |
% non-breakable? Because the reader is disturbed by linebreaks like |
| 165 |
% 1 $\mathrm{m}$. |
| 166 |
% |
| 167 |
% Why should the space between the value and the dimension be a |
| 168 |
% half word space only? Because things belonging together are |
| 169 |
% typeset tighter. Compare \unit[1]{m} with 1~m and the normal word |
| 170 |
% spacing, which can vary from line to line. |
| 171 |
% |
| 172 |
% Why should nice fractions be typeset so that the numerator does |
| 173 |
% not extend above the height of the letter ``M'' and the |
| 174 |
% denominator does not extend below the baseline? Because otherwise |
| 175 |
% a stretching of the baselineskip could be necessary due to |
| 176 |
% descenders. |
| 177 |
% |
| 178 |
% By the way, a very common mistake is to place units into |
| 179 |
% brackets, like [\unit{N}]. The correct notation is $[F] = |
| 180 |
% \unit{N}$. The brackets indeed are a function with a variable as |
| 181 |
% an argument. The value returned is the unit. If you need to |
| 182 |
% specify units in table headings, then use a single row for the |
| 183 |
% units, where you put them into \emph{parentheses} instead. |
| 184 |
% \section{Bugs} |
| 185 |
% None, are you kidding? |
| 186 |
% \section{Features} |
| 187 |
% \begin{itemize} |
| 188 |
% \item Consistent and logical markup of units is enhanced instead |
| 189 |
% of fiddling around with spacing and fonts. |
| 190 |
% \item The same command works in text mode \emph{and} math mode, |
| 191 |
% font and size are adjusted automatically for nice integration |
| 192 |
% within text mode while forcing strict notation in math mode. |
| 193 |
% \item Basic requirements of typography are fulfilled: Forbidden |
| 194 |
% linebreaks, correct spacing and the numerator automatically |
| 195 |
% aligning with the height of an ``M''. |
| 196 |
% \item Easy configuration by use of package options. |
| 197 |
% \end{itemize} |
| 198 |
% \section{Bugs again \winkey} |
| 199 |
% Ok, ok, you got me. |
| 200 |
% \begin{itemize} |
| 201 |
% \item Fonts without ``M'' do not work correctly. Do you know one? |
| 202 |
% \item Fractions in \cmd{\scriptscriptstyle} look ugly because they |
| 203 |
% exceed the height of an ``M''. As far as I know this is a |
| 204 |
% \LaTeX{} problem, because there are no smaller math fonts |
| 205 |
% available. |
| 206 |
% \item The kerning between numerator and slash or denominator and |
| 207 |
% slash is bad. In fact, there is none. |
| 208 |
% \item The combination of the \option{ugly} option with text mode |
| 209 |
% can lead to ambiguous fractions. Be happy that a warning is |
| 210 |
% issued. Why do you use this option? Your boss? Ah, I see. |
| 211 |
% \end{itemize} |
| 212 |
% \section{Implementation} |
| 213 |
% \subsection{Documentation Driver} |
| 214 |
% \begin{macrocode} |
| 215 |
%<*driver> |
| 216 |
\documentclass[12pt,a4paper]{ltxdoc} |
| 217 |
\usepackage{units} |
| 218 |
\begin{document} |
| 219 |
\DocInput{units.dtx} |
| 220 |
\end{document} |
| 221 |
%</driver> |
| 222 |
% \end{macrocode} |
| 223 |
% \StopEventually{ |
| 224 |
% \font\logosl=logosl10 scaled\magstep1 |
| 225 |
% \begin{thebibliography}{1} |
| 226 |
% \bibitem{Goossens:1994} |
| 227 |
% \textsc{Goossens, M.; Mittelbach, F.; Samarin, A.}: \emph{Der |
| 228 |
% \LaTeX-Begleiter}. \newblock Addison-Wesley, Bonn, 1st edn., |
| 229 |
% 1994. |
| 230 |
% \bibitem{Kopka:1994} |
| 231 |
% \textsc{Kopka, H.}: \emph{Einf{\"u}hrung}, vol.~1 of |
| 232 |
% \emph{\LaTeX}. \newblock Addison-Wesley, Bonn, 1st edn., |
| 233 |
% 1994. |
| 234 |
% \bibitem{Kopka:1995} |
| 235 |
% \textsc{Kopka, H.}: \emph{Erg{\"a}nzungen -- mit einer |
| 236 |
% Einf{\"u}hrung in {\logosl META}\-{\logosl FONT}}, vol.~2 of |
| 237 |
% \emph{\LaTeX}. \newblock Addison-Wesley, Bonn, 1st edn., |
| 238 |
% 1995. |
| 239 |
% \bibitem{Kopka:1997} |
| 240 |
% \textsc{Kopka, H.}: \emph{Erweiterungen}, vol.~3 of |
| 241 |
% \emph{\LaTeX}. \newblock Addison-Wesley-Longman, Bonn, 1997. |
| 242 |
% \bibitem{Willberg:1997} |
| 243 |
% \textsc{Willberg, H.\,P.; Forssman, F.}: |
| 244 |
% \emph{Lesetypographie}. \newblock Schmidt, Mainz, 1997. |
| 245 |
% \end{thebibliography} |
| 246 |
% } |
| 247 |
% \subsection{\file{units.sty}} |
| 248 |
% \begin{macrocode} |
| 249 |
%<*units> |
| 250 |
% \end{macrocode} |
| 251 |
% \subsubsection{Identification} |
| 252 |
% As this package uses the \cmd{\RequirePackage} command, it does |
| 253 |
% not work with older \LaTeXe{} versions. |
| 254 |
% \begin{macrocode} |
| 255 |
\NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 256 |
% \end{macrocode} |
| 257 |
% The package identifies itself with its release date, a version |
| 258 |
% number, and a short description. |
| 259 |
% \begin{macrocode} |
| 260 |
\ProvidesPackage{units}[1998/08/04 v0.9b Typesetting units] |
| 261 |
% \end{macrocode} |
| 262 |
% \subsubsection{Initialization} |
| 263 |
% The \package{ifthen} package is loaded because a new boolean |
| 264 |
% variable has to be declared. |
| 265 |
% \begin{macrocode} |
| 266 |
\RequirePackage{ifthen} |
| 267 |
\newboolean{B@UnitsLoose} |
| 268 |
% \end{macrocode} |
| 269 |
% \subsubsection{Option Declaration} |
| 270 |
% This boolean variable is set according to the package options. |
| 271 |
% \begin{macrocode} |
| 272 |
\DeclareOption{tight}{\setboolean{B@UnitsLoose}{false}} |
| 273 |
\DeclareOption{loose}{\setboolean{B@UnitsLoose}{true}} |
| 274 |
% \end{macrocode} |
| 275 |
% Other options will be passed to the \package{nicefrac} package. |
| 276 |
% \begin{macrocode} |
| 277 |
\DeclareOption*{% |
| 278 |
\PassOptionsToPackage{\CurrentOption}{nicefrac}% |
| 279 |
} |
| 280 |
% \end{macrocode} |
| 281 |
% \subsubsection{Option Processing} |
| 282 |
% If no options are specified, tight spacing between the value and |
| 283 |
% the dimension of a unit is used by default. Otherwise the options |
| 284 |
% are processed in the order given by the calling command. |
| 285 |
% \begin{macrocode} |
| 286 |
\ExecuteOptions{tight} |
| 287 |
\ProcessOptions* |
| 288 |
% \end{macrocode} |
| 289 |
% \subsubsection{Loading Files} |
| 290 |
% \enlargethispage{\baselineskip} |
| 291 |
% Because the macro used for fractions of units is also helpful for |
| 292 |
% other nice fractions, it is build into a stand-alone package |
| 293 |
% called \package{nicefrac}, which therefore is required by |
| 294 |
% \file{units.sty}. |
| 295 |
% \begin{macrocode} |
| 296 |
\RequirePackage{nicefrac}[1998/08/04] |
| 297 |
% \end{macrocode} |
| 298 |
% \subsubsection{Defining Commands} |
| 299 |
% In order to make debugging easier for the package user (missing |
| 300 |
% braces or brackets), all commands are declared with the |
| 301 |
% \texttt{*}-form of \cmd{\DeclareRobustCommand}. The \texttt{*}-form |
| 302 |
% does not allow ``long'' arguments for the commands, so e.\,g.\ |
| 303 |
% |\par| commands are forbidden inside the arguments. This should |
| 304 |
% be no serious restriction. \winkey |
| 305 |
% \begin{macro}{\unit} |
| 306 |
% First, it is checked if the optional argument is |
| 307 |
% empty.\footnote{Credits go to \person{Bernd Raichle} for |
| 308 |
% supplying this method.} |
| 309 |
% \begin{macrocode} |
| 310 |
\DeclareRobustCommand*{\unit}[2][]{% |
| 311 |
\begingroup |
| 312 |
\def\0{#1}% |
| 313 |
\expandafter |
| 314 |
\endgroup |
| 315 |
% \end{macrocode} |
| 316 |
% If it is, nothing happens. |
| 317 |
% \begin{macrocode} |
| 318 |
\ifx\0\@empty |
| 319 |
% \end{macrocode} |
| 320 |
% Otherwise it is typeset and followed by a space depending on the |
| 321 |
% boolean declared above. |
| 322 |
% \begin{macrocode} |
| 323 |
\else |
| 324 |
#1% |
| 325 |
\ifthenelse{\boolean{B@UnitsLoose}}{~}{\,}% |
| 326 |
\fi |
| 327 |
% \end{macrocode} |
| 328 |
% The use of upright fonts for the dimension is forced in math |
| 329 |
% mode. Units in text mode are typeset with the currently active font. |
| 330 |
% \begin{macrocode} |
| 331 |
\ifthenelse{\boolean{mmode}}{\mathrm{#2}}{#2}% |
| 332 |
} |
| 333 |
% \end{macrocode} |
| 334 |
% \end{macro} |
| 335 |
% \begin{macro}{\unitfrac} |
| 336 |
% Fractions of units are typeset by means of the \cmd{\nicefrac} |
| 337 |
% command. Upright fonts are forced in math mode by use of the |
| 338 |
% optional argument. The rest of code is identical to the former |
| 339 |
% macro. |
| 340 |
% \begin{macrocode} |
| 341 |
\DeclareRobustCommand*{\unitfrac}[3][]{% |
| 342 |
\begingroup |
| 343 |
\def\0{#1}% |
| 344 |
\expandafter |
| 345 |
\endgroup |
| 346 |
\ifx\0\@empty |
| 347 |
\else |
| 348 |
#1% |
| 349 |
\ifthenelse{\boolean{B@UnitsLoose}}{~}{\,}% |
| 350 |
\fi |
| 351 |
\ifthenelse{\boolean{mmode}}{% |
| 352 |
\nicefrac[\mathrm]{#2}{#3}% |
| 353 |
}% |
| 354 |
{% |
| 355 |
\nicefrac{#2}{#3}% |
| 356 |
}% |
| 357 |
} |
| 358 |
%</units> |
| 359 |
% \end{macrocode} |
| 360 |
% \end{macro} |
| 361 |
% \subsection{\file{nicefrac.sty}} |
| 362 |
% \begin{macrocode} |
| 363 |
%<*nicefrac> |
| 364 |
% \end{macrocode} |
| 365 |
% \subsubsection{Identification} |
| 366 |
% \begin{macrocode} |
| 367 |
\NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 368 |
\ProvidesPackage{nicefrac}[1998/08/04 v0.9b Nice fractions] |
| 369 |
% \end{macrocode} |
| 370 |
% \subsubsection{Initialization} |
| 371 |
% First, some new lengths are allocated. |
| 372 |
% \begin{macrocode} |
| 373 |
\newlength{\L@UnitsRaiseDisplaystyle} |
| 374 |
\newlength{\L@UnitsRaiseTextstyle} |
| 375 |
\newlength{\L@UnitsRaiseScriptstyle} |
| 376 |
% \end{macrocode} |
| 377 |
% \subsubsection{Loading Files} |
| 378 |
% The \package{ifthen} package is loaded for easier handling of decisions. |
| 379 |
% \begin{macrocode} |
| 380 |
\RequirePackage{ifthen} |
| 381 |
% \end{macrocode} |
| 382 |
% \subsubsection{Defining Commands} |
| 383 |
% \begin{macro}{\@UnitsNiceFrac} |
| 384 |
% Now the code used for nice fractions in math mode: |
| 385 |
% \begin{macrocode} |
| 386 |
\DeclareRobustCommand*{\@UnitsNiceFrac}[3][]{% |
| 387 |
\ifthenelse{\boolean{mmode}}{% |
| 388 |
% \end{macrocode} |
| 389 |
% For each of the four different math styles the ``M'' height is |
| 390 |
% measured, taking specified font changing commands into account. |
| 391 |
% \begin{macrocode} |
| 392 |
\settoheight{\L@UnitsRaiseDisplaystyle}{% |
| 393 |
\ensuremath{\displaystyle#1{M}}% |
| 394 |
}% |
| 395 |
\settoheight{\L@UnitsRaiseTextstyle}{% |
| 396 |
\ensuremath{\textstyle#1{M}}% |
| 397 |
}% |
| 398 |
\settoheight{\L@UnitsRaiseScriptstyle}{% |
| 399 |
\ensuremath{\scriptstyle#1{M}}% |
| 400 |
}% |
| 401 |
\settoheight{\@tempdima}{% |
| 402 |
\ensuremath{\scriptscriptstyle#1{M}}% |
| 403 |
}% |
| 404 |
% \end{macrocode} |
| 405 |
% The raise height is calculated by taking the difference between |
| 406 |
% the height of a normal ``M'' and the height of an ``M'' set in |
| 407 |
% the correct numerator size. |
| 408 |
% \begin{macrocode} |
| 409 |
\addtolength{\L@UnitsRaiseDisplaystyle}{% |
| 410 |
-\L@UnitsRaiseScriptstyle% |
| 411 |
}% |
| 412 |
\addtolength{\L@UnitsRaiseTextstyle}{% |
| 413 |
-\L@UnitsRaiseScriptstyle% |
| 414 |
}% |
| 415 |
\addtolength{\L@UnitsRaiseScriptstyle}{-\@tempdima}% |
| 416 |
% \end{macrocode} |
| 417 |
% The height of the numerator above the baseline is dependent on |
| 418 |
% the actual fontsize within the math environment.\footnote{Credits |
| 419 |
% go to \person{Wolfgang May} for telling me of the |
| 420 |
% \cmd{\mathchoice} command.} The numerator is put into an |
| 421 |
% appropriately raised box, within math mode (the additional |
| 422 |
% \cmd{\ensuremath} is necessary, because the \cmd{\raisebox} |
| 423 |
% command leaves math mode). |
| 424 |
% |
| 425 |
% The fontsize for the numerator part is \cmd{\scriptstyle} within |
| 426 |
% \cmd{\displaystyle} and \cmd{\textstyle}, but |
| 427 |
% \cmd{\scriptscriptstyle} within \cmd{\scriptstyle} and |
| 428 |
% \cmd{\scriptscriptstyle} context. |
| 429 |
% |
| 430 |
% Then the numerator is typeset either with the upright math font or |
| 431 |
% using the font command specified in the optional argument (if it |
| 432 |
% is given). Only the math alphabet commands may be used: |
| 433 |
% \cmd{\mathnormal}, \cmd{\mathrm}, \cmd{\mathbf}, \cmd{\mathsf}, |
| 434 |
% \cmd{\mathit}, \cmd{\mathtt}, and \cmd{\mathcal}. |
| 435 |
% \begin{macrocode} |
| 436 |
\mathchoice |
| 437 |
{% |
| 438 |
\raisebox{\L@UnitsRaiseDisplaystyle}{% |
| 439 |
\ensuremath{\scriptstyle#1{#2}}% |
| 440 |
}% |
| 441 |
}% |
| 442 |
{% |
| 443 |
\raisebox{\L@UnitsRaiseTextstyle}{% |
| 444 |
\ensuremath{\scriptstyle#1{#2}}% |
| 445 |
}% |
| 446 |
}% |
| 447 |
{% |
| 448 |
\raisebox{\L@UnitsRaiseScriptstyle}{% |
| 449 |
\ensuremath{\scriptscriptstyle#1{#2}}% |
| 450 |
}% |
| 451 |
}% |
| 452 |
% \end{macrocode} |
| 453 |
% Within \cmd{\scriptscriptstyle} context, \LaTeX{} does \emph{not} |
| 454 |
% use even smaller fonts for numerator or denominator. Following |
| 455 |
% the above calculation scheme would lead to a raise height of |
| 456 |
% \unit[0]{pt}. Because this could make fractions at least |
| 457 |
% ambiguous (if not wrong, like $\mathrm{J}/\mathrm{kg\cdot K}$ for |
| 458 |
% specific thermal capacity), the numerator in |
| 459 |
% \cmd{\scriptscriptstyle} context is raised by the same amount as |
| 460 |
% in \cmd{\scriptstyle} context and so exceeds the height of an |
| 461 |
% adjacent ``M''. This is ugly, but cannot be avoided. |
| 462 |
% \begin{macrocode} |
| 463 |
{% |
| 464 |
\raisebox{\L@UnitsRaiseScriptstyle}{% |
| 465 |
\ensuremath{\scriptscriptstyle#1{#2}}% |
| 466 |
}% |
| 467 |
}% |
| 468 |
% \end{macrocode} |
| 469 |
% The slash is typeset with reduced spacing to the numerator and to |
| 470 |
% the denominator. |
| 471 |
% \begin{macrocode} |
| 472 |
\mkern-2mu/\mkern-1mu% |
| 473 |
% \end{macrocode} |
| 474 |
% \changes{v0.9b}{1998-08-04}{\cmd{\bgroup} and \cmd{\egroup} |
| 475 |
% instead of \cmd{\begingroup} and \cmd{\endgroup}} |
| 476 |
% The denominator needs a seperate group to delimit the range of the |
| 477 |
% font commands.\footnote{Credits go to \person{Michael Switkes} |
| 478 |
% for the bug report and to \person{Heiko Oberdiek} for telling me |
| 479 |
% why the fix works.} The choice for the fontsize and the font |
| 480 |
% changing are made just like for the numerator. |
| 481 |
% \begin{macrocode} |
| 482 |
\bgroup |
| 483 |
\mathchoice |
| 484 |
{\scriptstyle}% |
| 485 |
{\scriptstyle}% |
| 486 |
{\scriptscriptstyle}% |
| 487 |
{\scriptscriptstyle}% |
| 488 |
#1{#3}% |
| 489 |
\egroup |
| 490 |
}% |
| 491 |
% \end{macrocode} |
| 492 |
% Now the code for nice fractions in text mode: |
| 493 |
% \begin{macrocode} |
| 494 |
{% |
| 495 |
% \end{macrocode} |
| 496 |
% First, the height of a normal ``M'' is measured. |
| 497 |
% \begin{macrocode} |
| 498 |
\settoheight{\L@UnitsRaiseTextstyle}{#1{M}}% |
| 499 |
% \end{macrocode} |
| 500 |
% \LaTeX{} offers no commands for relative fontsizes. To make the |
| 501 |
% macro work for example within footnotes or chapter headings, it |
| 502 |
% is necessary to avoid absolute sizing commands like |
| 503 |
% \cmd{\normalsize} or \cmd{\scriptsize}. To obtain a fontsize |
| 504 |
% that suits for the numerator and denominator, some code was taken |
| 505 |
% from the \LaTeX{} kernel (\file{latex.ltx}, definition of |
| 506 |
% \cmd{\textsuperscript}). |
| 507 |
% |
| 508 |
% In all these measurements the font changing effect of the |
| 509 |
% optional argument is taken into account. Only the following font |
| 510 |
% commands may be used: \cmd{\textnormal}, \cmd{\textrm}, |
| 511 |
% \cmd{\textsf}, \cmd{\texttt}, \cmd{\textbf}, \cmd{\textmd}, |
| 512 |
% \cmd{\textup}, \cmd{\textit}, \cmd{\textsc}, and \cmd{\textsl}. |
| 513 |
% \begin{macrocode} |
| 514 |
\settoheight{\@tempdima}{% |
| 515 |
\ensuremath{% |
| 516 |
\mbox{\fontsize\sf@size\z@\selectfont#1{M}}% |
| 517 |
}% |
| 518 |
}% |
| 519 |
% \end{macrocode} |
| 520 |
% Both lengths are subtracted. The result is used for the raise of |
| 521 |
% the numerator. |
| 522 |
% \begin{macrocode} |
| 523 |
\addtolength{\L@UnitsRaiseTextstyle}{-\@tempdima}% |
| 524 |
% \end{macrocode} |
| 525 |
% Finally, the numerator is typeset in ``relative scriptsize'' |
| 526 |
% either with the normal text font or using the font command |
| 527 |
% specified in the optional argument (if it is given). |
| 528 |
% \begin{macrocode} |
| 529 |
\raisebox{\L@UnitsRaiseTextstyle}{% |
| 530 |
\ensuremath{% |
| 531 |
\mbox{\fontsize\sf@size\z@\selectfont#1{#2}}% |
| 532 |
}% |
| 533 |
}% |
| 534 |
% \end{macrocode} |
| 535 |
% The code for the slash and the denominator should now be straight |
| 536 |
% forward. |
| 537 |
% \begin{macrocode} |
| 538 |
\ensuremath{\mkern-2mu}/\ensuremath{\mkern-1mu}% |
| 539 |
\ensuremath{% |
| 540 |
\mbox{\fontsize\sf@size\z@\selectfont#1{#3}}% |
| 541 |
}% |
| 542 |
}% |
| 543 |
} |
| 544 |
% \end{macrocode} |
| 545 |
% \end{macro} |
| 546 |
% \clearpage |
| 547 |
% \begin{macro}{\@UnitsUglyFrac} |
| 548 |
% Ugly fractions in math mode~\ldots |
| 549 |
% \begin{macrocode} |
| 550 |
\DeclareRobustCommand*{\@UnitsUglyFrac}[3][]{% |
| 551 |
\ifthenelse{\boolean{mmode}}{% |
| 552 |
% \end{macrocode} |
| 553 |
% \ldots~are typeset just like normal fractions. |
| 554 |
% \begin{macrocode} |
| 555 |
\frac{#1{#2}}{#1{#3}}% |
| 556 |
}% |
| 557 |
% \end{macrocode} |
| 558 |
% In text mode~\ldots |
| 559 |
% \begin{macrocode} |
| 560 |
{% |
| 561 |
% \end{macrocode} |
| 562 |
% ~\ldots they are typeset like J/kg\textperiodcentered K. |
| 563 |
% \begin{macrocode} |
| 564 |
#1{#2}/#1{#3}% |
| 565 |
% \end{macrocode} |
| 566 |
% Because the fraction can get ambiguous or even wrong, a warning |
| 567 |
% message is issued. |
| 568 |
% \begin{macrocode} |
| 569 |
\PackageWarning{nicefrac}{% |
| 570 |
You used \protect\nicefrac\space or |
| 571 |
\protect\unitfrac\space in text mode\MessageBreak |
| 572 |
and specified the ``ugly'' option.\MessageBreak |
| 573 |
The fraction may be ambiguous or wrong.\MessageBreak |
| 574 |
Please make sure the denominator is |
| 575 |
correct.\MessageBreak |
| 576 |
If it is, you can safely ignore\MessageBreak |
| 577 |
this warning |
| 578 |
}% |
| 579 |
}% |
| 580 |
} |
| 581 |
% \end{macrocode} |
| 582 |
% \end{macro} |
| 583 |
% \subsubsection{Option Declaration} |
| 584 |
% Dependent on the package options, the \cmd{\nicefrac} command |
| 585 |
% typesets either nice or ugly fractions by means of the |
| 586 |
% corresponding macros. |
| 587 |
% \begin{macrocode} |
| 588 |
\DeclareOption{nice}{% |
| 589 |
\DeclareRobustCommand*{\nicefrac}{\@UnitsNiceFrac}% |
| 590 |
} |
| 591 |
\DeclareOption{ugly}{% |
| 592 |
\DeclareRobustCommand*{\nicefrac}{\@UnitsUglyFrac}% |
| 593 |
} |
| 594 |
% \end{macrocode} |
| 595 |
% \subsubsection{Option Processing} |
| 596 |
% If no options are specified, nice fractions are used by default. |
| 597 |
% Otherwise the options are processed in the order given by the |
| 598 |
% calling command. |
| 599 |
% \begin{macrocode} |
| 600 |
\ExecuteOptions{nice} |
| 601 |
\ProcessOptions* |
| 602 |
%</nicefrac> |
| 603 |
% \end{macrocode} |
| 604 |
% \Finale |
| 605 |
\endinput |