summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/units/units.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/units/units.dtx')
-rw-r--r--macros/latex/contrib/units/units.dtx605
1 files changed, 605 insertions, 0 deletions
diff --git a/macros/latex/contrib/units/units.dtx b/macros/latex/contrib/units/units.dtx
new file mode 100644
index 0000000000..e63a755427
--- /dev/null
+++ b/macros/latex/contrib/units/units.dtx
@@ -0,0 +1,605 @@
+% \iffalse
+%
+% units.dtx
+% Docstrip archive, run through LaTeX.
+%
+% Copyright (C) 1998 Axel Reichert
+% See the files README and COPYING.
+%
+% \fi
+%
+% \CheckSum{174}
+%
+% \changes{v0.9a}{1998-06-25}{First release}
+% \changes{v0.9b}{1998-08-04}{Documentation update}
+%
+%% \CharacterTable
+%% {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
+%% 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
+%% Digits \0\1\2\3\4\5\6\7\8\9
+%% Exclamation \! Double quote \" Hash (number) \#
+%% Dollar \$ Percent \% Ampersand \&
+%% Acute accent \' Left paren \( Right paren \)
+%% Asterisk \* Plus \+ Comma \,
+%% Minus \- Point \. Solidus \/
+%% Colon \: Semicolon \; Less than \<
+%% Equals \= Greater than \> Question mark \?
+%% Commercial at \@ Left bracket \[ Backslash \\
+%% Right bracket \] Circumflex \^ Underscore \_
+%% Grave accent \` Left brace \{ Vertical bar \|
+%% Right brace \} Tilde \~}
+%
+% \newcommand{\file}[1]{\texttt{#1}}
+% \newcommand{\option}[1]{\texttt{#1}}
+% \newcommand{\package}[1]{\texttt{#1}}
+% \newcommand{\person}[1]{\textsc{#1}}
+% \newcommand{\winkey}{\texttt{(-;}}
+%
+% \title{\file{units.sty} -- \file{nicefrac.sty}}
+% \author{Axel Reichert}
+% \date{1998-08-04}
+% \maketitle
+% \begin{abstract}
+% \file{units.sty} is a package for setting units in a
+% typographically correct way. It is based upon
+% \file{nicefrac.sty}, a package for nice fractions. See the
+% files \file{README} and \file{COPYING} for additional
+% information.
+% \end{abstract}
+% \section{Loading}
+% \begin{tabbing}
+% Only nice fractions: \= |\usepackage{nicefrac}| \\
+% Only units or both: \> |\usepackage{units}|
+% \end{tabbing}
+% \section{Options}
+% \begin{tabbing}
+% Tight spacing for units (default): \=
+% |\usepackage[tight]{units}| \\
+% Loose spacing for units: \>
+% |\usepackage[loose]{units}| \\
+% ``Nice'' fractions (default): \>
+% |\usepackage[nice]{nicefrac}| \\
+% ``Ugly'' fractions: \>
+% |\usepackage[ugly]{nicefrac}|
+% \end{tabbing}
+%
+% The options \option{nice} and \option{ugly} can also be used for
+% the \package{units} package, they will simply be passed to the
+% \package{nicefrac} package, so you can combine the options,
+% e.\,g.: |\usepackage[loose,ugly]{units}|
+%
+% Tight spacing means \cmd{\,} for the space between the value and the
+% dimension, loose spacing uses |~|, like \unit[1]{m} and 1~m. Nice
+% fractions look like \nicefrac{m}{s}, ugly fractions look like m/s
+% in text mode and $\frac{\mathrm{m}}{\mathrm{s}}$ in math mode.
+% \section{Commands}
+% \begin{tabbing}
+% Fractions of units: \=
+% |\unitfrac[|\meta{val}|]{|\meta{num}|}{|\meta{denom}|}| \kill
+% Units: \> |\unit[|\meta{val}|]{|\meta{dim}|}| \\
+% Fractions of units: \>
+% |\unitfrac[|\meta{val}|]{|\meta{num}|}{|\meta{denom}|}| \\
+% Nice fractions: \>
+% |\nicefrac[|\meta{fontcmd}|]{|\meta{num}|}{|\meta{denom}|}|
+% \end{tabbing}
+% In these list, \meta{val} and \meta{dim} denote the value and the
+% dimension of the unit, respectively. \meta{num} and \meta{denom}
+% are the numerator and denominator of the fraction, and
+% \meta{fontcmd} can be an author command for fonts or a math
+% alphabet, see \file{fntguide.dvi}.
+%
+% Typically, \meta{val} is only a number and \meta{num} and
+% \meta{denom} are relatively simple \LaTeX{} expressions. If you
+% really feel the need for putting whole paragraphs or complex
+% formula into such a fraction, you have misunderstood the purpose
+% of this package. \winkey
+%
+% A common mistake is to forget the enclosing braces when using the
+% optional argument of the commands inside another optional
+% argument. This is no package bug, but a \LaTeX{} feature. Correct
+% example: |\section[{\unit[1]{m}}]{...}|.\footnote{Credits go to
+% \person{Frank Knappe} for suggesting this documentation update.}
+%
+% It is very important to be aware of the fact that all these
+% commands distinguish between text mode and math mode. Within text
+% mode, the font of the surrounding text will be used by default,
+% for math mode \cmd{\mathrm} is the default.
+%
+% This is quite sensible, because you would not want your
+% collection of delicious recipes (typeset in a mega-cool ultra
+% condensed bold italic calligraphical font) contain those spindle
+% Computer Modern Roman just for half a litre of milk. \winkey
+%
+% Otherwise, when working on scientific papers, strict and
+% consistent notation is really a virtue, and, like it or not,
+% units are typeset with upright fonts. So take great care when
+% deciding about math mode or not.
+% \section{Examples}
+% \begin{tabbing}
+% |\sffamily\itshape$\unitfrac[1]{m}{s}$| \quad \=
+% \sffamily\itshape$\unitfrac[1]{m}{s}$ \kill
+% |\sffamily\bfseries\unit{m}| \> \sffamily\bfseries\unit{m} \\
+% |\sffamily\bfseries$\unit{m}$| \> \sffamily\bfseries$\unit{m}$ \\
+% |\sffamily\itshape\unit[1]{m}| \> \sffamily\itshape\unit[1]{m} \\
+% |\sffamily\itshape$\unit[1]{m}$| \> \sffamily\itshape$\unit[1]{m}$ \\
+% |\sffamily\bfseries\unitfrac{m}{s}| \>
+% \sffamily\bfseries\unitfrac{m}{s} \\
+% |\sffamily\bfseries$\unitfrac{m}{s}$| \>
+% \sffamily\bfseries$\unitfrac{m}{s}$ \\
+% |\sffamily\itshape\unitfrac[1]{m}{s}| \>
+% \sffamily\itshape\unitfrac[1]{m}{s} \\
+% |\sffamily\itshape$\unitfrac[1]{m}{s}$| \>
+% \sffamily\itshape$\unitfrac[1]{m}{s}$
+% \end{tabbing}
+% As you can see, font changes are ignored in math mode~\ldots
+% \begin{tabbing}
+% |\scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$| \quad \=
+% \scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$ \kill
+% |\scriptsize\sffamily\itshape\unitfrac[1]{m}{s}| \>
+% \scriptsize\sffamily\itshape\unitfrac[1]{m}{s} \\
+% |\scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$| \>
+% \scriptsize\sffamily\itshape$\unitfrac[1]{m}{s}$
+% \end{tabbing}
+% \ldots~except for the fontsize.
+% \begin{tabbing}
+% |\bfseries\itshape$\nicefrac{1}{2}$| \quad \=
+% \bfseries\itshape$\nicefrac{1}{2}$ \kill
+% |\bfseries\itshape\nicefrac{1}{2}| \>
+% \bfseries\itshape\nicefrac{1}{2} \\
+% |\bfseries\itshape$\nicefrac{1}{2}$| \>
+% \bfseries\itshape$\nicefrac{1}{2}$ \\
+% |\nicefrac[\texttt]{1}{2}| \> \nicefrac[\texttt]{1}{2} \\
+% |\nicefrac[\texttt]{\textit{1}}{2}| \>
+% \nicefrac[\texttt]{\textit{1}}{2} \\
+% |$\nicefrac[\mathcal]{A}{B}$| \> $\nicefrac[\mathcal]{A}{B}$
+% \end{tabbing}
+% The \cmd{\nicefrac} command can deal even with quite strange font
+% changing commands.
+% \section{Typography}
+% Why should units be typeset in upright fonts, not in italics?
+% Because they have to be distinguished from normal variables:
+% ``\unit{m}'' is meter, ``$m$'' is a variable, for example a mass.
+%
+% Why should the space between the value and the dimension be
+% non-breakable? Because the reader is disturbed by linebreaks like
+% 1 $\mathrm{m}$.
+%
+% Why should the space between the value and the dimension be a
+% half word space only? Because things belonging together are
+% typeset tighter. Compare \unit[1]{m} with 1~m and the normal word
+% spacing, which can vary from line to line.
+%
+% Why should nice fractions be typeset so that the numerator does
+% not extend above the height of the letter ``M'' and the
+% denominator does not extend below the baseline? Because otherwise
+% a stretching of the baselineskip could be necessary due to
+% descenders.
+%
+% By the way, a very common mistake is to place units into
+% brackets, like [\unit{N}]. The correct notation is $[F] =
+% \unit{N}$. The brackets indeed are a function with a variable as
+% an argument. The value returned is the unit. If you need to
+% specify units in table headings, then use a single row for the
+% units, where you put them into \emph{parentheses} instead.
+% \section{Bugs}
+% None, are you kidding?
+% \section{Features}
+% \begin{itemize}
+% \item Consistent and logical markup of units is enhanced instead
+% of fiddling around with spacing and fonts.
+% \item The same command works in text mode \emph{and} math mode,
+% font and size are adjusted automatically for nice integration
+% within text mode while forcing strict notation in math mode.
+% \item Basic requirements of typography are fulfilled: Forbidden
+% linebreaks, correct spacing and the numerator automatically
+% aligning with the height of an ``M''.
+% \item Easy configuration by use of package options.
+% \end{itemize}
+% \section{Bugs again \winkey}
+% Ok, ok, you got me.
+% \begin{itemize}
+% \item Fonts without ``M'' do not work correctly. Do you know one?
+% \item Fractions in \cmd{\scriptscriptstyle} look ugly because they
+% exceed the height of an ``M''. As far as I know this is a
+% \LaTeX{} problem, because there are no smaller math fonts
+% available.
+% \item The kerning between numerator and slash or denominator and
+% slash is bad. In fact, there is none.
+% \item The combination of the \option{ugly} option with text mode
+% can lead to ambiguous fractions. Be happy that a warning is
+% issued. Why do you use this option? Your boss? Ah, I see.
+% \end{itemize}
+% \section{Implementation}
+% \subsection{Documentation Driver}
+% \begin{macrocode}
+%<*driver>
+\documentclass[12pt,a4paper]{ltxdoc}
+\usepackage{units}
+\begin{document}
+ \DocInput{units.dtx}
+\end{document}
+%</driver>
+% \end{macrocode}
+% \StopEventually{
+% \font\logosl=logosl10 scaled\magstep1
+% \begin{thebibliography}{1}
+% \bibitem{Goossens:1994}
+% \textsc{Goossens, M.; Mittelbach, F.; Samarin, A.}: \emph{Der
+% \LaTeX-Begleiter}. \newblock Addison-Wesley, Bonn, 1st edn.,
+% 1994.
+% \bibitem{Kopka:1994}
+% \textsc{Kopka, H.}: \emph{Einf{\"u}hrung}, vol.~1 of
+% \emph{\LaTeX}. \newblock Addison-Wesley, Bonn, 1st edn.,
+% 1994.
+% \bibitem{Kopka:1995}
+% \textsc{Kopka, H.}: \emph{Erg{\"a}nzungen -- mit einer
+% Einf{\"u}hrung in {\logosl META}\-{\logosl FONT}}, vol.~2 of
+% \emph{\LaTeX}. \newblock Addison-Wesley, Bonn, 1st edn.,
+% 1995.
+% \bibitem{Kopka:1997}
+% \textsc{Kopka, H.}: \emph{Erweiterungen}, vol.~3 of
+% \emph{\LaTeX}. \newblock Addison-Wesley-Longman, Bonn, 1997.
+% \bibitem{Willberg:1997}
+% \textsc{Willberg, H.\,P.; Forssman, F.}:
+% \emph{Lesetypographie}. \newblock Schmidt, Mainz, 1997.
+% \end{thebibliography}
+% }
+% \subsection{\file{units.sty}}
+% \begin{macrocode}
+%<*units>
+% \end{macrocode}
+% \subsubsection{Identification}
+% As this package uses the \cmd{\RequirePackage} command, it does
+% not work with older \LaTeXe{} versions.
+% \begin{macrocode}
+\NeedsTeXFormat{LaTeX2e}[1995/12/01]
+% \end{macrocode}
+% The package identifies itself with its release date, a version
+% number, and a short description.
+% \begin{macrocode}
+\ProvidesPackage{units}[1998/08/04 v0.9b Typesetting units]
+% \end{macrocode}
+% \subsubsection{Initialization}
+% The \package{ifthen} package is loaded because a new boolean
+% variable has to be declared.
+% \begin{macrocode}
+\RequirePackage{ifthen}
+\newboolean{B@UnitsLoose}
+% \end{macrocode}
+% \subsubsection{Option Declaration}
+% This boolean variable is set according to the package options.
+% \begin{macrocode}
+\DeclareOption{tight}{\setboolean{B@UnitsLoose}{false}}
+\DeclareOption{loose}{\setboolean{B@UnitsLoose}{true}}
+% \end{macrocode}
+% Other options will be passed to the \package{nicefrac} package.
+% \begin{macrocode}
+\DeclareOption*{%
+ \PassOptionsToPackage{\CurrentOption}{nicefrac}%
+}
+% \end{macrocode}
+% \subsubsection{Option Processing}
+% If no options are specified, tight spacing between the value and
+% the dimension of a unit is used by default. Otherwise the options
+% are processed in the order given by the calling command.
+% \begin{macrocode}
+\ExecuteOptions{tight}
+\ProcessOptions*
+% \end{macrocode}
+% \subsubsection{Loading Files}
+% \enlargethispage{\baselineskip}
+% Because the macro used for fractions of units is also helpful for
+% other nice fractions, it is build into a stand-alone package
+% called \package{nicefrac}, which therefore is required by
+% \file{units.sty}.
+% \begin{macrocode}
+\RequirePackage{nicefrac}[1998/08/04]
+% \end{macrocode}
+% \subsubsection{Defining Commands}
+% In order to make debugging easier for the package user (missing
+% braces or brackets), all commands are declared with the
+% \texttt{*}-form of \cmd{\DeclareRobustCommand}. The \texttt{*}-form
+% does not allow ``long'' arguments for the commands, so e.\,g.\
+% |\par| commands are forbidden inside the arguments. This should
+% be no serious restriction. \winkey
+% \begin{macro}{\unit}
+% First, it is checked if the optional argument is
+% empty.\footnote{Credits go to \person{Bernd Raichle} for
+% supplying this method.}
+% \begin{macrocode}
+\DeclareRobustCommand*{\unit}[2][]{%
+ \begingroup
+ \def\0{#1}%
+ \expandafter
+ \endgroup
+% \end{macrocode}
+% If it is, nothing happens.
+% \begin{macrocode}
+ \ifx\0\@empty
+% \end{macrocode}
+% Otherwise it is typeset and followed by a space depending on the
+% boolean declared above.
+% \begin{macrocode}
+ \else
+ #1%
+ \ifthenelse{\boolean{B@UnitsLoose}}{~}{\,}%
+ \fi
+% \end{macrocode}
+% The use of upright fonts for the dimension is forced in math
+% mode. Units in text mode are typeset with the currently active font.
+% \begin{macrocode}
+ \ifthenelse{\boolean{mmode}}{\mathrm{#2}}{#2}%
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\unitfrac}
+% Fractions of units are typeset by means of the \cmd{\nicefrac}
+% command. Upright fonts are forced in math mode by use of the
+% optional argument. The rest of code is identical to the former
+% macro.
+% \begin{macrocode}
+\DeclareRobustCommand*{\unitfrac}[3][]{%
+ \begingroup
+ \def\0{#1}%
+ \expandafter
+ \endgroup
+ \ifx\0\@empty
+ \else
+ #1%
+ \ifthenelse{\boolean{B@UnitsLoose}}{~}{\,}%
+ \fi
+ \ifthenelse{\boolean{mmode}}{%
+ \nicefrac[\mathrm]{#2}{#3}%
+ }%
+ {%
+ \nicefrac{#2}{#3}%
+ }%
+}
+%</units>
+% \end{macrocode}
+% \end{macro}
+% \subsection{\file{nicefrac.sty}}
+% \begin{macrocode}
+%<*nicefrac>
+% \end{macrocode}
+% \subsubsection{Identification}
+% \begin{macrocode}
+\NeedsTeXFormat{LaTeX2e}[1995/12/01]
+\ProvidesPackage{nicefrac}[1998/08/04 v0.9b Nice fractions]
+% \end{macrocode}
+% \subsubsection{Initialization}
+% First, some new lengths are allocated.
+% \begin{macrocode}
+\newlength{\L@UnitsRaiseDisplaystyle}
+\newlength{\L@UnitsRaiseTextstyle}
+\newlength{\L@UnitsRaiseScriptstyle}
+% \end{macrocode}
+% \subsubsection{Loading Files}
+% The \package{ifthen} package is loaded for easier handling of decisions.
+% \begin{macrocode}
+\RequirePackage{ifthen}
+% \end{macrocode}
+% \subsubsection{Defining Commands}
+% \begin{macro}{\@UnitsNiceFrac}
+% Now the code used for nice fractions in math mode:
+% \begin{macrocode}
+\DeclareRobustCommand*{\@UnitsNiceFrac}[3][]{%
+ \ifthenelse{\boolean{mmode}}{%
+% \end{macrocode}
+% For each of the four different math styles the ``M'' height is
+% measured, taking specified font changing commands into account.
+% \begin{macrocode}
+ \settoheight{\L@UnitsRaiseDisplaystyle}{%
+ \ensuremath{\displaystyle#1{M}}%
+ }%
+ \settoheight{\L@UnitsRaiseTextstyle}{%
+ \ensuremath{\textstyle#1{M}}%
+ }%
+ \settoheight{\L@UnitsRaiseScriptstyle}{%
+ \ensuremath{\scriptstyle#1{M}}%
+ }%
+ \settoheight{\@tempdima}{%
+ \ensuremath{\scriptscriptstyle#1{M}}%
+ }%
+% \end{macrocode}
+% The raise height is calculated by taking the difference between
+% the height of a normal ``M'' and the height of an ``M'' set in
+% the correct numerator size.
+% \begin{macrocode}
+ \addtolength{\L@UnitsRaiseDisplaystyle}{%
+ -\L@UnitsRaiseScriptstyle%
+ }%
+ \addtolength{\L@UnitsRaiseTextstyle}{%
+ -\L@UnitsRaiseScriptstyle%
+ }%
+ \addtolength{\L@UnitsRaiseScriptstyle}{-\@tempdima}%
+% \end{macrocode}
+% The height of the numerator above the baseline is dependent on
+% the actual fontsize within the math environment.\footnote{Credits
+% go to \person{Wolfgang May} for telling me of the
+% \cmd{\mathchoice} command.} The numerator is put into an
+% appropriately raised box, within math mode (the additional
+% \cmd{\ensuremath} is necessary, because the \cmd{\raisebox}
+% command leaves math mode).
+%
+% The fontsize for the numerator part is \cmd{\scriptstyle} within
+% \cmd{\displaystyle} and \cmd{\textstyle}, but
+% \cmd{\scriptscriptstyle} within \cmd{\scriptstyle} and
+% \cmd{\scriptscriptstyle} context.
+%
+% Then the numerator is typeset either with the upright math font or
+% using the font command specified in the optional argument (if it
+% is given). Only the math alphabet commands may be used:
+% \cmd{\mathnormal}, \cmd{\mathrm}, \cmd{\mathbf}, \cmd{\mathsf},
+% \cmd{\mathit}, \cmd{\mathtt}, and \cmd{\mathcal}.
+% \begin{macrocode}
+ \mathchoice
+ {%
+ \raisebox{\L@UnitsRaiseDisplaystyle}{%
+ \ensuremath{\scriptstyle#1{#2}}%
+ }%
+ }%
+ {%
+ \raisebox{\L@UnitsRaiseTextstyle}{%
+ \ensuremath{\scriptstyle#1{#2}}%
+ }%
+ }%
+ {%
+ \raisebox{\L@UnitsRaiseScriptstyle}{%
+ \ensuremath{\scriptscriptstyle#1{#2}}%
+ }%
+ }%
+% \end{macrocode}
+% Within \cmd{\scriptscriptstyle} context, \LaTeX{} does \emph{not}
+% use even smaller fonts for numerator or denominator. Following
+% the above calculation scheme would lead to a raise height of
+% \unit[0]{pt}. Because this could make fractions at least
+% ambiguous (if not wrong, like $\mathrm{J}/\mathrm{kg\cdot K}$ for
+% specific thermal capacity), the numerator in
+% \cmd{\scriptscriptstyle} context is raised by the same amount as
+% in \cmd{\scriptstyle} context and so exceeds the height of an
+% adjacent ``M''. This is ugly, but cannot be avoided.
+% \begin{macrocode}
+ {%
+ \raisebox{\L@UnitsRaiseScriptstyle}{%
+ \ensuremath{\scriptscriptstyle#1{#2}}%
+ }%
+ }%
+% \end{macrocode}
+% The slash is typeset with reduced spacing to the numerator and to
+% the denominator.
+% \begin{macrocode}
+ \mkern-2mu/\mkern-1mu%
+% \end{macrocode}
+% \changes{v0.9b}{1998-08-04}{\cmd{\bgroup} and \cmd{\egroup}
+% instead of \cmd{\begingroup} and \cmd{\endgroup}}
+% The denominator needs a seperate group to delimit the range of the
+% font commands.\footnote{Credits go to \person{Michael Switkes}
+% for the bug report and to \person{Heiko Oberdiek} for telling me
+% why the fix works.} The choice for the fontsize and the font
+% changing are made just like for the numerator.
+% \begin{macrocode}
+ \bgroup
+ \mathchoice
+ {\scriptstyle}%
+ {\scriptstyle}%
+ {\scriptscriptstyle}%
+ {\scriptscriptstyle}%
+ #1{#3}%
+ \egroup
+ }%
+% \end{macrocode}
+% Now the code for nice fractions in text mode:
+% \begin{macrocode}
+ {%
+% \end{macrocode}
+% First, the height of a normal ``M'' is measured.
+% \begin{macrocode}
+ \settoheight{\L@UnitsRaiseTextstyle}{#1{M}}%
+% \end{macrocode}
+% \LaTeX{} offers no commands for relative fontsizes. To make the
+% macro work for example within footnotes or chapter headings, it
+% is necessary to avoid absolute sizing commands like
+% \cmd{\normalsize} or \cmd{\scriptsize}. To obtain a fontsize
+% that suits for the numerator and denominator, some code was taken
+% from the \LaTeX{} kernel (\file{latex.ltx}, definition of
+% \cmd{\textsuperscript}).
+%
+% In all these measurements the font changing effect of the
+% optional argument is taken into account. Only the following font
+% commands may be used: \cmd{\textnormal}, \cmd{\textrm},
+% \cmd{\textsf}, \cmd{\texttt}, \cmd{\textbf}, \cmd{\textmd},
+% \cmd{\textup}, \cmd{\textit}, \cmd{\textsc}, and \cmd{\textsl}.
+% \begin{macrocode}
+ \settoheight{\@tempdima}{%
+ \ensuremath{%
+ \mbox{\fontsize\sf@size\z@\selectfont#1{M}}%
+ }%
+ }%
+% \end{macrocode}
+% Both lengths are subtracted. The result is used for the raise of
+% the numerator.
+% \begin{macrocode}
+ \addtolength{\L@UnitsRaiseTextstyle}{-\@tempdima}%
+% \end{macrocode}
+% Finally, the numerator is typeset in ``relative scriptsize''
+% either with the normal text font or using the font command
+% specified in the optional argument (if it is given).
+% \begin{macrocode}
+ \raisebox{\L@UnitsRaiseTextstyle}{%
+ \ensuremath{%
+ \mbox{\fontsize\sf@size\z@\selectfont#1{#2}}%
+ }%
+ }%
+% \end{macrocode}
+% The code for the slash and the denominator should now be straight
+% forward.
+% \begin{macrocode}
+ \ensuremath{\mkern-2mu}/\ensuremath{\mkern-1mu}%
+ \ensuremath{%
+ \mbox{\fontsize\sf@size\z@\selectfont#1{#3}}%
+ }%
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+% \clearpage
+% \begin{macro}{\@UnitsUglyFrac}
+% Ugly fractions in math mode~\ldots
+% \begin{macrocode}
+\DeclareRobustCommand*{\@UnitsUglyFrac}[3][]{%
+ \ifthenelse{\boolean{mmode}}{%
+% \end{macrocode}
+% \ldots~are typeset just like normal fractions.
+% \begin{macrocode}
+ \frac{#1{#2}}{#1{#3}}%
+ }%
+% \end{macrocode}
+% In text mode~\ldots
+% \begin{macrocode}
+ {%
+% \end{macrocode}
+% ~\ldots they are typeset like J/kg\textperiodcentered K.
+% \begin{macrocode}
+ #1{#2}/#1{#3}%
+% \end{macrocode}
+% Because the fraction can get ambiguous or even wrong, a warning
+% message is issued.
+% \begin{macrocode}
+ \PackageWarning{nicefrac}{%
+ You used \protect\nicefrac\space or
+ \protect\unitfrac\space in text mode\MessageBreak
+ and specified the ``ugly'' option.\MessageBreak
+ The fraction may be ambiguous or wrong.\MessageBreak
+ Please make sure the denominator is
+ correct.\MessageBreak
+ If it is, you can safely ignore\MessageBreak
+ this warning
+ }%
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+% \subsubsection{Option Declaration}
+% Dependent on the package options, the \cmd{\nicefrac} command
+% typesets either nice or ugly fractions by means of the
+% corresponding macros.
+% \begin{macrocode}
+\DeclareOption{nice}{%
+ \DeclareRobustCommand*{\nicefrac}{\@UnitsNiceFrac}%
+}
+\DeclareOption{ugly}{%
+ \DeclareRobustCommand*{\nicefrac}{\@UnitsUglyFrac}%
+}
+% \end{macrocode}
+% \subsubsection{Option Processing}
+% If no options are specified, nice fractions are used by default.
+% Otherwise the options are processed in the order given by the
+% calling command.
+% \begin{macrocode}
+\ExecuteOptions{nice}
+\ProcessOptions*
+%</nicefrac>
+% \end{macrocode}
+% \Finale
+\endinput