[Tex/LaTex] How to create internet link in PDF

links

Let us consider the following example :

\documentclass[11pt,twoside,a4paper]{book}
\usepackage{hyperref}
\begin{document}
For more information about 'TikZ' click on the following link :
\href{url}{http://www.texample.net/tikz/resources/}
\end{document}

This gives :
enter image description here

When I click on the link on the PDF file it is not working. What is the way to go webpage clicking on the link ?

Best Answer

You have the two parameters backwards. The correct syntax is:

\href{<url>}{<text to display>}. 

The first parameter is the url to link to, the second is the text to display.

Also it should be noted that you need to ensure that your PDF viewer is capable of opening a link in a browser.

Code:

\documentclass[11pt,twoside,a4paper]{book} 
\usepackage{hyperref} 
\begin{document} 
    For more information about 'TikZ' click on the following link: 
    \href{http://www.texample.net/tikz/resources/}{Tex Example Site}
\end{document}

Although this question is only about linking to external URLs, one can use \href to open other types of files as well. So with the example below (assuming that there exists a foo.pdf, foo.tex, foo.png files in the current directory), and viewing with TeXShop's PDF viewer, all the files can be opened by clicking on the links.

However, with TeXWorks and Mac Preview only the web url link works. All the links also work with Acrobat once you accept the security warning.

enter image description here

Code:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\href{http://www.google.com}{Google}
\href{run:foo.pdf}{My PDF}
\href{run:foo.tex}{My TeX}
\href{run:foo.png}{My PNG}
\end{document}
Related Question