3

MWE:

\documentclass[11pt,a4paper]{article}

\usepackage{xcolor}
\usepackage{soul}
\usepackage[acronym,toc]{glossaries}

\newacronym{a}{A}{The one and only A}

\newcommand{\myCmd}[3][]{%
    \ifthenelse{\equal{#2}{}}%
        {}%
        {\texthl{#2}}%
    \ifthenelse{\equal{#1}{}}{%
        Test #3 %
    }{%
        Other Test #1 #3%
    }%
}%


\begin{document}

\begin{itemize}
  \item works: \gls{a}
  \item works: \myCmd{1}{2}
  \item works: \myCmd[3]{1}{2}
  \item does not work: \myCmd[3]{\gls{a}}{2}
\end{itemize}

\end{document}

I know that myCmd looks weird, but that's only because I simplified a lot of it for the MWE.

Anyways, the MWE results in this error:

! Package glossaries Error: Glossary entry `{a}' has not been defined.

The only thing I figured already is, that the gls command does not find the parameter, because it looks for {a} instead of a - but why?

2
  • \gls is not expandable, most likely this is the reason why the test fails!
    – user31729
    Commented Aug 17, 2016 at 15:40
  • Sounds reasonable, but what can I do beside "not using \gls as (part) of an argument"? Or is there nothing I can do about it?
    – user112212
    Commented Aug 17, 2016 at 19:28

1 Answer 1

2

Here's a work-around, with the expandable commands \glsentryname and \glsentrydesc (for more of them see section 9 of glossaries-user.pdf documentation).

In order to calm soul and 'expand' the argument, an \mbox{} is appropiate. Long descriptions won't break however over lines.

\documentclass[11pt,a4paper]{article}

\usepackage{xcolor}
\usepackage{soul}
\usepackage{etoolbox}
\usepackage[acronym,toc,nomain]{glossaries}

\newcommand{\glsinfo}[1]{%
  \glsentryname{#1} -- \glsentrydesc{#1}%
}

\makeglossaries

\newacronym{a}{A}{The one and only A}

\newcommand{\myCmd}[3][]{%
  \ifblank{#2}{}{\texthl{\mbox{#2}}}%
  \ifblank{#1}{Test #3}{Other Test #1 #3}%
}


\begin{document}
\begin{itemize}
  \item works: \gls{a}
  \item works: \myCmd{1}{2}
  \item works: \myCmd[3]{1}{2}
  \item works: \myCmd[3]{\glsinfo{a}}{2}
  \item works: \myCmd[3]{\glsentrydesc{a}}{2}
  \item works: \myCmd[3]{}{2}
\end{itemize}

%\printglossaries
\end{document}

enter image description here

1
  • A better solution requires more information on the intentions what the code should do actually.
    – user31729
    Commented Aug 19, 2016 at 8:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .