3

The following memoir class source file, when processed with pdflatex and makeindex, using the memoir class basic.gst glossary style file, produces a glossary that is missing the 3rd entry (about "function from one set to another"):

\documentclass{memoir}

\usepackage{amsmath}

\makeglossary[glossary]

\begin{document}

The empty set is denoted by $\emptyset$.%
\glossary[glossary]{$\emptyset$}{empty set}

The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\glossary[glossary]{$\mathcal{P}(X)$}{power set of set}

\newpage

For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\glossary[glossary]{$f \colon X \to Y$}{function from one set to another}

\printglossary[glossary]

\end{document}

The generated glossary.glo has as its 3rd, and last, entry:

\glossaryentry{$f \penalty \@M \mskip 2mu\mathpunct {}\nonscript \mkern -\thinmuskip {:}\mskip 6muplus1mu\relax X \to Y$@ {\memgloterm{$f \penalty \@M \mskip 2mu\mathpunct {}\nonscript \mkern -\thinmuskip {:}\mskip 6muplus1mu\relax X \to Y$}}{\memglodesc{function from one set to another}} {\memgloref{}}|memjustarg}{2}

However, the generated glossary.gls contains no corresponding entry.

The log file glossary.glg includes:

...Scanning input file glossary.glo....
!! Input index error (file = glossary.glo, line = 3):
   -- Extra `@' at position 106 of first argument.
done (2 entries accepted, 1 rejected).
Sorting entries....done (2 comparisons).....

How can this problem be fixed?

3 Answers 3

3

It's a bug in the definition of \@@glossary, which does \@sanitize after having absorbed its arguments, so defeating its purpose.

So long as you don't use \glossary in the argument to another command, you can use a different definition that doesn't do expansion of commands:

\documentclass{memoir}

\usepackage{xparse}

\makeglossary[glossary]

\makeatletter
\RenewDocumentCommand{\glossary}{O{\jobname}d()vv}{%
  \@bsphack
  \@ifundefined{#1memglofile}{\@esphack}
   {%
    \def\memglofile{#1}%
    \begingroup
    \IfNoValueTF{#2}
      {\@wrglom@m{#3}{#3}{#4}}
      {\@wrglom@m{#2}{#3}{#4}}
   }%
}
\makeatother

\begin{document}

The empty set is denoted by $\emptyset$.%
\glossary[glossary]{$\emptyset$}{empty set}

The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\glossary[glossary]{$\mathcal{P}(X)$}{power set of set}

\newpage

For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that 
$f$ is a functions from $X$ to $Y$.%
\glossary[glossary]{$f \colon X \to Y$}{function from one set to another}

\printglossary[glossary]

\end{document}

Alternative solution: redefine \@wrglom@m

\documentclass{memoir}
\makeglossary[glossary]

\makeatletter
\renewcommand{\@wrglom@m}[3]{%
  \protected@write\@auxout{}{%
    \string\@@wrglom@m
      {\memglofile}%
      {\unexpanded{\unexpanded{#1}}}%
      {\unexpanded{\unexpanded{#2}}}%
      {\unexpanded{\unexpanded{#3}}}%
      {\@nameuse{memglsnx\memglofile}}{\@nameuse{memglsn\memglofile}}%
  }%
  \endgroup
  \@esphack
}
\makeatother

\begin{document}

The empty set is denoted by $\emptyset$.%
\glossary[glossary]{$\emptyset$}{empty set}

The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\glossary[glossary]{$\mathcal{P}(X)$}{power set of set}

\newpage

For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that 
$f$ is a functions from $X$ to $Y$.%
\glossary[glossary]{$f \colon X \to Y$}{function from one set to another}

\printglossary[glossary]

\end{document}
1
  • The alternative solution, just to redefine \@wrglom@m also takes care of other problematic uses of memoirs \glossary when the first argument is a math expression in turn containing a math operator that takes an argument (with { and }).
    – murray
    Aug 3, 2016 at 19:48
3

You just need to \protect the problematic macros which use @s in their definitions.

\documentclass{memoir}

\usepackage{amsmath}

\makeglossary[glossary]

\begin{document}

The empty set is denoted by $\emptyset$.%
\glossary[glossary]{$\emptyset$}{empty set}

The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\glossary[glossary]{$\mathcal{P}(X)$}{power set of set}

\newpage

For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\glossary[glossary]{$f \protect\colon X \protect\to Y$}{function from one set to another}

\printglossary[glossary]

\end{document}

glossary with protections

0

Herb Schulz pointed out to me that the underlying problem is that \colon is a relational command.

An easy workaround that still gives smaller space to the left of the actual colon than does \colon seems to be to define

\newcommand{\from}{\mathpunct{:}}

and then use, e.g.:

$f \from X \to Y$

both in the body of the text and in a corresponding \glossary item.

I'm unsure of which produces the more satisfactory spacing around the actual colon from the point of view of mathematical style -- \newcommand{\from}{\mathpunct{:}} or \newcommand{\from}{\protect\colon}. (Any thoughts?)

You must log in to answer this question.

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