1

I know I can use the package hyperref for urls, but I want is to create a definition that uses this and assigns a color, for example

\c{url}{Something} 

would write Something in crimson color linked to the url (and assume default urls aren't in crimson)

1
  • 2
    what about \usepackage[colorlinks=true,urlcolor=magenta]{hyperref} and \href{http://www.myurl.com}{something} ? Commented Apr 6, 2016 at 7:47

1 Answer 1

1

You can use hyperref options, and locally modify it when needed.

\documentclass{article} \usepackage[colorlinks=true,urlcolor=magenta]{hyperref} \newcommand{\myhref}[2] {\hypersetup{urlcolor=blue}% \href{#1}{#2}% \hypersetup{urlcolor=magenta}% } \begin{document} Here is \href{http://www.myurl.com}{my link}. Here is \myhref{http://www.myurl.com}{my special link}. And here, \href{http://www.myurl.com}{another normal link}. \end{document} 

enter image description here

2
  • 1
    This will break if the url contains special chars like % or #. Commented Apr 6, 2016 at 8:01
  • Cf. Special character in url link Commented Apr 6, 2016 at 8:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.