# 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#{%