Debian Codegraph @

texmf-dist/source/latex/gensymb/gensymb.dtx

raw
1 %\CheckSum{283}
2 %
3 % \iffalse
4 %
5 %% gensymb.dtx
6 % Copyright (c) 2005--2022 Walter Schmidt
7 % Copyright (c) 2022-- Keiran Harcombe
8 %
9 % This work may be distributed and/or modified under the
10 % conditions of the LaTeX Project Public License, either version 1.3
11 % of this license or (at your option) any later version.
12 % The latest version of this license is in
13 % http://www.latex-project.org/lppl.txt
14 % and version 1.3 or later is part of all distributions of LaTeX
15 % version 2005/12/01 or later.
16 %
17 % This work has the LPPL maintenance status `maintained'.
18 %
19 % The Current Maintainer of this work is Keiran Harcombe
20 %
21 % This work consists of the files gensymb.dtx, gensymb.ins
22 % and the derived file gensymb.sty.%
23 % \fi
24 %
25 % \iffalse
26 %
27 %<*driver>
28 \ProvidesFile{gensymb.drv}
29 %</driver>
30 %<package>\ProvidesPackage{gensymb}
31 [2022/10/17 v1.0.2 (KJH)]
32 %<*driver>
33 \documentclass{ltxdoc}
34 \OnlyDescription
35 \usepackage{textcomp}
36 \CodelineNumbered
37 \begin{document}
38 \DocInput{gensymb.dtx}
39 \end{document}
40 %</driver>
41 % \fi
42 %
43 % \newcommand\Lopt[1]{\textsf{#1}}
44 % \let\Lpack\Lopt
45 % \GetFileInfo{gensymb.drv}
46 %
47 % \title{The \textsf{gensymb} package for \LaTeXe}
48 % \author{Walter Schmidt & Keiran Harcombe\thanks{{\ttfamily [email protected]}}}
49 % \date{(\fileversion{} -- \filedate)}
50 % \maketitle
51 % \sloppy
52 %
53 % \section{The problem}
54 % Typesetting units of measurement with \LaTeX{} is sometimes difficult.
55 % Why? For instance, most (but no all) typefaces have an
56 % upright \textmu{} and also a degree symbol, but
57 % there is no obvious way to use these in math mode. On the other hand,
58 % an upright \textohm{} is part of all math fonts for \TeX,
59 % but most text fonts are lacking the corresponding \cmd{\textohm}.
60 % Thus, it is not only impossible to use the
61 % same notation in text and in formulas;
62 % depending on the fonts used, it may even be impossible to
63 % typeset units properly at all, if you are restricted to
64 % the means of `standard' \LaTeX.
65 %
66 % \section{The macro package}
67 % The \Lpack{gensymb} package provides a number of `generic' macros,
68 % which produce the same output in text and math mode:
69 % \begin{verse}
70 % \begin{tabular}{ccccc}
71 % \cmd{\degree} &
72 % \cmd{\celsius} &
73 % \cmd{\perthousand}&
74 % \cmd{\ohm} &
75 % \cmd{\micro} \\
76 % \textdegree &
77 % \textcelsius &
78 % \textperthousand &
79 % \textohm &
80 % \textmu \\
81 % \end{tabular}
82 % \end{verse}
83 % Thus, you can write, for instance:
84 % \begin{verse}
85 % |$ \lambda = 10.6\,\micro\mathrm{m} $|\\
86 % |... a wavelength of 10.6\,\micro m|
87 % \end{verse}
88 % With the help of the package \Lpack{units}, you can even apply
89 % exactly the same notation in text and formulas:
90 % \begin{verse}
91 % |$ \lambda = \unit[10.6]{\micro m} $|\\
92 % |... a wavelength of \unit[10.6]{\micro m}|
93 % \end{verse}
94 %
95 % Under normal circumstances you should use \Lpack{gensymb} in conjunction with
96 % the \Lpack{textcomp} package. In this case the above symbols
97 % are taken from a text font using the TS1 (text companion)
98 % encoding -- even in math.
99 % As a result, they will exhibit the style of the surrounding text or of the \cmd{\mathrm}
100 % alphabet, respectively.
101 %
102 % When \Lpack{textcomp} is \emph{not} used (for instance, because your text fonts
103 % are not available with TS1 encoding),
104 % the \Lpack{gensymb} package tries to emulate the above symbols
105 % using what is available in the math fonts.
106 % However, the symbols \textmu{} and \textperthousand{} cannot be faked,
107 % and the package will issue appropriate warning messages.
108 % The option \Lopt{upmu} is a workaround to provide at least the \textmu{} -- see below.
109 %
110 % The symbol \cmd{\ohm} is particular, too: Loading the \Lpack{textcomp}
111 % package does \emph{not ensure} that the text fonts actually include
112 % an \textohm. Unfortunately, many fonts don't. \LaTeX{} cannot detect this
113 % situation in advance, and the command \cmd{\ohm} will print some garbage
114 % then -- possibly without any error message.
115 % A workaround is to use the options \Lopt{Omega} or \Lopt{Upomega}
116 % described below.
117 %
118 % The default behavior of the \Lpack{gensymb} package can be modified
119 % using the following options:
120 % \begin{description}
121 % \item[\Lopt{upmu}] With this option, the \cmd{\micro} uses internally
122 % a math symbol with the name \cmd{\upmu}.
123 % The responsibility to provide this macro lies with you; for instance,
124 % load the package \Lpack{upgreek}\footnote{%
125 % available from the same CTAN directory as \Lpack{gensymb}} or use a set
126 % of math fonts which include an upright mu and make sure it is accessible as \cmd{\upmu}.
127 % This option is useful,
128 % when your text fonts are not available with TS1 (text companion) encoding,
129 % or when their \cmd{\textmu} is ugly or broken. The drawback is,
130 % that the style of this \textmu{} will not vary with the surrounding font.
131 % It is always upright roman, regardless of whether
132 % the surrounding text is sans serif, bold or whatever.
133 %
134 % \item[\Lopt{Omega}] makes \cmd{\ohm} always use the upright Greek Omega
135 % from the current math font, regardless of whether \Lpack{textcomp} is loaded.
136 % This makes sense, when there is no \textohm{} in your text font(s).
137 % The option works always, but the style of the Omega in text will
138 % not vary then.
139 %
140 % Various packages provide an option \Lopt{slantedGreek} to make
141 % uppercase Greek letters in formulas slanted. You may safely use
142 % this option in conjunction with the \Lopt{Omega} option of the package
143 % \Lpack{gensymb}: \cmd{\ohm} will be upright, though!
144 %
145 % \addtocounter{footnote}{-1}
146 % \item[\Lpack{Upomega}] A math symbol with the name \cmd{\Upomega} will
147 % be used to for the \cmd{\ohm}.
148 % The responsibility to provide this macro lies with you; for instance,
149 % load the package \Lpack{upgreek}\footnotemark.
150 % Again, the style of this \cmd{\ohm} in text never changes.
151 % The option may be useful, when the text font does not include a \cmd{\textomega}
152 % of its own and the mathematical \cmd{\Omega} is not a suitable substitute,
153 % for one reason or another.
154 % \end{description}
155 %
156 % \section{Examples}
157 % \subsection*{The optimum case}
158 % With text fonts providing \textmu{} as well as \textohm{}
159 % in the text companion encoding, the default behavior of
160 % \Lpack{gensymb} is appropriate.
161 % This holds, e.g., for the EC/TC fonts (i.e., Computer Modern with T1
162 % and TS1 encoding), Palatino, Lucida Bright, the Fourier fonts,
163 % and most font families from MicroPress:
164 % \begin{verbatim}
165 % \usepackage[T1]{fontenc}
166 % \usepackage{textcomp}
167 % \usepackage{gensymb}
168 % \end{verbatim}
169 %
170 % \subsection*{The normal case}
171 % Many commercial text fonts have a correct `micro' symbol, but no Omega.
172 % In this case the package can be loaded with the \Lopt{Omega} option,
173 % to make sure that the mathematical Omega is used instead:
174 % \begin{verbatim}
175 % \usepackage[T1]{fontenc}
176 % \usepackage{textcomp}
177 % \usepackage{mathptmx} % for instance
178 % \usepackage[Omega]{gensymb}
179 % \end{verbatim}
180 %
181 % \subsection*{Using the `classical' CM fonts}
182 % When you are restricted to the classical Computer Modern fonts with
183 % OT1 encoding, you can still take the Omega from the math fonts,
184 % but you need to take the upright mu from an an extra font such as
185 % Euler Roman.
186 % Notice, however, that \cmd{\perthousand} is not made available.
187 % You may try \cmd{\permil} instead, which is provided in the
188 % WASY fonts.
189 % \begin{verbatim}
190 % \usepackage[Euler]{upgreek}
191 % \usepackage[Omega, upmu]{gensymb}
192 % \usepackage{wasysym}
193 % \let\perthousand=\permil
194 % \end{verbatim}
195 %
196 % \subsection*{A special case}
197 % Imagine that you are using the Bitstream Charter text fonts
198 % in conjunction with Euler-VM for math.\footnote{I do not actually
199 % recommend this combination\dots}
200 % Charter, like most typefaces from Bitstream, has a wrong mu symbol.
201 % The missing Omega could be taken from the math font (Euler), but it would not go well
202 % with Charter in a combination such as M$\Omega$.
203 % As a workaround, load the \Lpack{upgreek} package
204 % and take both \cmd{\micro} and \cmd{\ohm} from the `Adobe Symbol' font:
205 % \begin{verbatim}
206 % \usepackage[T1]{fontenc}
207 % \usepackage{textcomp}
208 % \usepackage{charter,eulervm}
209 % \usepackage[Symbol]{upgreek}
210 % \usepackage[Upomega, upmu]{gensymb}
211 % \end{verbatim}
212 %
213 % \section{Using \Lpack{gensymb} together with other packages}
214 % \begin{itemize}
215 % \item
216 % \Lpack{gensymb} goes well with the package \Lpack{units},
217 % but it cannot be used in conjunction with the
218 % package \Lpack{SIunits}, because the latter has its own means to typeset
219 % prefixes.
220 % \item
221 % Using the package \Lpack{mathcomp} together with \Lpack{gensymb}
222 % is possible, if you need the additional `math companion' symbols.
223 % Both packages will use only one common math symbol font.
224 % \end{itemize}
225 %
226 % \section{Known deficiencies}
227 % The current version of the package does not work properly
228 % in conjunction with the LY1 font encoding.
229 % This will possibly be fixed in a future release, if there is an actual need.
230 %
231 % \StopEventually{}
232 %
233 % \section{Implementation}
234 %
235 % The options are implemented using switches:
236 % \begin{macrocode}
237 %<*package>
238 \newif\ifgns@Upomega
239 \newif\ifgns@Omega
240 \newif\ifgns@upmu
241 % \end{macrocode}
242 % \begin{macrocode}
243 \DeclareOption{Upomega}{\gns@Upomegatrue}
244 \DeclareOption{Omega}{\gns@Omegatrue}
245 \DeclareOption{upmu}{\gns@upmutrue}
246 \ProcessOptions\relax
247 % \end{macrocode}
248 % These are the generic commands:
249 % \begin{macrocode}
250 \newcommand\celsius{}
251 \newcommand\degree{}
252 \newcommand\ohm{}
253 % \end{macrocode}
254 % The following macros will be used later to actually define the generic commands.
255 % We start with a macro to fake \cmd{\degree} and \cmd{\celsius} and to generate
256 % a warning message for \cmd{\perthousand}:
257 % \begin{macrocode}
258 \def\gns@usefakedsymbols{%
259 \renewcommand{\degree}{\ensuremath{^\circ}}
260 \DeclareRobustCommand{\celsius}{%
261 \ifmmode^\circ\mathrm{C}\else$^\circ$C\fi}
262 \PackageInfo{gensymb}{%
263 Faking symbols for \protect\degree\space and \protect\celsius}
264 \PackageWarningNoLine{gensymb}{%
265 Not defining \protect\perthousand}
266 }
267 % \end{macrocode}
268 % The following macro sets up a SymbolFont for the text companion symbols to be
269 % used in math. If \cmd{\tcmu} is already defined, we assume that the
270 % \Lpack{mathcomp} package is already loaded, and that the `math companion'
271 % symbols need not be defined once again:
272 % \begin{macrocode}
273 \def\gns@setupmathcomp{%
274 \expandafter\ifx\csname tcmu\endcsname\relax
275 \DeclareSymbolFont{gns@font}{TS1}{\familydefault}{m}{n}
276 \ifx\mv@bold\@undefined\else
277 \SetSymbolFont{gns@font}{bold}{TS1}{\familydefault}{\bfdefault}{n}
278 \fi
279 \DeclareMathSymbol{\tccelsius}{\mathord}{gns@font}{137} % {'211}
280 \DeclareMathSymbol{\tcdegree}{\mathord}{gns@font}{176} % {'260}
281 \DeclareMathSymbol{\tcperthousand}{\mathord}{gns@font}{135} % {'207}
282 \DeclareMathSymbol{\tcmu}{\mathord}{gns@font}{181} % {'265}
283 \DeclareMathSymbol{\tcohm}{\mathord}{gns@font}{87} % {'127}
284 \PackageInfo{gensymb}{Math companion symbols declared}
285 \else
286 \PackageInfo{gensymb}{Math companion symbols found}
287 \fi
288 }
289 % \end{macrocode}
290 % A macro to define \cmd{\degree}, \cmd{\celsius} and \cmd{\perthousand}
291 % so as to use text companion symbols:
292 % \begin{macrocode}
293 \def\gns@usetcsymbols{%
294 \DeclareRobustCommand{\degree}{%
295 \ifmmode\tcdegree\else\textdegree\fi}
296 \DeclareRobustCommand{\celsius}{%
297 \ifmmode\tccelsius\else\textcelsius\fi}
298 \DeclareRobustCommand{\perthousand}{%
299 \ifmmode\tcperthousand\else\textperthousand\fi}
300 \PackageInfo{gensymb}{Using text companion symbols for %
301 \protect\degree, \protect\celsius\space and \protect\perthousand}
302 }
303 % \end{macrocode}
304 % A macro to define \cmd{\ohm} so as to use the math symbol \cmd{\Upomega}:
305 % \begin{macrocode}
306 \def\gns@useUpomega{%
307 \expandafter\ifx\csname Upomega\endcsname\relax
308 \PackageError{gensymb}
309 {You have requested the option Upomega,\MessageBreak
310 but the command \protect\Upomega\space is undefined}
311 {Load the upgreek package additionally and try again!}
312 \fi
313 \DeclareRobustCommand{\ohm}{\ifmmode\Upomega\else$\Upomega$\fi}
314 \PackageInfo{gensymb}{Using \protect\Upomega\space for \protect\ohm}
315 }
316 % \end{macrocode}
317 % A macro to define \cmd{\ohm} so as to use \cmd{\Omega} (or \cmd{\upOmega},
318 % if it is provided):
319 % \begin{macrocode}
320 \def\gns@useOmega{%
321 \expandafter\ifx\csname upOmega\endcsname\relax
322 \DeclareRobustCommand{\ohm}{\ifmmode\Omega\else$\Omega$\fi}
323 \PackageInfo{gensymb}{Using \protect\Omega\space for \protect\ohm}
324 \else
325 \DeclareRobustCommand{\ohm}{\ifmmode\upOmega\else$\upOmega$\fi}
326 \PackageInfo{gensymb}{Using \protect\upOmega\space for \protect\ohm}
327 \fi
328 }
329 % \end{macrocode}
330 % A macro to define \cmd{\ohm} so as to use the text companion symbol:
331 % \begin{macrocode}
332 \def\gns@usetextohm{%
333 \DeclareRobustCommand{\ohm}{\ifmmode\tcohm\else\textohm\fi}
334 \PackageInfo{gensymb}{Using \protect\textohm\space for \protect\ohm}
335 }
336 % \end{macrocode}
337 % A macro to define \cmd{\micro} so as to use the math symbol \cmd{\upmu}:
338 % \begin{macrocode}
339 \def\gns@useupmu{%
340 \expandafter\ifx\csname upmu\endcsname\relax
341 \PackageError{gensymb}
342 {You have requested the option upmu,\MessageBreak
343 but the command \protect\upmu\space is undefined}
344 {Load the upgreek package additionally and try again!}
345 \fi
346 \DeclareRobustCommand{\micro}{\ifmmode\upmu\else$\upmu$\fi}
347 \PackageInfo{gensymb}{Using \protect\upmu\space for \protect\micro}
348 }
349 % \end{macrocode}
350 % A macro to define \cmd{\micro} so as to use the text companion symbol:
351 % \begin{macrocode}
352 \def\gns@usetextmu{%
353 \DeclareRobustCommand{\micro}{\ifmmode\tcmu\else\textmu\fi}
354 \PackageInfo{gensymb}{Using \protect\textmu\space for \protect\micro}
355 }
356 % \end{macrocode}
357 % A macro to issue a warning, if \cmd{\micro} cannot be made available:
358 % \begin{macrocode}
359 \def\gns@usenomu{%
360 \PackageWarningNoLine{gensymb}{%
361 Not defining \protect\micro}
362 }
363 % \end{macrocode}
364 % The actual work is executed AtBeginDocument, so that we can detect the
365 % presence of the \Lpack{textcomp} package and the availability of
366 % \cmd{\Upmu} and other commands, regardless of the sequence of loading the
367 % packages.
368 % \begin{macrocode}
369 \AtBeginDocument{%
370 % \end{macrocode}
371 % First, we check for \Lpack{textcomp}. If it is loaded, we set up the
372 % text companion symbols for use in math and define \cmd{\degree}, \cmd{\celsius}
373 % and \cmd{\perthousand} so that they use these. Otherwise, the symbols are faked
374 % as far as possible:
375 % \begin{macrocode}
376 \@ifpackageloaded{textcomp}{\gns@setupmathcomp\gns@usetcsymbols}%
377 {\gns@usefakedsymbols}
378 % \end{macrocode}
379 % Now we define \cmd{\ohm}. In case the options \Lopt{Upomega}
380 % or \Lopt{Omega} have been specified, behave acordingly.
381 % Otherwise, use the text companion symbol, if available.
382 % Default is to use the mathematical Omega:
383 % \begin{macrocode}
384 \ifgns@Upomega
385 \gns@useUpomega
386 \else
387 \ifgns@Omega
388 \gns@useOmega
389 \else
390 \@ifpackageloaded{textcomp}%
391 {\gns@usetextohm}%
392 {\gns@useOmega}
393 \fi\fi
394 % \end{macrocode}
395 % Next, define \cmd{\micro}. In case the option \Lopt{upmu}
396 % has been specified, behave acordingly.
397 % Otherwise, use the text companion symbol, if available.
398 % Default is not to provide \cmd{\micro} at all.
399 % \begin{macrocode}
400 \ifgns@upmu
401 \gns@useupmu
402 \else
403 \@ifpackageloaded{textcomp}%
404 {\gns@usetextmu}%
405 {\gns@usenomu}
406 \fi
407 % \end{macrocode}
408 % Finally, we destroy the commands that are no longer needed:
409 % \begin{macrocode}
410 \let\gns@usefakedsymbols\relax
411 \let\gns@setupmathcomp\relax
412 \let\gns@usetcsymbols\relax
413 \let\gns@useUpomega\relax
414 \let\gns@useOmega\relax
415 \let\gns@usetextohm\relax
416 \let\gns@useupmu\relax
417 \let\gns@usenomu\relax
418 \let\gns@usetextmu\relax
419 % \end{macrocode}
420 % \begin{macrocode}
421 }
422 %</package>
423 % \end{macrocode}
424 %
425 % The next line of code is only to prevent DocStrip from adding the
426 % character table to all modules:
427 % \begin{macrocode}
428 \endinput
429 % \end{macrocode}
430 % \Finale
431 %% \CharacterTable
432 %% {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
433 %% 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
434 %% Digits \0\1\2\3\4\5\6\7\8\9
435 %% Exclamation \! Double quote \" Hash (number) \#
436 %% Dollar \$ Percent \% Ampersand \&
437 %% Acute accent \' Left paren \( Right paren \)
438 %% Asterisk \* Plus \+ Comma \,
439 %% Minus \- Point \. Solidus \/
440 %% Colon \: Semicolon \; Less than \<
441 %% Equals \= Greater than \> Question mark \?
442 %% Commercial at \@ Left bracket \[ Backslash \\
443 %% Right bracket \] Circumflex \^ Underscore \_
444 %% Grave accent \` Left brace \{ Vertical bar \|
445 %% Right brace \} Tilde \~}
446 %%