[Tex/LaTex] \gls inside caption without protect

captionsglossaries

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 }.

Best Answer

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.