2

This is a follow up question to glossaries and phantom.

It was about the following alignemnt in a glossary:

 symbol
#symbol
 other
#other

rather than

symbol
#symbol
other
#other

I wanted to align terms as this and decided to use phantom, however this solution has the disadvantag that there is to much whitespace when I use the glossary symbol in text, since the phantom part appears as well. Is there any good solution to have the phantom part only in the glossary but not when using the term in text?

\documentclass{report}
\usepackage[sanitize=none]{glossaries}    
\makeglossaries%

\newglossaryentry{nc:line:num}{
    name=thing,
    symbol=\ensuremath{\protect\hphantom{\#}l},
    description=other thing}
\newglossaryentry{nc}{
    name=thingy,
    symbol=\ensuremath{\#l},
    description=something}  

\usepackage{glossary-mcols}
\begin{document}
    \printglossary[style=altlong4col]
    \clearpage%
    nc:line:num glossary entry '\glssymbol{nc:line:num}`, notice the whitespace after the '
\end{document}
ted
  • 3,377

1 Answers1

3

The following example defines a command called \nohash that puts in the correct spacing in the glossary but after the glossary is redefined so the symbol can be used in the text without a problem:

\documentclass{report}
\usepackage[sanitize=none]{glossaries}
\makeglossaries

\newcommand*{\nohash}[1]{\hphantom{\#}#1}

\newglossaryentry{nc:line:num}{
    name=thing,
    symbol=\ensuremath{\protect\nohash{l}},
    description=other thing}
\newglossaryentry{nc}{
    name=thingy,
    symbol=\ensuremath{\#l},
    description=something}

\usepackage{glossary-mcols}
\begin{document}

\printglossary[style=altlong4col]

% reset \nohash:
\renewcommand{\nohash}[1]{#1}%

\clearpage

nc:line:num glossary entry `\glssymbol{nc:line:num}'.

For comparison: `\glssymbol{nc}'.

\end{document}

The glossary looks like:

Image of glossary

The text looks like:

enter image description here

Nicola Talbot
  • 41,153
  • Thanks for the quick awnser, two more questions though: shouldn't it be \renewcommand* if you use \newcommand*? And is there a benefit to make \hash a one parameter macro, and not a 0 parameter macro? – ted Jul 03 '13 at 08:22
  • Sorry, I forgot the *. There's no benefit here with regard to the parameter. They'd only be a benefit if you wanted to use \Glssymbol. (Which isn't relevant for this specific example where you have a variable in math mode.) – Nicola Talbot Jul 03 '13 at 08:52