Glossary link's color
Normally the link color is set via the option linkcolor
of the package hyperref
. To influence only the link color of glossaries
you must redefine the command \glstextformat
. In the documentation you can find:
The way the link text is displayed depends on
\glstextformat{⟨text⟩}
For example, to make all link text appear in a sans-serif font, do:
\renewcommand*{\glstextformat}[1]{\textsf{#1}}
In relation to this comment here an example:
\documentclass[10pt,a4paper]{report}
\usepackage{xcolor}
\usepackage[colorlinks=true]{hyperref}
\usepackage[xindy]{glossaries}
\renewcommand*{\glstextformat}[1]{\textcolor{green}{#1}}
\makeglossaries
\newglossaryentry{A}{name={A}, description={A is A}}
\newglossaryentry{AA}{name={AA}, description={AA is AA}}
\newglossaryentry{B}{name={B}, description={B is B}}
\newglossaryentry{C}{name={C}, description={C is C}}
\newglossaryentry{CC}{name={CC}, description={CC is CC}}
\begin{document}
Here I cite either \gls{A}, \gls{AA}, \gls{B}, \gls{C} or \gls{CC}.
I want three groups in the glossary output, indicated by \textbf{A},
\textbf{B} and \textbf{C} with entries in them according to their initial letter.
\printglossary[style=indexgroup]
\end{document}
I had a similar request, with the only difference that I didn't want to have any colored glossary links at all. Marco's solution wasn't satisfying for me as it changes all links to a specific color. Instead I wanted to keep the corresponding current text color.
Another approach might be setting the hyperlink color to the current text color (.
) before the hyperlink is created and resetting it to the globally used link color (\@linkcolor
) afterwards in a new command:
\newcommand*{\glsplainhyperlink}[2]{%
\colorlet{currenttext}{.}% store current text color
\colorlet{currentlink}{\@linkcolor}% store current link color
\hypersetup{linkcolor=currenttext}% set link color
\hyperlink{#1}{#2}%
\hypersetup{linkcolor=currentlink}% reset to default
}
Then, override the existing \@glslink
to use our command:
\let\@glslink\glsplainhyperlink
Complete example with a black link on white background and a white link on a black background:
\documentclass{report}
\usepackage{xcolor}
\usepackage[colorlinks,linkcolor=green]{hyperref}
\usepackage{glossaries}
\makeatletter
\newcommand*{\glsplainhyperlink}[2]{%
\colorlet{currenttext}{.}% store current text color
\colorlet{currentlink}{\@linkcolor}% store current link color
\hypersetup{linkcolor=currenttext}% set link color
\hyperlink{#1}{#2}%
\hypersetup{linkcolor=currentlink}% reset to default
}
\let\@glslink\glsplainhyperlink
\makeatother
\makenoidxglossaries
\newglossaryentry{GPU}{name={GPU}, description={Graphics Processing Unit}}
\begin{document}
I need a faster \gls{GPU}.
\colorbox{black}{\color{white}I need a faster \gls{GPU}.}
\printnoidxglossary
\end{document}