# How to have multiple link styles with hyperref?

I have hyperrefs in many places in my program. Part of it is in normal text, which I have styled with \hypersetup.

I also have some listings inside which I use hyperref. The problem is, the listings has its own style, so I want to have a different style for hyperref.

Is such a thing possible? Can you have two hyperrefs in the same document with different styles?

-
Do you mean different link colors? – Harish Kumar Mar 2 '12 at 11:06
@Dr.HarishKumar For example. Or any other style related stuff. Let's say, one hyperref that has colorlinks true and the other false. – Shahbaz Mar 2 '12 at 13:08
This is IMHO a duplicate of tex.stackexchange.com/questions/45560/…, but my answer there lacks the part of \Hy@DisableOption{...} as in Ulrike’s answer. – Speravir Mar 2 '12 at 18:30

hyperref disables some options (with \Hy@DisableOption{...}) in the package, other at the begin of the document. These options (including colorlinks)can't be changed in the mid of the document.

But other options can be changed without problem:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\hypersetup{urlcolor= red}
\url{test}

\hypersetup{urlcolor= green}
\url{test}

\end{document}

-
Great! I didn't know hypersetup could be written in the document body. – Shahbaz Mar 2 '12 at 15:31
Quick side question, is it possible to tell hyperref to have urlcolor equal to whatever the text itself is? So its color would follow the color of the the text. If the link is in some red text, it would be red and if in green text it would be green? – Shahbaz Mar 2 '12 at 15:33
@Shahbaz: Yes, that’s exactly the effect of colorlinks=true (Ulrike used the equivalent short form). Or did you mean something like \definecolor{textcolor}{named}{black} \color{textcolor} \hypersetup{colorlinks,urlcolor=textcolor}? – Speravir Mar 2 '12 at 18:46
@speravir: I mean something like this: \hypersetup{colorlinks,urlcolor=blue} in the preamble, and then later something like: \hypersetup{urlcolor=follow-text} and then have \color{red} some text \url{this url will be red} some text \color{green} some text \url{this url will be green} some text \hypersetup{urlcolor=blue}. Of course, everywhere else in the document, the url would be blue – Shahbaz Mar 4 '12 at 13:53
In fact, it's no big deal, but if there is such an option it would be easier for me – Shahbaz Mar 4 '12 at 13:54