Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to use \gls (from the glossaries package) inside a caption without \protecting it every single time? The glossaries package says the \gls command is not fragile... but I get errors unless I protect it.

Kind of annoying since half the advantage of a glossary/acronym package is reducing the amount of typing you have to repeat.

\documentclass{article}
\usepackage{caption}
\usepackage{glossaries}

\newglossaryentry{Name}{name={Name},description={Description}}

\makeglossaries

\begin{document}

\begin{figure}[h]
    \caption{Blah blah \protect\gls{name}}
\end{figure}

\end{document}

If you remove the protect it will complain about an extra }.

share|improve this question
    
Robustify appears to have worked. Thanks! Why would it compile without that for you but not me? –  Jack Oct 7 '11 at 9:00

1 Answer 1

up vote 5 down vote accepted

The glossaries package loads the etoolbox package by default. And, etoolbox provides \robustify{<command>} that redeclares <command> as a robust (non-fragile) command. Therefore, add

\robustify{\gls}% Make \gls not fragile

after loading glossaries.

share|improve this answer
    
I had to manually usepackage etoolbox for this to work. –  Jack Oct 7 '11 at 9:05
    
What version of glossaries do you have? Mine is 2011/04/12 v3.01. Add \listfiles before \documentclass{...} and view your .log file. Earlier versions may not have needed/loaded etoolbox. –  Werner Oct 7 '11 at 9:08
1  
@Werner Also, the documentation says 'As from v3.01 \gls is no longer fragile and doesn’t need protecting', so this may just be a version issue. –  Joseph Wright Oct 7 '11 at 10:01
    
I have v2.05 so this must be the problem. But I specifically downloaded the latest version and placed it in my tex directory. How can I stop the old version that comes with my dist overriding this? –  Jack Oct 7 '11 at 10:34
    
@Jack: It's best to update packages via your package manager. If not, you need to overwrite the older package style file with the new one since TeX will retrieve the file (with the same name) in the same location. Updating your FNDB (FileName DataBase) may also solve this issue, as long as you don't have duplicates stored in different places. –  Werner Oct 7 '11 at 14:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.