词汇表的描述长度限制

词汇表的描述长度限制

我的一些glossarie条目有相当长的描述。超过一定数量的字符后,命令将不再显示它们 printglossaries。以下是产生此问题的一个示例:

\documentclass{article}
\usepackage[shortcuts]{glossaries}

\makeglossaries

\newglossaryentry{short}{name={short},
description={a short entry}}

\newglossaryentry{long}{name={long},
description={
a long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry
}}

\begin{document}
This one works : \gls{short}.
This one does not : \gls{long}

\printglossaries

\end{document}

我怎样才能避开这个问题?

答案1

在词汇表日志文件中你会看到

!! Input index error (file = gl55.glo, line = 2):
   -- First argument too long (max 1024).

幸运的是,TeX 是一个宏处理器,因此很容易用短文本代替长文本:

在此处输入图片描述

\newglossaryentry{long}{name={long},
description={\longdesc}}

\def\longdesc{a long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry}

答案2

我想提出更自动化的方法来解决这个问题:

\documentclass{article}
\usepackage[shortcuts]{glossaries}
\usepackage{etoolbox}
\makeatletter 
%define new glossary entry key, description with no size limit
\define@key{glossentry}{description}{\def\@glo@ldesc{#1}}

%overwrite standard description key with new long description
%it also makes description key not mandatory when long description is defined
\renewcommand{\@newglossaryentryprehook}{
\def\@glo@ldesc{}
\def\@glo@desc{\@glo@ldesc}
}
\renewcommand{\@newglossaryentryposthook}{
%save the content of new ldesc variable and prevent it from expanding. Its important if we want to use fancy latex commands description
\protected@csxdef{glo@\@glo@label @ldesc}{\expandonce{\@glo@ldesc}}
%overide description field for this glossary entry. By using csexpandonce and csuse we prevent expansion and take into account that \@glo@label may have white spacess in it.
\protected@csxdef{glo@\@glo@label @desc}{\csexpandonce{csuse{glo@\@glo@label @ldesc}}}
%because \@newglossaryentryprehook is invoked after \do@glo@storeentry in glossaries.sty we need to save it all again ;(
\do@glo@storeentry{\@glo@label}
}
\makeatother

\makeglossaries

\newglossaryentry{short}{name={short},
description={a short entry}}

\newglossaryentry{long}{name={long},
description={
a long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry
}}

\begin{document}
This one works : \gls{short}.
This one does not : \gls{long}

\printglossaries

\end{document}

答案3

(我意识到这个问题已经很老了,但如果有人仍然感兴趣,我会添加它。)

这对于较新版本(4.0 及以上)来说不是问题,因为glossaries描述不再写入 处理的文件中makeindex。现在,您只可能makeindex因为标签过长而溢出 的缓冲区。

因此,您的最小示例现在可以正常工作,而不会出现任何错误makeindex。 如果其他人遇到同样的问题,最好的解决方案是更新他们的版本glossaries

现在还可以使用多段落描述\longnewglossaryentry

\documentclass{article}
\usepackage[shortcuts]{glossaries}

\makeglossaries

\newglossaryentry{short}{name={short},
description={a short entry}}

\longnewglossaryentry{long}{name={long}}
{a long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
paragraph break

long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry a long entry a long entry a long entry a
long entry a long entry
}

\begin{document}
This one works : \gls{short}.
This also works : \gls{long}

\printglossaries

\end{document}

相关内容