Textcomp Package Overriding Gensymb for Degree Symbol

degreespdftexsymbolstextcomp

Consider the code

\documentclass{book}
\usepackage{amsthm,latexsym,amssymb,amsmath,verbatim}
\usepackage{gensymb}
%\usepackage{textcomp}
\begin{document}
\Huge
\noindent 45$\degree$ \\
45$^\circ$\\
%45\textdegree
\end{document}

which produces the output

enter image description here

Upon inspection, it would appear that 45$\degree$ and 45$^\circ$ produce exactly the same glyph.

Now, if I uncomment %\usepackage{textcomp} and %45\textdegree within the above code and run it, I get

enter image description here

Notice that 45$\degree$ seemingly now renders 45\textdegree; while 45$^\circ$ seems to produce the same glyph as before.

QUESTION: Are there other symbols for which textcomp "trumps" gensymb? Can anyone explain what might be causing this; and perhaps, how I may override it so that if I call for both the gensymb and textcomp packages in the preamble and invoke, say, the \degree command in the document—I get what \degree normally produces?

Thank you.

Best Answer

If I compile

\documentclass{book}
\usepackage{gensymb}
\usepackage{textcomp}

\begin{document}

$45\degree$

$45^\circ$

45\textdegree

\end{document}

with TeX Live 2012, prior to the inclusion of textcomp in the kernel, I get

enter image description here

and an error about \textdegree if I comment out \usepackage{textcomp}. The output from the first two lines becomes

enter image description here

So the aim of gensymb has always been using the smaller glyph from textcomp if possible.

It achieves this by doing

\AtBeginDocument{%
  \@ifpackageloaded{textcomp}
    {\gns@setupmathcomp\gns@usetcsymbols}%
    {\gns@usefakedsymbols}
  [...]
}

Unfortunately the package has not been updated for keeping up with the inclusion of textcomp in the kernel, so it doesn't actually realize that \textdegree is available even if textcomp is not loaded. If you load it, the output is as expected by the author of gensymb.

I'm not sure why you think that textcomp “trumps” gensymb: the behavior is wanted.

To be honest, I'd avoid loading gensymb that provides nothing that isn't available in different ways. Anyway, you can get a shortened gensymb by

\documentclass{book}

\makeatletter
\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}
\DeclareRobustCommand{\degree}{%
  \ifmmode\tcdegree\else\textdegree\fi}
\DeclareRobustCommand{\celsius}{%
  \ifmmode\tccelsius\else\textcelsius\fi}
\DeclareRobustCommand{\perthousand}{%
  \ifmmode\tcperthousand\else\textperthousand\fi}
\DeclareRobustCommand{\ohm}{\ifmmode\tcohm\else\textohm\fi}
\DeclareRobustCommand{\micro}{\ifmmode\tcmu\else\textmu\fi}
\makeatother


\begin{document}

$45\degree$

$45^\circ$

45\textdegree

\degree,\celsius,\perthousand,\ohm,\micro

\end{document}

enter image description here

If you just need \degree, there's no point in wasting a math group:

\documentclass{book}
\usepackage{amsmath}

\ExplSyntaxOn

\NewDocumentCommand{\degree}{}
 {
  \mode_if_math:TF
   {
    \text
     {
      \normalfont
      \str_if_eq:vnT { math@version } { bold } { \bfseries }
      \textdegree
     }
   }
   {
    \textdegree
   }
 }

\ExplSyntaxOff

\begin{document}

$45\degree$

$45^\circ$

45\textdegree

\boldmath $45\degree$

\end{document}

enter image description here