[Tex/LaTex] How to get only one symbol from a symbol package

incompatibilitypackagessymbols

I need to use the \Writinghand symbol from the package marvosym.sty. But, for some reason, loading this package raises an error:

(/usr/local/texlive/2013/texmf-dist/tex/latex/ifsym/ifsym.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/tools/calc.sty)

! LaTeX Error: Command \Sun already defined.
Or name \end… illegal, see p.192 of the manual.

So, here is my general question:
Is there a general procedure to follow when one wants to include only one symbol from a « symbol package » (a package that creates many new symbols)?

Best Answer

No, there is no general procedure. One has to look into the package code and some knowledge of the terminal can be helpful; but one can always open the package file with an editor.

Let's see for \WritingHand that the Comprehensive List tells you it is from marvosym.sty.

First of all, we need to identify how the font is known to LaTeX. In these cases, rather than opening the file in an editor, I use less:

less $(kpsewhich marvosym.sty)

because kpsewhich is the utility that's used internally by the TeX programs to find a file. The first lines in the file are

\ProvidesPackage{marvosym}
  [2011/07/20 v2.2 Martin Vogel's Symbols font definitions]
\newcommand{\mvs}{\fontfamily{mvs}\fontencoding{U}%
\fontseries{m}\fontshape{n}\selectfont}

Good. We know how to load the font. The code is not the best possible, because

\newcommand{\mvs}{\usefont{U}{mvs}{m}{n}}

would be a cleaner call, although they're equivalent. The encoding U is “unspecified“ or “unknown”, which means that LaTeX won't try any of its tricks to adapt commands to the current encoding. It is a standard encoding, so there's no need to declare it beforehand. Any time we need a glyph from the font, we can say

\usefont{U}{mvs}{m}{n}

in a group. Now we look for \WritingHand and we find it on line 80:

\newcommand\WritingHand{\mvchr{98}}     \let\Writinghand\WritingHand

the second part is just an alias. What's \mvchr? It's on line 5

\newcommand{\mvchr}[1]{{\mvs\char#1}}

but it's again poor LaTeX programming, because \symbol{#1} would be better.

So we have all the necessary bits in order to accomplish our task:

\newcommand{\WritingHand}{{\usefont{U}{mvs}{m}{n}\symbol{98}}}

will work without loading any package. If you plan to use \WritingHand in moving arguments (sectional titles or captions, for instance), it may be better to use \DeclareRobustCommand instead of \newcommand, otherwise in the .aux file you would find

{\fontencoding  {#1}\fontfamily  {#2}\fontseries  {#3}\fontshape  {#4}\selectfont  \ignorespaces \char 98\relax }

instead of a simple \WritingHand. Not much of a problem, but possibly annoying.

Suppose instead you want to use the glyph

enter image description here

that is available in the STIX font package. Looking at the documentation, we find it at position octal 204 (decimal 132) in the font stix-extra1 (font table on page 43).

As before, we look in stix.sty, but we don't find extra inside it. Turn back to the documentation: on page 2 we find indeed

There are also three fonts containing extra miscellaneous symbols, stix-extra1, stix-extra2 and stix-extra3, provided as TFM and PFB files without support from the macro package.

This seems a problem, but indeed it isn't. We can proceed almost as before, just adding the necessary infrastructure

\DeclareFontFamily{U}{stixextrai}{}
\DeclareFontShape{U}{stixextrai}{m}{n}
 { <-> stix-extra1 }{}

\newcommand{\WolframSym}{{\usefont{U}{stixextrai}{m}{n}\symbol{132}}}

The same caveat as before for \DeclareRobustCommand applies. The family name stixextrai is arbitrary. Example document:

\documentclass{article}

\DeclareFontFamily{U}{stixextrai}{}
\DeclareFontShape{U}{stixextrai}{m}{n}
 { <-> stix-extra1 }{}

\newcommand{\WolframSym}{{\usefont{U}{stixextrai}{m}{n}\symbol{132}}}

\begin{document}
\WolframSym
\end{document}

which is how I produced the image above.

Related Question