# How to use different colors for different \href commands?

I have two different \href{}{} links and I want each to be a different color. In the example below they will both be blue, how can I make each link have a different color?

\documentclass{article}
urlcolor  = blue,
citecolor = blue,
anchorcolor = blue]{hyperref}
\begin{document}
\end{document}


-

You can define a custom \MYhref macro to provide a color change with an optional parameter. If you don't provide the first parameter you would get the first line (which is identical to what your code produces). The second line illustrate the how you can change the color with the optional parameter:

## Code:

\documentclass{article}
\usepackage{xcolor}
urlcolor  = blue,
citecolor = blue,
anchorcolor = blue]{hyperref}

\newcommand{\MYhref}[3][blue]{\href{#2}{\color{#1}{#3}}}%

\begin{document}

\end{document}

-
I applied this procedure but after replacing href with MYhref (no matter if I define a color or not), instead of looking in the internet, it tries to open a file and it writes: "Go to file "Google.pdf" " for example –  makhlaghi Jun 24 '12 at 8:47
@astroboy: Opps.. there was a typo in the definition of \MYhref- the first parameter to \href was wrong. Try with the new definition. –  Peter Grill Jun 24 '12 at 8:50
Yes, now it is working perfectly. Thanks a lot.... –  makhlaghi Jun 24 '12 at 8:58

One way to go is to define a command that change the color before the call to \href.

Example:

\documentclass{article}
urlcolor  = blue,
citecolor = blue,
anchorcolor = blue]{hyperref}

\newcommand{\changeurlcolor}[1]{\hypersetup{urlcolor=#1}}

\begin{document}

Yes: indeed what I noticed from your answer is that my approach does not provide a way to use the default color. I mean: once one has called \changeurlcolor that is the new standard. Your answer, instead, allows to come back to the standard. –  Claudio Fiandrino Jun 24 '12 at 8:30