1

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.)

tuculuxu
  • 167
  • 1
  • 11

1 Answers1

3

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:

image of document

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.

Nicola Talbot
  • 41,153
  • 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? – tuculuxu Mar 10 '16 at 14:06
  • I guess it's a version issue – tuculuxu Mar 10 '16 at 14:12
  • @tuculuxu You need at least v4.08, so I'm guessing you have an older version installed. – Nicola Talbot Mar 10 '16 at 14:41
  • Is there an easy way to update packages in ubuntu? – tuculuxu Mar 10 '16 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 http://tex.stackexchange.com/a/13710 – Nicola Talbot Mar 10 '16 at 17:07
  • Yep, I tried to use tlmgr but ubuntu bashes me saying the command is not found... Seems I have texlive installed (but I never really understood this), can't remember how I installed Kile... But I guess it's another question. – tuculuxu Mar 11 '16 at 09:35