The gensymb package for L^{A}TEX 2ε

Walter Schmidt^{∗}

(v0.99 – 2003/02/12)

1 The problem

Typesetting units of measurement with L^{A}TEX is sometimes difficult. Why? For instance, most typefaces have an upright µ and also a degree symbol, but there is no obvious way to use these in math mode. On the other hand, an upright � is part of all math fonts for TEX, but most text fonts are lacking the corresponding \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’ L^{A}TEX.

2 The macro package

The gensymb package provides a number of ‘generic’ macros, which produce the same output in text and math mode:

    \degree  \celsius  \perthousand  \ohm  \micro

°  �  ‰  �  µ

Thus, you can write, for instance,

     $ \lambda = 10.6\,\micro\mathrm{m} $
     ... a wavelength of 10.6\,\micro m

or, with the help of the package units:

     $ \lambda = \unit[10.6]{\micro m} $
     ... a wavelength of \unit[10.6]{\micro m}

Notice that the notation in text and math mode is the same!

Normally, you should use gensymb in conjunction with the textcomp package. In this case the above symbols are taken from a text font using the TS1 (text companion) encoding—even in math. Thus, they will always exhibit the style of the surrounding text or of the \mathrm alphabet, respectively.

If you do not use textcomp (for instance, because your text fonts are not available with TS1 encoding), the gensymb package will try to emulate the above symbols, using what is available the math fonts. However, the symbols µ and ‰ will not be made available, because they cannot be faked. The package will issue appropriate warning messages in this case. A workaround to provide at least the µ is the option upmu; see below.

∗w-a-schmidt@arcor.de

The symbol \ohm is particular, too: Loading the textcomp package does not ensure that the text fonts actually include an �. Unfortunately, most fonts don’t. L^{A}TEX cannot detect this situation in advance, and the command \ohm will print a black square or something similar then—most likely, without any error message. A workaround is to use the options Omega or Upomega described below.

The default behavior of the gensymb package can be modified through the following options:

upmu With this option, the \micro uses internally a math symbol with the name \upmu. You must additionally load the package upgreek^{1} to provide it (or define \upmu yourself). This option is useful, if your text fonts are not available with TS1 (text companion) encoding, or if their \textmu is ugly or broken. The drawback is, that the style of this µ will not vary with the surrounding font. It is always upright roman, regardless of whether the surrounding text is sans serif, bold or whatever.

Omega makes \ohm always use the upright math symbol \Omega, regardless of whether textcomp is loaded. This makes sense, if there is no � in your text font(s). Thus, the option works always, but the style of the Omega in text will not vary.

Various packages provide an option slantedGreek to make uppercase Greek letters in formulas slanted. You may safely use this option in conjunction with the Omega option of the package gensymb: \ohm will be upright, though!

NB: With a future version of the textcomp package, gensymb may possibly detect the lack of \textohm on its own and behave automatically as if you had specified the Omega option.

Upomega A math symbol with the name \Upomega will be used to for the \ohm. You must additionally load the package upgreek to define it (or define \Upomega yourself). Again, the style of this \ohm in text never changes. The option may be useful, if the text font does not include a \textomega of its own, and the mathematical \Omega does not blend well with the text font, either.

3 Examples

The optimum case

With text fonts providing µ as well as � in the text companion encoding, the default behavior of gensymb is appropriate. This holds, e.g., for the EC/TC fonts (i.e., Computer Modern with T1 and TS1 encoding), for Palatino (in conjunction with PSNFSS version 9 and later), and for most font families provided by MicroPress, Inc.:

\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{gensymb}

1CTAN:macros/latex/contrib/supported/was/

The normal case

Most commercial text fonts have a correct ‘micro’ symbol, but no Omega. In this case the package can be loaded with the Omega option, to make sure that the mathematical Omega is used instead:

 \usepackage[T1]{fontenc}
 \usepackage{textcomp}
 \usepackage{mathptmx} % for instance
 \usepackage[Omega]{gensymb}

Using the ‘classical’ CM fonts

If 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 external font such as Euler Roman. Notice, however, that \perthousand is not available. You may try \permil instead, which is provided in the WASY fonts^{2}.

 \usepackage[Euler]{upgreek}
 \usepackage[Omega, upmu]{gensymb}

A special case

