summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/was/gensymb.dtx
blob: 95d58740762babef8f14f5d9907ab5ac3e01dc90 (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
%\CheckSum{283}
%
% \iffalse
%
% File `gensymb.dtx'.
% Copyright (c) 2003 Walter Schmidt
%
% This program may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
% This program consists of the files gensymb.dtx and gensymb.ins
%
% \fi
%
% \iffalse
%
%<*driver>
\ProvidesFile{gensymb.drv}
%</driver>
%<package>\ProvidesPackage{gensymb}
  [2003/07/02 v1.0 (WaS)]
%<*driver>
\documentclass{ltxdoc}
\OnlyDescription
\usepackage{textcomp}
\CodelineNumbered
\begin{document}
 \DocInput{gensymb.dtx}
\end{document}
%</driver>
% \fi
%
% \newcommand\Lopt[1]{\textsf{#1}}
% \let\Lpack\Lopt
% \GetFileInfo{gensymb.drv}
%
% \title{The \textsf{gensymb} package for \LaTeXe}
% \author{Walter Schmidt\thanks{{\ttfamily w.a.schmidt@gmx.net}}}
% \date{(\fileversion{} -- \filedate)}
% \maketitle
% \sloppy
%
% \section{The problem}
% Typesetting units of measurement with \LaTeX{} is sometimes difficult.
% Why?  For instance, most (but no all) typefaces have an 
% upright \textmu{} and also a degree symbol, but
% there is no obvious way to use these in math mode.  On the other hand,
% an upright \textohm{} is part of all math fonts for \TeX,
% but most text fonts are lacking the corresponding \cmd{\textohm}.  
% Thus, it is not only impossible to use the
% same notation in text and in formulas;
% depending on the fonts used, it may even be impossible to
% typeset units properly at all, if you are restricted to 
% the means of `standard' \LaTeX.
%
% \section{The macro package}
% The \Lpack{gensymb} package provides a number of `generic' macros,
% which produce the same output in text and math mode:
% \begin{verse}
% \begin{tabular}{ccccc}
%   \cmd{\degree}     &    
%   \cmd{\celsius}    &    
%   \cmd{\perthousand}& 
%   \cmd{\ohm}        &
%   \cmd{\micro}      \\
%   \textdegree       &
%   \textcelsius      &
%   \textperthousand  &
%   \textohm          &
%   \textmu          \\           
% \end{tabular}
% \end{verse}
% Thus, you can write, for instance:
% \begin{verse}
% |$ \lambda = 10.6\,\micro\mathrm{m} $|\\
% |... a wavelength of 10.6\,\micro m|
% \end{verse}
% With the help of the package \Lpack{units}, you can even apply 
% exactly the same notation in text and formulas:
% \begin{verse}
% |$ \lambda = \unit[10.6]{\micro m} $|\\
% |... a wavelength of \unit[10.6]{\micro m}|
% \end{verse}
%
% Under normal circumstances  you should use \Lpack{gensymb} in conjunction with
% the \Lpack{textcomp} package.  In this case the above symbols
% are taken from a text font using the  TS1 (text companion) 
% encoding -- even in math. 
% As a result, they will exhibit the style of the surrounding text or of the \cmd{\mathrm}
% alphabet, respectively.
%
% When \Lpack{textcomp} is \emph{not} used (for instance, because your text fonts 
% are not available with TS1 encoding), 
% the \Lpack{gensymb} package tries to emulate the above symbols
% using what is available in the math fonts.   
% However, the symbols \textmu{} and \textperthousand{} cannot be faked,
% and the package will issue appropriate warning messages.  
% The option \Lopt{upmu} is a workaround to provide at least the \textmu{} -- see below.
% 
% The symbol \cmd{\ohm} is particular, too:  Loading the \Lpack{textcomp}
% package does \emph{not ensure} that the text fonts actually include
% an \textohm.  Unfortunately, many fonts don't.  \LaTeX{} cannot detect this
% situation in advance, and the command \cmd{\ohm} will print some garbage
% then -- possibly without any error message.
% A workaround is to use the options \Lopt{Omega} or \Lopt{Upomega}
% described below.  
%
% The default behavior of the \Lpack{gensymb} package can be modified
% using the following options:
% \begin{description} 
% \item[\Lopt{upmu}] With this option, the \cmd{\micro} uses internally 
% a math symbol with the name \cmd{\upmu}.
% The responsibility to provide this macro lies with you; for instance,
% load the package \Lpack{upgreek}\footnote{%
% available from the same CTAN directory as \Lpack{gensymb}} or use a set
% of math fonts which include an upright mu and make sure it is accessible as \cmd{\upmu}.
% This option is useful, 
% when your text fonts are not available with TS1 (text companion) encoding, 
% or when their \cmd{\textmu} is  ugly or broken.  The drawback is, 
% that the style of this \textmu{} will not vary with the surrounding font.
% It is always upright  roman, regardless of whether 
% the surrounding text is  sans serif, bold or whatever.
%
% \item[\Lopt{Omega}] makes \cmd{\ohm} always use the upright Greek Omega
% from the current math font, regardless of whether \Lpack{textcomp} is loaded.
% This makes sense, when there is no \textohm{} in your text font(s).
% The option works always, but the style of the  Omega in text will
% not vary then.
%
% Various packages provide an option \Lopt{slantedGreek} to make
% uppercase Greek letters in formulas slanted.  You may safely use 
% this option in conjunction with the \Lopt{Omega} option of the package
% \Lpack{gensymb}: \cmd{\ohm} will be upright, though!
% 
% \addtocounter{footnote}{-1}
% \item[\Lpack{Upomega}] A math symbol with the name \cmd{\Upomega} will
% be used to for the \cmd{\ohm}.
% The responsibility to provide this macro lies with you; for instance,
% load the package \Lpack{upgreek}\footnotemark.
% Again, the style of this \cmd{\ohm} in text never changes.  
% The option may be useful, when the text font does not include a \cmd{\textomega}
% of its own and the mathematical \cmd{\Omega} is not a suitable substitute,
% for one reason or another.
% \end{description}
% 
% \section{Examples}
% \subsection*{The optimum case}
% With text fonts providing \textmu{} as well as \textohm{}
% in the text companion encoding, the default behavior of 
% \Lpack{gensymb} is appropriate.
% This holds, e.g., for the EC/TC fonts (i.e., Computer Modern with T1 
% and TS1 encoding), Palatino, Lucida Bright, the Fourier fonts, 
% and most font families from MicroPress:
% \begin{verbatim}
% \usepackage[T1]{fontenc}
% \usepackage{textcomp}
% \usepackage{gensymb}
% \end{verbatim}
%
% \subsection*{The normal case}
% Many commercial text fonts have a correct `micro' symbol, but no Omega.
% In this case the package can be loaded with the \Lopt{Omega} option,
% to make sure that the mathematical Omega is used instead:
% \begin{verbatim}
% \usepackage[T1]{fontenc}
% \usepackage{textcomp}
% \usepackage{mathptmx} % for instance
% \usepackage[Omega]{gensymb}
% \end{verbatim}
% 
% \subsection*{Using the `classical' CM fonts}
% When you are restricted to the classical Computer Modern fonts with
% OT1 encoding, you can still take the Omega from the math fonts,
% but you need to take the upright mu from an an extra font such as
% Euler Roman.
% Notice, however, that \cmd{\perthousand} is not made available.
% You may try \cmd{\permil} instead, which is provided in the
% WASY fonts.
% \begin{verbatim}
% \usepackage[Euler]{upgreek}
% \usepackage[Omega, upmu]{gensymb}
% \usepackage{wasysym}
% \let\perthousand=\permil
% \end{verbatim}
%
% \subsection*{A special case}
% Imagine that you are using the Bitstream Charter text fonts 
% in conjunction with Euler-VM for math.\footnote{I do not actually
% recommend this combination\dots}
% Charter, like most typefaces from Bitstream, has a wrong mu symbol.
% The missing Omega could be taken from the math font (Euler), but it would not go well 
% with  Charter  in a combination such as M$\Omega$.
% As a workaround, load the \Lpack{upgreek} package 
% and take both \cmd{\micro} and \cmd{\ohm} from the `Adobe Symbol' font:
% \begin{verbatim}
% \usepackage[T1]{fontenc}
% \usepackage{textcomp}
% \usepackage{charter,eulervm}
% \usepackage[Symbol]{upgreek}
% \usepackage[Upomega, upmu]{gensymb}
% \end{verbatim}
%
% \section{Using \Lpack{gensymb} together with other packages}
% \begin{itemize}
% \item
% \Lpack{gensymb} goes well with the package \Lpack{units},
% but it cannot be used in conjunction with the
% package \Lpack{SIunits}, because the latter has its own means to typeset
% prefixes.
% \item
% Using the package \Lpack{mathcomp} together with \Lpack{gensymb}
% is possible, if you need the additional `math companion' symbols.
% Both packages will use only one common math symbol font.
% \end{itemize}
%
% \section{Known deficiencies}
% The current version of the package does not work properly 
% in conjunction with the LY1 font encoding.
% This will possibly be fixed in a future release, if there is an actual need.
%
% \StopEventually{}
% 
% \section{Implementation}
% 
% The options are implemented using switches:
%    \begin{macrocode}
%<*package>
\newif\ifgns@Upomega
\newif\ifgns@Omega
\newif\ifgns@upmu
%    \end{macrocode}
%    \begin{macrocode}
\DeclareOption{Upomega}{\gns@Upomegatrue}
\DeclareOption{Omega}{\gns@Omegatrue}
\DeclareOption{upmu}{\gns@upmutrue}
\ProcessOptions\relax
%    \end{macrocode}
% These are the generic commands:
%    \begin{macrocode}
\newcommand\celsius{}
\newcommand\degree{}
\newcommand\ohm{}
%    \end{macrocode}
% The following macros will be used later to actually define the generic commands.
% We start with a macro to fake \cmd{\degree} and \cmd{\celsius} and to generate
% a warning message for \cmd{\perthousand}:
%    \begin{macrocode}
\def\gns@usefakedsymbols{%
\renewcommand{\degree}{\ensuremath{^\circ}}
\DeclareRobustCommand{\celsius}{%
  \ifmmode^\circ\mathrm{C}\else$^\circ$C\fi}
\PackageInfo{gensymb}{%
  Faking symbols for \protect\degree\space and \protect\celsius}
\PackageWarningNoLine{gensymb}{%
  Not defining \protect\perthousand}
}
%    \end{macrocode}
% The following macro sets up a SymbolFont for the text companion symbols to be
% used in math.  If \cmd{\tcmu} is already defined, we assume that the
% \Lpack{mathcomp} package is already loaded, and that the `math companion'
% symbols need not be defined once again:
%    \begin{macrocode}
\def\gns@setupmathcomp{%
\expandafter\ifx\csname tcmu\endcsname\relax
  \DeclareSymbolFont{gns@font}{TS1}{\familydefault}{m}{n}
  \ifx\mv@bold\@undefined\else  
    \SetSymbolFont{gns@font}{bold}{TS1}{\familydefault}{\bfdefault}{n}
  \fi
  \DeclareMathSymbol{\tccelsius}{\mathord}{gns@font}{137}     % {'211}
  \DeclareMathSymbol{\tcdegree}{\mathord}{gns@font}{176}      % {'260}
  \DeclareMathSymbol{\tcperthousand}{\mathord}{gns@font}{135} % {'207}
  \DeclareMathSymbol{\tcmu}{\mathord}{gns@font}{181}          % {'265}
  \DeclareMathSymbol{\tcohm}{\mathord}{gns@font}{87}          % {'127}
  \PackageInfo{gensymb}{Math companion symbols declared}
\else
  \PackageInfo{gensymb}{Math companion symbols found}
\fi
}
%    \end{macrocode}
% A macro to define \cmd{\degree}, \cmd{\celsius} and \cmd{\perthousand}
% so as to use text companion  symbols:
%    \begin{macrocode}
\def\gns@usetcsymbols{%
\DeclareRobustCommand{\degree}{%
  \ifmmode\tcdegree\else\textdegree\fi}
\DeclareRobustCommand{\celsius}{%
  \ifmmode\tccelsius\else\textcelsius\fi}
\DeclareRobustCommand{\perthousand}{%
  \ifmmode\tcperthousand\else\textperthousand\fi}
\PackageInfo{gensymb}{Using text companion symbols for %
  \protect\degree, \protect\celsius\space and \protect\perthousand}
}
%    \end{macrocode}
%  A macro to define \cmd{\ohm} so as to use the math symbol \cmd{\Upomega}:
%    \begin{macrocode}
\def\gns@useUpomega{%
  \expandafter\ifx\csname Upomega\endcsname\relax
    \PackageError{gensymb}
    {You have requested the option Upomega,\MessageBreak
    but the command \protect\Upomega\space is undefined}
    {Load the upgreek package additionally and try again!}
  \fi
  \DeclareRobustCommand{\ohm}{\ifmmode\Upomega\else$\Upomega$\fi}
  \PackageInfo{gensymb}{Using \protect\Upomega\space for \protect\ohm}
}
%    \end{macrocode}
%  A macro to define \cmd{\ohm} so as to use \cmd{\Omega} (or \cmd{\upOmega},
%  if it is provided):
%    \begin{macrocode}
\def\gns@useOmega{%
  \expandafter\ifx\csname upOmega\endcsname\relax
   \DeclareRobustCommand{\ohm}{\ifmmode\Omega\else$\Omega$\fi}
   \PackageInfo{gensymb}{Using \protect\Omega\space for \protect\ohm}
  \else
   \DeclareRobustCommand{\ohm}{\ifmmode\upOmega\else$\upOmega$\fi}
   \PackageInfo{gensymb}{Using \protect\upOmega\space for \protect\ohm}
  \fi
}
%    \end{macrocode}
%  A macro to define \cmd{\ohm} so as to use the text companion symbol:
%    \begin{macrocode}
\def\gns@usetextohm{%
  \DeclareRobustCommand{\ohm}{\ifmmode\tcohm\else\textohm\fi}
  \PackageInfo{gensymb}{Using \protect\textohm\space for \protect\ohm}
}
%    \end{macrocode}
%  A macro to define \cmd{\micro} so as to use the math symbol \cmd{\upmu}:
%    \begin{macrocode}
\def\gns@useupmu{%
  \expandafter\ifx\csname upmu\endcsname\relax
    \PackageError{gensymb}
    {You have requested the option upmu,\MessageBreak
    but the command \protect\upmu\space is undefined}
    {Load the upgreek package additionally and try again!}
  \fi
  \DeclareRobustCommand{\micro}{\ifmmode\upmu\else$\upmu$\fi}
  \PackageInfo{gensymb}{Using \protect\upmu\space for \protect\micro}
}
%    \end{macrocode}
%  A macro to define \cmd{\micro} so as to use the text companion symbol:
%    \begin{macrocode}
\def\gns@usetextmu{%
  \DeclareRobustCommand{\micro}{\ifmmode\tcmu\else\textmu\fi}
  \PackageInfo{gensymb}{Using \protect\textmu\space for \protect\micro}
}
%    \end{macrocode}
%  A macro to issue a warning, if \cmd{\micro} cannot be made available:
%    \begin{macrocode}
\def\gns@usenomu{%
  \PackageWarningNoLine{gensymb}{%
    Not defining \protect\micro}
}
%    \end{macrocode}
% The actual work is executed AtBeginDocument, so that we can detect the
% presence of the \Lpack{textcomp} package and the availability of
% \cmd{\Upmu} and other commands, regardless of the sequence of loading the
% packages.
%    \begin{macrocode}
\AtBeginDocument{%
%    \end{macrocode}
% First, we check for \Lpack{textcomp}.  If it is loaded, we set up the
% text companion symbols for use in math and define \cmd{\degree}, \cmd{\celsius} 
% and \cmd{\perthousand} so that they use these. Otherwise, the symbols are faked
% as far as possible:
%    \begin{macrocode}
\@ifpackageloaded{textcomp}{\gns@setupmathcomp\gns@usetcsymbols}%
  {\gns@usefakedsymbols}
%    \end{macrocode}
% Now we define \cmd{\ohm}.  In case the options \Lopt{Upomega}
% or \Lopt{Omega} have been specified, behave acordingly.
% Otherwise, use the text companion symbol, if available.
% Default is to use the mathematical Omega:
%    \begin{macrocode}
\ifgns@Upomega
  \gns@useUpomega
\else
\ifgns@Omega
  \gns@useOmega
\else
\@ifpackageloaded{textcomp}%
  {\gns@usetextohm}%
  {\gns@useOmega}
\fi\fi
%    \end{macrocode}
% Next, define \cmd{\micro}. In case the option \Lopt{upmu}
% has been specified, behave acordingly.
% Otherwise, use the text companion symbol, if available.
% Default is not to provide \cmd{\micro} at all.
%    \begin{macrocode}
\ifgns@upmu
  \gns@useupmu
\else
\@ifpackageloaded{textcomp}%
  {\gns@usetextmu}%
  {\gns@usenomu}
\fi
%    \end{macrocode}
% Finally, we destroy the commands that are no longer needed:
%    \begin{macrocode}
\let\gns@usefakedsymbols\relax
\let\gns@setupmathcomp\relax
\let\gns@usetcsymbols\relax
\let\gns@useUpomega\relax
\let\gns@useOmega\relax
\let\gns@usetextohm\relax
\let\gns@useupmu\relax
\let\gns@usenomu\relax
\let\gns@usetextmu\relax
%    \end{macrocode}
%    \begin{macrocode}
}
%</package>
%    \end{macrocode}
%
% The next line of code is only to prevent DocStrip from adding the
% character table to all modules:
%    \begin{macrocode}
\endinput
%    \end{macrocode}
% \Finale
%% \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         \~}
%%