The hyperref package

Turns cross-references, citations, the table of contents and URLs into clickable links and writes bookmarks and metadata into the PDF; \href, \url and \hypersetup are its main commands.

Loading the package

\usepackage{hyperref}

Loading the package is enough to make every \ref, \cite, footnote mark and entry of the table of contents a link inside the PDF. The section headings also appear as bookmarks in the side panel of the PDF viewer.

By default a link is marked with a coloured frame that is visible on screen. colorlinks=true colours the link text instead, and hidelinks removes every marking while the links keep working.

All settings go into \hypersetup{...} or into the package options. This includes the document properties pdftitle, pdfauthor and pdfkeywords.

Main commands

\href{https://example.org}{link text}Link to a web address with a text of your choice; mailto: addresses work too.
\url{https://example.org}Prints the address itself and links it.
\hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue}Coloured link text instead of frames, with one colour each for internal links, URLs and citations.
\usepackage[hidelinks]{hyperref}Links without frame and without colour, for documents that will be printed.
\autoref{sec:intro}Reference with the kind of object in front, for example "section 1", all of it a link.
\nameref{sec:intro}Prints the title of the referenced section instead of its number.
\hyperref[sec:intro]{the introduction}Link to a label with a text of your choice.
\texorpdfstring{$\alpha$}{alpha}In a heading: the first argument is typeset, the second one goes into the bookmark.

Complete example

\documentclass{article}
\usepackage{hyperref}
\hypersetup{
  colorlinks=true, linkcolor=blue, urlcolor=blue,
  pdftitle={Links in a PDF}, pdfauthor={A. Author}
}
\begin{document}
\tableofcontents
\section{Introduction}\label{sec:intro}
The project page is \url{https://example.org/project}, and the
\href{https://example.org/manual.pdf}{manual} is a PDF file.

\section{\texorpdfstring{$\alpha$}{Alpha} decay}
See \autoref{sec:intro}, called \nameref{sec:intro}, or jump to
\hyperref[sec:intro]{the first section}.
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → pdflatex.

Pitfalls

Related pages