Imagine that you are using the Bitstream Charter text fonts in conjunction with the Euler-VM math fonts. Charter, like most fonts from Bitstream, has a wrong \textmu symbol, so that you need to use an external one. The Euler fonts provide an upright Omega, but it does not go well with the Charter typeface in a combination such as MΩ. As a workaround, use the upgreek package and take both symbols from the ‘Adobe Symbol’ font:

 \usepackage[T1]{fontenc}
 \usepackage{textcomp}
 \usepackage{charter,eulervm}
 \usepackage[Symbol]{upgreek}
 \usepackage[Upomega, upmu]{gensymb}

4 Using gensymb together with other packages

• gensymb must not be used in conjunction with the package SIunits, because the latter has its own means to typeset units of measurement.

• Using the package mathcomp together with gensymb is possible, if you need the additional ‘math companion’ symbols. Both packages will use only one common math symbol font.

2CTAN:fonts/wasy2/, CTAN:macros/latex/contrib/supported/wasysym/

5 Known deficiencies

• If you are using the T1 and TS1 encoding, the package textcomp must be loaded after fontenc only:

          \usepackage[T1]{fontenc}
          \usepackage{textcomp}

Otherwise, the perthousand symbol may be broken. Note that this is a problem of L^{A}TEX; it is not specific for gensymb.

• 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.

6 Implementation

The options are implemented using switches:

1 ⟨∗package⟩

 2 \newif\ifgns@Upomega
 3 \newif\ifgns@Omega
 4 \newif\ifgns@upmu
 5 \DeclareOption{Upomega}{\gns@Upomegatrue}
 6 \DeclareOption{Omega}{\gns@Omegatrue}
 7 \DeclareOption{upmu}{\gns@upmutrue}
 8 \ProcessOptions\relax

These are the generic commands:

 9 \newcommand\celsius{}
10 \newcommand\degree{}
11 \newcommand\perthousand{}
12 \newcommand\ohm{}
13 \newcommand\micro{}

The following macros will be used later to actually define the generic commands. We start with a macro to fake \degree and \celsius and to generate an error

message for \perthousand:
14 \def\gns@usefakedsymbols{%
15 \renewcommand{\degree}{\ensuremath{^\circ}}
16 \DeclareRobustCommand{\celsius}{%
17 \ifmmode^\circ\mathrm{C}\else$^\circ$C\fi}
18 \renewcommand\perthousand{%
19 \PackageError{gensymb}{Symbol perthousand not available}{}}
20 \PackageInfo{gensymb}{%
21 Faking symbols for \protect\degree\space and \protect\celsius}
22 \PackageWarningNoLine{gensymb}{%
23 \protect\perthousand\space will not be available}

24 }

The following macro sets up a SymbolFont for the text companion symbols to be used in math. If \tcmu is already defined, we assume that the mathcomp package is already loaded, and that the ‘math companion’ symbols need not be defined once again:

