# fontspec \setmainfont over-rides href color

I'm happy with the way fontspec is working for me, but have one problem. I have the command: \setmainfont[Color=393939]{URW Palladio L} which colors all the text in my document. I have darker greys for headings.

The problem is that I want all hyperlinks to be automatically colored with the color of my choice. I use \usepackage{hyperref} \hypersetup{...urlcolor=orange}

Coloring hyperlinks like this works fine if I do not have the \setmainfont[Color=393939]{URW Palladio L} command, but it does not work when it is included.

Is there a way I can color all body text and also automatically color hyperlinks?

Kit

-
Oddly enough, the correct colour is maintained with \url links, just not with \href links. –  Alan Munn Jul 1 '11 at 4:59
The coloring by hyperref relies on the \color macro, which is overridden by the color specification for the font. URL work because they use a different font. –  egreg Jul 1 '11 at 8:20
So the solution would be to "trick" xetex into thinking the hrefs are a different font. Any ideas how that might work? –  Seamus Jul 1 '11 at 14:42

Building again on Alan's answer, this seems to work (even better), so long as the color has been defined beforehand or it's predefined:

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}

\definecolor{mycolor}{rgb}{1,0.3,0.5}

\setmainfont[Color=FF0000]{Linux Libertine O}
\setsansfont[Color=00FF00]{Linux Biolinum O}
\usepackage{hyperref}
\makeatletter
\makeatother

\begin{document}

\href{http://tex.stackexchange.com}{TeX StackExchange}

\href{abc}{TeX StackExchange}
\end{document}


You'll notice that the second hyperlink is colored differently because it's not a URL and filecolor is used.

-
Nicer. :-) I didn't hunt hard enough into hycolor.sty. –  Alan Munn Jul 1 '11 at 16:02
Thank you so much for all this support. I don't even understand what you're doing. Regardless, it is not working for me, the same problem as above (hyperlinks coming out black, but I do have the red and green colours working before the links). I must be doing something very basic wrong here. –  oldmankit Jul 5 '11 at 3:39
Working now that I have up-to-date texlive. Thank you! –  oldmankit Aug 29 '11 at 5:40

Building on Seamus' suggestion in the comments (and edited to include egreg's suggestion) into an answer, here's what seems like a solution:

I redefine the relevant part of the \href command to add the orange colour in the links. I've left the urlcolor in the \hypersetup command to get the color for plain \url links.

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\setmainfont[Color=393939]{Linux Libertine O}
\usepackage{hyperref}
\makeatletter
\def\Hy@href#{%
}
\makeatother
\begin{document}

Nice. However, simply writing \addfontfeatures{Color=orange} instead of \hreffont seems to work the same; it doesn't require a new font family and works also in a "sans serif" context. One should probably act where urlcolor= does its business. –  egreg Jul 1 '11 at 15:24
Thanks, you're right, using \addfontfeatures is a better way to go. I've updated my answer. Your answer is even more general, though. –  Alan Munn Jul 1 '11 at 16:05
@Alan, actually defining a separate font might be a wiser choice (IIRC, \addfontfeatures defines a new font behind the scenes each time it is invoked, which can be expensive resources-wise). –  Khaled Hosny Jul 1 '11 at 17:16
@oldmankit What version of hyperref are you using? Mine is 6.82g (2011/04/17). (Put \listfiles in your preamble to see what versions of the packages are loaded (the list will appear in the log file (or the console output.))) –  Alan Munn Jul 5 '11 at 4:39