3

I've a user-defined symbol like this:

\newcommand{\myexclam}{\mathrel{\stackinset{c}{}{t}{}{\rotatebox{-45}{\scalebox{.5}{$/$}}}{$!$}}}

This symbol should be used in one of my glossary's entries as below (gloss.tex):

\newglossaryentry{mykey}{name={\ensuremath{\delta_{\text{act}}(a,\tau)\myexclam}}, description={Activity automaton}}

and here is main.tex:

\documentclass[doublespaced,12pt]{article}

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage[symbols]{glossaries}
\usepackage{stackengine}
\usepackage{hyperref}

\newcommand{\myexclam}{\mathrel{\stackinset{c}{}{t}{}{\rotatebox{-45}{\scalebox{.5}{$/$}}}{$!$}}}

\makenoidxglossaries
\loadglsentries{gloss}

\begin{document}

    Here is my formula \gls{mykey}

    \printnoidxglossary[sort=standard,title={List of Symbols}]      

\end{document}

But the compilation throws an undefined control sequence corresponding to \myexclam.

How can I properly use this command in my glossary?

4
  • What if you paste the command's code into the glossary entry instead of \myexclam?
    – user122160
    Commented Oct 12, 2017 at 5:49
  • @A.Loc: The result would be the same.
    – user78499
    Commented Oct 12, 2017 at 5:50
  • @Roboticist: I get the same error using \myexclam directly, i.e. without glossaries at all, so there error is inside \myexclam, not with \gls etc.
    – user31729
    Commented Oct 12, 2017 at 7:04
  • I've written a comment to Steven B. Segletes -- it's possibily an issue with \stackinset from his stackengine package
    – user31729
    Commented Oct 12, 2017 at 7:12

1 Answer 1

3

In this case, \myexclam must be \protected in the \newglossaryentry.

EDITED to add a sort= key to \newglossaryentry, since the name is non-alphabetic, per Nicola's instruction. Also, loaded hyperref prior to glossaries.

\documentclass[doublespaced,12pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{gloss.tex}
\newglossaryentry{mykey}{name={\ensuremath{\delta_{\text{act}}(a,\tau)\protect\myexclam}}, 
  description={Activity automaton},sort={delta activity}}
\end{filecontents*}

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{hyperref}
\usepackage[symbols]{glossaries}
\usepackage{stackengine}

\newcommand{\myexclam}{\mathrel{\stackinset{c}{}{t}{}{\rotatebox{-45}{%
  \scalebox{.5}{$/$}}}{$!$}}}

\makenoidxglossaries
\loadglsentries{gloss}

\begin{document}

    Here is my formula \gls{mykey}

    \printnoidxglossary[sort=standard,title={List of Symbols}]      

\end{document}

enter image description here

In the event that there were multiple macros needing protection (for example, if \myexclam were used more than once), it might just be easier to define it this way, so that only a single \protect is required:

\begin{filecontents*}{gloss.tex}
\newcommand\newname{\ensuremath{\myexclam\delta_{\text{act}}(a,\tau)\myexclam}}
\newglossaryentry{mykey}{name={\protect\newname}, description={Activity automaton},
  sort={delta activity}}
\end{filecontents*}
4
  • 1
    The sort key is always needed in \newglossaryentry for entries that contain any (non-accent) commands when used with \makenoidxglossaries. Commented Oct 12, 2017 at 12:37
  • @NicolaTalbot Not being a glossary user, that key would be in the form of ,sort={? ? ?}, what, exactly? Maybe ,sort={delta actual}? Commented Oct 12, 2017 at 12:53
  • \printnoidxglossary sorts according to the value of the sort key provided with each entry and sort=standard means an alphabetical sort. Since it uses TeX to sort, it only sorts according to (lowercase) character code. If sort is missing it will be taken from the name key but the noidx method used here locally modifies accent commands to allow them to be stripped when the sort is obtained from the name (hence the expansion problem). I think sort={delta actual} sounds like a reasonable value. Commented Oct 12, 2017 at 14:02
  • 1
    This type of glossary entry would be much better with \makeglossaries and makeindex. (name={\protect\newname} won't work with xindy without the sort key.) By the way, didn't notice it earlier: hyperref needs to be loaded before glossaries. Commented Oct 12, 2017 at 14:05

You must log in to answer this question.