Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
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. –  Visa is Racism Mar 2 '12 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 Mar 2 '12 at 18:30
add comment

1 Answer

up vote 4 down vote accepted

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}
\usepackage[colorlinks]{hyperref}
\begin{document}
\hypersetup{urlcolor= red}
\url{test}

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

\end{document}
share|improve this answer
    
Great! I didn't know hypersetup could be written in the document body. –  Visa is Racism 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? –  Visa is Racism Mar 2 '12 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 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 –  Visa is Racism 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 –  Visa is Racism Mar 4 '12 at 13:54
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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