TransWikia.com

Change the hyperlink style in glossaries

TeX - LaTeX Asked by Eris on June 17, 2021

I’m using hyperref with glossaries. Per default, glossaries use hyperlink{<target>}{<text>} to generate the hyperlink. This results in the default link color being used (typically, red, or whatever is defined by linkcolor or linkbordercolor). I would like the color of the glossaries links to be different than the standard link color, say, blue instead of red.

I read the extended manual of glossaries but couldn’t figure it out.

The closest I got was this:

renewcommand*{glstextformat}[1]{hypersetup{linkbordercolor={0 0 1}}#1hypersetup{linkbordercolor={1 0 0}}}

but glstextformat changes the text inside the hyperlink, such that I miss the moment where the hyperlink is created, so it’s too late to change the color. So what happens with my command is, after the hyperlink is created, I quickly change the color of all the next links to blue and then immediately change it back, which makes no difference, of course.

I also tried glossaries-extra:

usepackage{glossaries-extra}
glssetcategoryattribute{acronym}{hyperoutside}{false}
newcommand{myformat}[2]{234 #1 #2 123 123}
glssetcategoryattribute{acronym}{textformat}{myformat}

in the hope that the second argument to the textformat command will be the link to use in the hyperlink, but there was no second argument.

Thanks!

EDIT: here’s a minimal working example:

documentclass{book}
usepackage{hyperref}
usepackage{glossaries-extra}

makeglossaries

% GLOSSARY
newglossaryentry{entry}{
    name=glossary entry,
    description={Test description}}

% ACRONYMS
newacronym{test}{TEST}{This Entry Stands for Test} 

begin{document}

hypertarget{tag}{Something something}

Want this gls{entry} to be blue.

This is a simple hyperlink, which should be the default red hyperlink{tag}{some link}.

Want this next glossary link to be blue again: gls{test}.

Thanks.

end{document}

One Answer

It's ugly, but it works.

documentclass{book}
usepackage{xcolor}
usepackage{hyperref}
usepackage{glossaries-extra}

letoldgls=gls
renewcommand{gls}[1]{{hypersetup{linkbordercolor=blue}%
  oldgls{#1}}}%

makeglossaries

% GLOSSARY
newglossaryentry{entry}{
    name=glossary entry,
    description={Test description}}

% ACRONYMS
newacronym{test}{TEST}{This Entry Stands for Test} 

begin{document}

hypertarget{tag}{Something something}

Want this gls{entry} to be blue.

This is a simple hyperlink, which should be the default red hyperlink{tag}{some link}.


Want this next glossary link to be blue again: gls{test}.

Thanks.

end{document}

Correct answer by John Kormylo on June 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP