# How to separate glossary entries from section references in hyperref

I have a document, a glossary and references. I am using the hyperref package to create hyperlinks

\usepackage[colorlinks = true,
linkcolor = red,
urlcolor  = green,
citecolor = blue,
anchorcolor = blue]{hyperref}


Apparently, linkcolor colors both glossary entries and Section / Table / Figure numbers in red.

Is there a way to split this? (Actually, I'd like blue for links and normal black for glossary entries.)

• You can temporarily change the colors using \hypersetup (repeatedly). Mar 9, 2016 at 15:41
• What do you mean? Before each call to \gls{} ? Mar 10, 2016 at 14:13
• Yup. See Talbot's answer below. Mar 10, 2016 at 16:51

## 1 Answer

As from glossaries v4.08, the command that performs the actual hyperlink is \glsdohyperlink. The default definition is

\newcommand*{\glsdohyperlink}[2]{\hyperlink{#1}{#2}}


When the hyperlinks are enabled with \glsenablehyper, the internal command that's used for the hyperlinks is set to \glsdohyperlink. (In earlier versions, it was set directly to \hyperlink.) This means that if you want to adjust the hyperlinks, you can redefine \glsdohyperlink and then use \glsenablehyper (rather than having to fiddle with internal commands.) For example:

% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: bibtex
% arara: pdflatex
% arara: pdflatex
\documentclass{article}

\usepackage[colorlinks = true,
linkcolor = red,
urlcolor  = green,
citecolor = blue,
anchorcolor = blue]{hyperref}
\usepackage{glossaries}

\makeglossaries

\newglossaryentry{sample}{name={sample},description={an
example~\cite{article-minimal}}}

\renewcommand*{\glsdohyperlink}[2]{%
{\hypersetup{linkcolor=black}\hyperlink{#1}{#2}}}

\glsenablehyper

\begin{document}

\section{Sample}
\label{sec:sample}

A \gls{sample} entry in section~\ref{sec:sample}.

\printglossaries

\bibliographystyle{plain}
\bibliography{xampl}

\end{document}


This will work for the other glossary entry commands, such as \glstext or \glslink, but not for the links in the location lists. The above produces:

So the citation link is in blue, the cross-references (including location cross-references) are in red and the glossary entry links are in black.

• Thanks for the answer. It didn't work for me though. I tried to copy the whole example but I get this error: \glsdohyperlink undefined ... What should I do? Mar 10, 2016 at 14:06
• I guess it's a version issue Mar 10, 2016 at 14:12
• @tuculuxu You need at least v4.08, so I'm guessing you have an older version installed. Mar 10, 2016 at 14:41
• Is there an easy way to update packages in ubuntu? Mar 10, 2016 at 14:56
• @tuculuxu tlmgr is the best way of updating package but it depends on how you installed the TeX distribution on ubuntu. See tex.stackexchange.com/a/13710 Mar 10, 2016 at 17:07