# How to repeat a URL using the hyperref package

Problem:

I have a URL that I need to repeat multiple times over several chapters in a document but after looking and trying to use the hyperref package I was not successful.

Code:

I included the package using \usepackage{hyperref}, then I added the URL using the following:

\href{http://www.google.com}{Google}


Whenever I try to call it using \ref{} the URL will not be printed.

Desired outcome:

Label a URL and reference to it multiple times throughout a document.

• That is not what label and ref, and for that matter, hyperref is meant for. – Willie Wong Jul 28 '16 at 20:05
• But if it is an academic publication, it may be worthwhile putting the url in either the citation or the end notes and refer to it using the usual citation mechanisms. – Willie Wong Jul 28 '16 at 20:09

## 1 Answer

In your preamble write

\newcommand\kexxcreamGoogleUrl{\href{http://www.google.com}{Google}}


and in your body, whenever you want to insert the Google hyperlink, call the macro

the answer to this can be easily found, for example, by searching
on \kexxcreamGoogleUrl.

• Thank you for the suggestion. I received the following error message when I tried this: Undefined control sequence. \kexxcreamGoogleUrl -> \href {http://www.google.com}{Google} l.741 \kexxcreamGoogleUrl – kexxcream Jul 28 '16 at 20:14
• Did you load hyperref? (\usepackage{hyperref}) – Willie Wong Jul 28 '16 at 20:21
• My apologies, I loaded it first but managed to rewind my edits with CMD+Z. Now everything works correctly. I greatly appreciate your time in helping me with this issue. – kexxcream Jul 28 '16 at 20:23