25 \def\gns@setupmathcomp{%
26 \expandafter\ifx\csname tcmu\endcsname\relax
27 \DeclareSymbolFont{gns@font}{TS1}{\familydefault}{m}{n}
28 \ifx\mv@bold\@undefined\else
29  \SetSymbolFont{gns@font}{bold}{TS1}{\familydefault}{\bfdefault}{n}
30 \fi
31 \DeclareMathSymbol{\tccelsius}{\mathord}{gns@font}{'211}
32 \DeclareMathSymbol{\tcdegree}{\mathord}{gns@font}{176}
33 \DeclareMathSymbol{\tcperthousand}{\mathord}{gns@font}{'207}
34 \DeclareMathSymbol{\tcmu}{\mathord}{gns@font}{'265}
35 \DeclareMathSymbol{\tcohm}{\mathord}{gns@font}{'127}
36 \PackageInfo{gensymb}{Math companion symbols declared}
37 \else
38 \PackageInfo{gensymb}{Math companion symbols found}
39 \fi

40 }

A macro to define \degree, \celsius and \perthousand so as to use text companion symbols:

41 \def\gns@usetcsymbols{%
42 \DeclareRobustCommand{\degree}{%
43 \ifmmode\tcdegree\else\textdegree\fi}
44 \DeclareRobustCommand{\celsius}{%
45 \ifmmode\tccelsius\else\textcelsius\fi}
46 \DeclareRobustCommand{%
47 \perthousand}{\ifmmode\tcperthousand\else\textperthousand\fi}
48 \PackageInfo{gensymb}{Using text companion symbols for %
49 \protect\degree, \protect\celsius and \protect\perthousand}

50 }

A macro to define \ohm so as to use the math symbol \Upomega:

51 \def\gns@useUpomega{%
52 \expandafter\ifx\csname Upomega\endcsname\relax
53  \PackageError{gensymb}
54  {You have requested the option Upomega,\MessageBreak
55  but the command \protect\Upomega\space is undefined}
56  {Load the upgreek package and try again!}
57 \fi
58 \DeclareRobustCommand{\ohm}{\ifmmode\Upomega\else$\Upomega$\fi}
59 \PackageInfo{gensymb}{Using \protect\Upomega\space for \protect\ohm}

60 }

A macro to define \ohm so as to use \Omega (or \upOmega, if it is provided):

61 \def\gns@useOmega{%
62 \expandafter\ifx\csname upOmega\endcsname\relax
63 \DeclareRobustCommand{\ohm}{\ifmmode\Omega\else$\Omega$\fi}
64 \PackageInfo{gensymb}{Using \protect\Omega\space for \protect\ohm}
65 \else
66 \DeclareRobustCommand{\ohm}{\ifmmode\upOmega\else$\upOmega$\fi}
67 \PackageInfo{gensymb}{Using \protect\upOmega\space for \protect\ohm}
68 \fi

69 }

A macro to define \ohm so as to use the text companion symbol:

70 \def\gns@usetextohm{%
71 \DeclareRobustCommand{\ohm}{\ifmmode\tcohm\else\textohm\fi}

72 \PackageInfo{gensymb}{Using \protect\textohm\space for \protect\ohm}

73 }

A macro to define \micro so as to use the math symbol \upmu:

74 \def\gns@useupmu{%
75 \expandafter\ifx\csname upmu\endcsname\relax
76  \PackageError{gensymb}
77  {You have requested the option upmu,\MessageBreak
78  but the command \protect\upmu\space is undefined}
79  {Load the upgreek package and try again!}
80 \fi
81 \DeclareRobustCommand{\micro}{\ifmmode\upmu\else$\upmu$\fi}
82 \PackageInfo{gensymb}{Using \protect\upmu\space for \protect\micro}

83 }

A macro to define \micro so as to use the text companion symbol:

84 \def\gns@usetextmu{%
85 \DeclareRobustCommand{\micro}{\ifmmode\tcmu\else\textmu\fi}
86 \PackageInfo{gensymb}{Using \protect\textmu\space for \protect\micro}

87 }

A macro to make \micro issue an arror message:

88 \def\gns@usenomu{%
89 \renewcommand{\micro}{%
90  \PackageError{gensymb}{Symbol micro not available}{}}
91 \PackageWarningNoLine{gensymb}{%
92  \protect\micro\space will not be available}

93 }

The actual work is exectued AtBeginDocument, so that we can detect the presence of the textcomp package and the availability of \Upmu and other commands, regardless of the sequence of loading the packages.

94 \AtBeginDocument{%

First, we check for textcomp. If it is loaded, we set up the text companion symbols for use in math and define \degree, \celsius and \perthousand so that they use these. Otherwise, the symbols are faked as far as possible:

95 \@ifpackageloaded{textcomp}{\gns@setupmathcomp\gns@usetcsymbols}%
96 {\gns@usefakedsymbols}

Now we define \ohm. In case the options Upomega or Omega have been specified, behave acordingly. Otherwise, use the text companion symbol, if available. Default is to use the mathematical Omega:

97 \ifgns@Upomega
98 \gns@useUpomega
99 \else
100 \ifgns@Omega
101 \gns@useOmega
102 \else
103 \expandafter\ifx\csname textohm\endcsname\relax
104 \gns@useOmega
105 \else
106 \gns@usetextohm
107 \fi\fi\fi

Next, define \micro. In case the option upmu has been specified, behave acordingly. Otherwise, use the text companion symbol, if available. Default is not to provide \micro at all.

108 \ifgns@upmu
109 \gns@useupmu
110 \else
111 \expandafter\ifx\csname textmu\endcsname\relax
112 \gns@usenomu
113 \else
114 \gns@usetextmu
115 \fi\fi

Finally, we destroy the commands that are no longer needed:

116 \let\gns@usefakedsymbols\relax
117 \let\gns@setupmathcomp\relax
118 \let\gns@usetcsymbols\relax
119 \let\gns@useUpomega\relax
120 \let\gns@useOmega\relax
121 \let\gns@usetextohm\relax
122 \let\gns@useupmu\relax
123 \let\gns@usenomu\relax
124 \let\gns@usetextmu\relax

125 } 126 ⟨/package⟩

The next line of code is only to prevent DocStrip from adding the character table to all modules:

127 \endinput