Using hyperref for clickable references and PDF metadata in LaTeX documents
Configure hyperref for clickable cross-references and PDF metadata in LaTeX documents compiled with pdfLaTeX.
29 May 2026, 22:38 UTC

Requirements
The goal is to produce a PDF where internal cross-references (sections, figures, tables, bibliography) are clickable and where document metadata such as title, author, and keywords appear in the PDF viewer's properties pane. The solution must work with the standard pdfLaTeX engine (or XeLaTeX/LuaLaTeX) and should not require privileged system access beyond a normal user LaTeX installation.
Smallest suitable design
Load the hyperref package after most other packages, then configure it with \hypersetup to set the desired link appearance and PDF info fields. This yields the minimal set of commands needed to achieve both clickable links and metadata.
Typical preamble
\documentclass{article}
\usepackage{graphicx} % example of a package that should precede hyperref
\usepackage{hyperref}
\hypersetup{
colorlinks=true, % coloured text instead of boxes
linkcolor=blue, % colour for internal links (sections, refs)
citecolor=green, % colour for bibliography citations
urlcolor=cyan, % colour for external URLs
breaklinks=true, % allow long URLs to break across lines
pdftitle={Sample Document},
pdfauthor={Author Name},
pdfsubject={Demonstration of hyperref},
pdfkeywords={LaTeX, hyperref, PDF metadata}
}
\begin{document}
\section{Introduction}
See Figure~\ref{fig:example}.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\linewidth]{example-image}
\caption{An example figure}
\label{fig:example}
\end{figure}
As shown in~\cite{latex2e}.
\begin{thebibliography}{9}
\bibitem{latex2e} Leslie Lamport, \emph{LaTeX: A Document Preparation System}, 2nd ed., Addison-Wesley, 1994.
\end{thebibliography}
\end{document}
Trust and data boundaries
The hyperref package operates entirely within the LaTeX compilation process; it does not invoke external programs unless the document also loads packages that require shell escape (e.g., minted). Therefore, the trust boundary is the LaTeX engine itself. No privileged system calls are made by hyperref alone, so a standard user account is sufficient.
Operational checks
- Compile the source with
pdflatex mydoc.tex(orxelatex/lualatex). No special flags are needed. - Open the resulting
mydoc.pdfin a PDF viewer (e.g., Okular, Adobe Reader, Evince). - Click on a section number, figure reference, or citation; the viewer should jump to the target location.
- Verify link colour: internal links should appear in the colour set by
linkcolor(blue in the example) without a surrounding box. - Open the document properties dialog and confirm that the fields Title, Author, Subject, and Keywords match the values supplied to
\hypersetup. - If a long URL is present (e.g.,
\url{https://www.example.com/very/long/path/with/many/segments}), ensure it wraps at hyphens or spaces while remaining clickable.
Failure modes
- Missing or misplaced links: Loading
hyperrefbefore a package that redefines\refor\cite(e.g.,cleveref,glossaries) can cause the links to disappear. The remedy is to movehyperrefafter those packages. - Link colour not applied: Forgetting
colorlinks=trueleaves the default boxed links, which may be undesirable for print. Ensure the option is set. - Metadata not appearing: Some PDF viewers hide metadata unless explicitly requested; verify via the viewer's "Properties" or "Document Info" pane.
- Broken line breaks in URLs: Without
breaklinks=true, long URLs may overflow the margin or cause overfull\hboxwarnings. Adding the option resolves this.
Conditions that would change the design
- If the workflow requires external programs that need shell escape (e.g., minted for syntax highlighting), the
-shell-escapeflag must be added to thepdflatexinvocation. In that case, consider isolating untrusted content in a separate file or using a restricted shell escape mode. - When producing PDF/A-compliant documents, certain
hyperrefoptions (like colour links) may need adjustment to meet the standard; consult a PDF/A validator. - If the target audience prefers printed output with no on-screen colour, switch to
hidelinksto keep links functional but invisible, while retaining metadata.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.