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

  • You can temporarily change the colors using \hypersetup (repeatedly). – John Kormylo Mar 9 '16 at 15:41
  • What do you mean? Before each call to \gls{} ? – tuculuxu Mar 10 '16 at 14:13
  • Yup. See Talbot's answer below. – John Kormylo Mar 10 '16 at 16:51
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.

  • 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 tex.stackexchange.com/a/13710 – Nicola Talbot Mar 10 '16 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.