3

Can \url and \href commands' hyperlinks be displayed in two different colors. Actually I'd like to keep the default \href color (blue) while displaying the url command color in a different color, e.g. in green.

The question is motivated by my need to "see" hyperlinks generated by the \url command, with a quick inspection of the pdf file.

\documentclass[11pt]{article}
\usepackage{hyperref}
\pagestyle{empty}

\urlstyle{same}

\begin{document}

\url{https://tex.stackexchange.com/} %% <--- Hyperlink in green

\href{https://tex.stackexchange.com/}{https://tex.stackexchange.com/}

\end{document}

1 Answer 1

3

Hope this may helps for you:

\documentclass[11pt]{article}
\usepackage[colorlinks=true,linkcolor=cyan,urlcolor=red]{hyperref}
\pagestyle{empty}

\urlstyle{same}

\DeclareUrlCommand\url{\color{green}}
\begin{document}

\url{https://tex.stackexchange.com/} %% <--- Hyperlink in green

\href{https://tex.stackexchange.com/}{https://tex.stackexchange.com/}

\end{document}

Output

enter image description here

2
  • Hello. If the links are broken to two lines, they aren't right links.
    – Y. zeng
    Jun 28 at 8:13
  • Please use PDFLaTeX, or XeLaTeX, or LuaLaTeX, etc...
    – MadyYuvi
    Jun 28 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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