以下memoir
类源文件在使用pdflatex
和处理时makeindex
,使用memoir
类basic.gst
词汇表样式文件,会生成缺少第 3 个条目(关于“从一个集合到另一个集合的功能”)的词汇表:
\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}
生成的文件glossary.glo
有第三个也是最后一个条目:
\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}
但是,生成的文件glossary.gls
中不包含相应的条目。
日志文件glossary.glg
包括:
...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).....
该如何解决?
答案1
这是 定义中的一个错误\@@glossary
,它\@sanitize
在吸收了其参数后就会这样做,从而违背了其目的。
只要您不在\glossary
另一个命令的参数中使用,您就可以使用不扩展命令的不同定义:
\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}
替代解决方案:重新定义\@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}
答案2
您只需要在定义中\protect
使用 s 的有问题的宏。@
\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}
答案3
Herb Schulz 向我指出,潜在的问题在于这\colon
是一个关系命令。
一个简单的解决方法,仍然给实际结肠左侧留出比\colon
定义更小的空间
\newcommand{\from}{\mathpunct{:}}
然后使用,例如:
$f \from X \to Y$
在正文和相应的项目中均有体现\glossary
。
从数学风格的角度来看,我不确定哪一个能在实际冒号周围产生更令人满意的间距 - \newcommand{\from}{\mathpunct{:}}
或者\newcommand{\from}{\protect\colon}
。(有什么想法吗?)