# Capitalization with glossaries package

I have the following minimal example in which the \Gls command of the glossaries package does not seem to work.

%%
% 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
% HTML should not appear in acronym list because not cited and not added
%
\printglossaries
%
\end{document}


I am using TeXLive 2010 on 64-bit Linux and the version of glossaries is [2010/07/10 v2.07 (NLCT)].

Can anyone throw light on how to get the correct display, please?

TIA

-

The trouble you've got has to do with what \glsdisplayfirst expects to see and what it actually receives after TeX expands this line in your code:

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


\glsdisplayfirst is trying to capitalize \textsf{\textcolor{magenta}{#1}} which, after expansion, is not in the form it needs to be. You can fix things up by protecting it from expansion first, e.g., like this:

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


Voila, now things work!

BTW, your "minimal" example was anything but. Maybe something this would have been better (incudes my updated to your code):

\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}

-
Thank you for your explanation as well as solution. And my apologies for posting my overall test file rather than a minimal example. – chandra Nov 4 '10 at 15:20