我正在使用glossaries
(或者glossaries-extra
),并尝试默默地将术语添加到词汇表中。也就是说,在我的文档中,我偶尔想将一个术语添加到词汇表中没有它出现在我使用该命令的文本输出中。
我试过了glsadd{<key>}
。这满足了两个条件。但令人讨厌的是,当写在空行上时,它会产生空格。是否有包选项可以防止这种情况或其他命令?
任何帮助都将不胜感激。以下是足以说明问题的最小示例。
\documentclass[a4paper]{scrbook}
\usepackage{glossaries} % problem exists under glossaries-extra too
\newglossaryentry{term}{sort={0}, name={Term}, description={Something.}}
\newglossaryentry{here}{sort={1}, name={Here}, description={Something.}}
\newglossaryentry{is}{sort={2}, name={Is}, description={Something.}}
\newglossaryentry{more}{sort={3}, name={More}, description={Something.}}
\newglossaryentry{proof}{sort={4}, name={Proof}, description={Something.}}
\makeglossaries
\def\silentcmd#1{\setcounter{page}{#1}}
\begin{document}
\setlength{\parskip}{1\baselineskip}
\setlength{\parindent}{0em}
Here is a sentence I want to to add a term \glsadd{term} silently and that works. But then consider writing a command on an empty line.
Between me and the last paragraph is nothing.
\silentcmd{5}
Between me and the last paragraph is a silent command.
\glsadd{here}
Between me and the last paragraph is a glsadd-command.
\glsadd{is}
\glsadd{more}
\glsadd{proof}
For clarity, between me and the last paragraph are 3 glsadd-commands.
Is there another command to glsadd to properly silently add terms to the glossary? If not\ldots why??!
\end{document}
答案1
glossaries
跟踪词汇表条目在哪些页面上使用。为此,发生这种情况的页面需要明确定义,即\glsadd
必须是一行文本的一部分。这就是为什么在垂直模式下调用时使用向文档glossaries
添加一个空白的原因。\mbox
\@gls@adjustmode
\glsadd
你应该决定每个段落\glsadd
属于哪个段落,这样你就不会遇到这个问题,并glossaries
会记录合理的页码。例如
This is a paragraph with some entries at the end.
\glsadd{some}
\glsadd{entries}
\glsadd{other}
\glsadd{entries}
This is a paragraph with other entries at the beginning and something between sentences.
\glsadd{something}
This way it is always well defined where in the document you called \verb|\glsadd|.
如果你不关心页码(并且正在使用该nonumberlist
选项),你可以使用以下方法删除该功能
\makeatletter
\AtBeginDocument{\let\@gls@adjustmode\@empty}
\makeatother
在你的序言中。