summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/units/units.dtx
blob: e63a75542758349545ef99c7d94bd924a0cfeeee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
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