使用词汇表包进行大写

使用词汇表包进行大写

我有以下最小示例,其中词汇表包的 \Gls 命令似乎不起作用。

%%
% listgloss.text
% Minimal file to test functionality and use of glossaries package
%
% Compile as
%
% pdflatex listgloss
% makeglossaries listgloss
% pdflatex listgloss
% pdflatex listgloss
%%
\documentclass[a4paper]{article}
%
\setlength{\parindent}{0pt}
%
\usepackage{xcolor}
\usepackage{hyperref}% Must now be the second-last package that is loaded
\usepackage[acronym]{glossaries}% Must be last package, loaded after hyperref
%
\newglossaryentry{htdoc}{name={hypertext document},description={Text file with references to other content via hyperlinks}}
%
\newglossaryentry{web}{name={World Wide Web},first={World Wide Web (WWW)}, text={WWW},description={A distributed system of linked hypertext documents}}
%
\newacronym{WWW}{WWW}{World Wide Web}
%
\newacronym{HTML}{HTML}{HyperText Markup Language}
%
\newacronym{SGML}{SGML}{Standard Generalized Markup Language}
%
% Define appearance of link on first citation
%
\renewcommand{\glsdisplayfirst}[4]{\textsf{\textcolor{magenta}{#1}}}
%
\makeglossaries

\begin{document}

% Test of glossary entries
% 1. Capitalization
Should be capitalized: \Gls{htdoc}\\
Should be lowercase: \gls{htdoc}\\
% 2. First use
First use of web: \gls{web}\\
Second use of web: \gls{web}\\

% Test of acronym entries
% SGML Is cited and should be listed
\gls{SGML} is another markup language.\\
% WWW is never cited but should appear in acronym list
\glsadd{WWW}\\
% HTML should not appear in acronym list because not cited and not added
%
\printglossaries
%
\end{document}

我在 64 位 Linux 上使用 TeXLive 2010,词汇表版本是 [2010/07/10 v2.07 (NLCT)]。

有人可以解释一下如何获得正确的显示吗?

短暂性脑缺血发作

答案1

您遇到的麻烦与\glsdisplayfirstTeX 在您的代码中扩展此行后期望看到的内容和实际收到的内容有关:

\renewcommand{\glsdisplayfirst}[4]{\textsf{\textcolor{magenta}{#1}}}

\glsdisplayfirst试图将\textsf{\textcolor{magenta}{#1}}其大写,但在扩展后,其格式不符合要求。您可以先保护其不被扩展,从而修复此问题,例如:

\DeclareRobustCommand\textsfmagenta[1]{\textsf{\textcolor{magenta}{#1}}}
\renewcommand{\glsdisplayfirst}[4]{\textsfmagenta{#1}}

瞧,现在一切正常!

顺便说一句,你的“最小”示例根本不是这样的。也许这样会更好(包括我对你的代码的更新):

\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}% Must now be the second-last package that is loaded
\usepackage[acronym]{glossaries}% Must be last package, loaded after hyperref

\DeclareRobustCommand\textsfmagenta[1]{\textsf{\textcolor{magenta}{#1}}}
\renewcommand{\glsdisplayfirst}[4]{\textsfmagenta{#1}}
\makeglossaries

\begin{document}
\newglossaryentry{htdoc}{name={hypertext document},%
                         description={Text file with references}}
Should be capitalized: \Gls{htdoc}

Should be lowercase: \gls{htdoc}

\printglossaries
\end{document}

相关内容