I'm in the process of writing my thesis which has a large glossary. The hyperref and glossaries package allow for linking and colouring the references, which is great. Unfortunately the large number of coloured entries is visually overwhelming. To circumvent this I edited the \glsdisplayfirst and \glsdisplay commands as follows,

which works effectively for \gls, \Gls and \GLS. This allows the first use of the glossary entry to be coloured differently to all subsequent uses. In this case the first entry is "blue" and the rest match the colour of the body text (BLACK). I arrived at these commands mostly by trial and error.

Unfortunately when I add the siunitx package \Gls and \GLS building the document returns the following error.

The conflict seems independent of where the \usepackage{siunitx} statement is located in the preamble. There does not appear to be a reference to @definecolor in siunitx.sty. \usepackage{siunitx} is commended out in the worked example below, uncomment to produce the error. Although I'm familiar with LaTeX, this is definitely beyond my experience. I'm not sure where to start resolving this issue, any help would be appreciated.

A separate and minor issue:
using the command \newacronym disables the two edited commands (\glsdisplayfirst and \glsdisplay) reverting all glossary entries to their original colour "red". Although this is an issue I can work around by only using \gls, any insight into why this happens would also be helpful. Code to test this issue is commented out in the worked example below.

Worked example

% document must be saved as "document.tex" for the makeindex command.
\documentclass[a4paper]{scrbook}
% \usepackage{siunitx}
% Colour
\usepackage{color}
\usepackage{xcolor}
% black must be capitalised due to the way glossaries works
\definecolor{BLACK}{RGB}{0,0,0}
% Hyperlinks
\usepackage{hyperref}
\hypersetup{colorlinks = true}
% Glossary
\usepackage[toc]{glossaries}
% define the colour of the first instance
\renewcommand{\glsdisplayfirst}[4]{\textcolor{blue}{#1}}
% define the colour of all subsequent instances
% as the subsequent entries are capitalised the colour BLACK must be defined
\renewcommand{\glsdisplay}[4]{\textcolor{black}{#1}}
% the following code automates the makeindex process
% borrowed from http://www.freiheitsfreund.de/2010/10/automatically-run-makeindex-from-within-a-latex-document-with-write18/
\def\execute{%
\begingroup
\catcode`\\=12
\executeaux}
\def\executeaux#1{\immediate\write18{#1}\endgroup}
\execute{makeindex -s document.ist -t document.glg -o document.gls document.glo}
\makeglossaries
%-------------------------
\begin{document}
\newglossaryentry{tla}{
name={TLA},
description={Three Letter Acronym},
first={Three Letter Acronym (TLA)}
}
%\newacronym{ana}{ANA}{A New Acronym}
Following is an example of a \gls{tla}.
Repeated again to demonstrate the desired change in colour at subsequent use \gls{tla}.
Again using the capitalised versions: 1) first letter \Gls{tla}, and 2) entire word \GLS{tla}.
%Using the newacronym command \gls{ana}, \Gls{ana} and \GLS{ana}
\printglossaries
\end{document}

Thanks in advance for your help.

EDIT

The second \renewcommand that is causing the issues. By removing it and placing the statement \hypersetup{linkcolor=black} after the table of contents (in my own example) I have been able to achieve the same result without the siunitx conflict; avoiding the problem rather than solving it.

1 Answer
1

Issue with color

The documentation for \glsdisplay contains a red box:

Care needs to be taken when redefining \glsdisplay and
\glsdisplayfirst as commands like \Gls will expand the displayed
text before applying \makefirstuc. If you want to use formatting
commands, it’s best to define a robust version that deals with all the
formatting. For example, suppose you want the text to appear in bold
italic, it’s best to do something like:

Issue with \newacronym

Thanks for your help @Oberdiek. Those four commands work brilliantly. I'll spend some time reading up on mfirdtuc. RE: \newacronym I get the error (/usr/local/texlive/2013/texmf-dist/tex/latex/glossaries/styles/glossary-tree.s ty)) ! Undefined control sequence. <argument> \glsdefaulttyp l.33 \DeclareAcronymList{\glsdefaulttyp}
–
user37061Sep 22 '13 at 8:12