# How to define a symbol that can be used in both a glossary and an equation?

I created a list of symbols table as you can see :

\newglossaryentry{slambda}{
name=$\lambda$,
description={wavelength}
}


When I tried to put this symbol in the equation :

$$\gls{slambda} = \frac{c}{f}$$


I got an error. I want to do that to show the symbol Lambda in my symbol list, generated as below :

\printglossary


Any ideas ?

• Can you be a bit more explicit (e.g., tell us what you did to create the list of symbols table, what did you try without success)? Aug 7 '15 at 9:00
• I'm trying to add symbol in the tag 'equation' to see them in the symbol table, because if I don't add them, I can't see them (I don't know if I'm pretty clear or not, english not my native language ...) Aug 7 '15 at 9:07
• @Zaertiu: If you show us the code how you generated the list of symbols table, it's possible to help you, as of now -- we can only guess
– user31729
Aug 7 '15 at 9:12
• post edited, I shall be clearer now. Aug 7 '15 at 9:19

Some will frown on this, but the error is $\lambda$ being used in $$...$$ when \gls{slambda} is replaced with $\lambda$ then.

It's not possible to use $...$ inside equation-like environments.

Omitting works for the environment, but then \printglossaries complains about missing math mode.

One possible solution is to apply \ensuremath around \lambda. It will use math mode if it's not already in math mode then -- so it is safe to use it.

\documentclass{article}

\usepackage{glossaries}
\makeglossaries

\newglossaryentry{slambda}{%
name=\ensuremath{\lambda},
description={wavelength}
}

\begin{document}

$$\gls{slambda} = \frac{c}{f}$$

\printglossary  % for usage with makeglossaries program

\end{document}


• @Zaertiu: Alright: Happy TeXing then ;-)
– user31729
Aug 7 '15 at 9:29
• This is a place where \ensuremath is good. ;-) Aug 7 '15 at 9:31
• +1 but minor nit-pick ;-) Both \printglossary and \printglossaries will have the same effect here as there's only one glossary. They're not dependent on the document build. (\printglossaries just iterates over all defined glossaries and applies \printglossary[type={...}] to each one.) Feb 25 '18 at 14:20
• @NicolaTalbot: Thanks, this is one of my older answers related to glossaries. I changed to \printglossary here
– user31729
Feb 25 '18 at 15:28
• @ChristianHupfer Oops, sorry I didn't notice the date! Feb 25 '18 at 16:34