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?

  • 1
    Do you mean different link colors?
    – user11232
    Commented Mar 2, 2012 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
    Commented Mar 2, 2012 at 13:08
  • 1
    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
    Commented Mar 2, 2012 at 18:30

1 Answer 1


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:

\hypersetup{urlcolor= red}

\hypersetup{urlcolor= green}

  • Great! I didn't know hypersetup could be written in the document body.
    – Shahbaz
    Commented Mar 2, 2012 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
    Commented Mar 2, 2012 at 15:33
  • 1
    @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
    Commented Mar 2, 2012 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
    Commented Mar 4, 2012 at 13:53
  • In fact, it's no big deal, but if there is such an option it would be easier for me
    – Shahbaz
    Commented Mar 4, 2012 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .