[Tex/LaTex] Undefined color error for URL, when compiling with XeLaTeX

colorhyperrefurlsxetex

I've defined a different color for hyperlink using \hypersetup command with urlcolor. When I am compiling it with XeLaTeX I am getting undefined color error for the URL link, but it works fine when I compile with LaTeX (the color of the link changes). Similar error have been discussed before here and here, but my problem seems to be a bit different. Below is a simplified example of code I am trying to compile:

\documentclass[10pt, a5paper]{article}
\usepackage{fontspec}
\PassOptionsToPackage{pdftex,usenames,dvipsnames}{color}
\usepackage[bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup{linkcolor=blue,citecolor=blue,filecolor=black,urlcolor=MidnightBlue} 
\begin{document}
\begin{center}
\href{https://tex.stackexchange.com/}{https://tex.stackexchange.com/}
\end{center}
\end{document}

Best Answer

You would also receive a host of other errors. Here it is best to use

\usepackage[usenames,dvipsnames]{xcolor}

rather than "passing the options to the package". Since you're processing your file under xelatex anyway, I've dropped the driver support pdftex. By default I use xcolor, although you could also use color.

enter image description here

\documentclass[10pt, a5paper]{article}
\usepackage{fontspec}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup{linkcolor=blue,citecolor=blue,filecolor=black,urlcolor=MidnightBlue} 
\begin{document}
\begin{center}
\href{http://tex.stackexchange.com/}{http://tex.stackexchange.com/}
\end{center}
\end{document}​
Related Question