hyperref turns cross-references, citations, table-of-contents entries, and URLs into clickable links inside the PDF**, and even sets up bookmarks (the PDF outline) and metadata such as the title. Loading it is a single line — \usepackage{hyperref} — but it comes with one iron rule: load it almost last. This page walks through that rule, link colors and borders, making links with \href and \url, and getting Japanese bookmarks right.
Loading it, and the order
Using it is genuinely simple: just put \usepackage{hyperref} in the preamble. From then on cross-references (\ref), citations (\cite), table-of-contents entries, footnotes, and the like become links automatically — click one in a PDF viewer and you jump to its target. With no configuration at all, every reference in the document is already a working link.
What you must watch is where you load it. hyperref redefines many commands internally — \ref, \cite, \section, and more — to make them link. So unless it is loaded after other packages that touch those same commands, its redefinitions get clobbered. The rule of thumb is clear: **put hyperref almost last in the preamble**, after most other packages.
But “last” has a few exceptions. The notable one is **cleveref**, which works by detecting hyperref’s definitions and therefore **must come after hyperref**. If you also use varioref, order them varioref → hyperref → cleveref. Get the order wrong and references can break with no warning in the log (see the cross-references page for cleveref details).
% プリアンブルのほぼ最後で読み込む / load almost last
\usepackage{graphicx}
\usepackage{amsmath}
% ... 他のパッケージ ... / ... other packages ...
\usepackage{hyperref} % ほぼ最後 / almost last
\usepackage{cleveref} % hyperref の後(数少ない例外)/ after hyperref (an exception)Link appearance — colors and borders
By default a link is shown by drawing a colored box (border) around the text. That is easy to spot on screen, but in print the box prints while the link does not, which looks poor — so it is often unwanted. You control appearance either with options at load time or, more flexibly, with **\hypersetup{...}**, listing key=value pairs separated by commas. \hypersetup may appear anywhere in the preamble.
The most-used option is **colorlinks=true, which drops the box and colors the link text itself (it survives printing and stays readable on screen). You set colors per kind: linkcolor** (internal links like \ref), **citecolor (bibliographic citations), urlcolor** (URLs from \url/\href), and **filecolor** (links that open local files). Their defaults are red, green, magenta, and cyan respectively.
For print, **hidelinks is handy: it applies neither color nor border**, so links look completely invisible while still remaining clickable. Conversely, when you do keep the boxed look (colorlinks=false) and want to recolor every border at once, **allbordercolors** sets all border colors together.
| Option | Effect |
|---|---|
colorlinks=true | Drop the box; color the link text instead |
hidelinks | No color, no border; still clickable (for print) |
linkcolor | Color of internal links like \ref (default: red) |
citecolor | Color of bibliographic citations (default: green) |
urlcolor | Color of URL links (default: magenta) |
filecolor | Color of links to local files (default: cyan) |
allbordercolors | Set all border colors at once |
Making links — \href and \url
You make links to external URLs with two commands. **\href{URL}{display text} attaches a link to any text you like (write \href{https://www.ctan.org/}{CTAN} and the word “CTAN” becomes the link). \url{URL}, by contrast, typesets the URL itself in a monospaced font and makes it a link at the same time.** Use \url when you want the URL visible in the text, \href when you want it hidden behind other words.
URLs often contain LaTeX special characters such as %, #, ~, and _, and the advantage of \url and \href is that you can write those literally in the URL part (no escaping needed — though the argument of \url has a few limitations). When you want the monospaced look of a URL but no link at all, use **\nolinkurl{URL}** (same typesetting as \url, without the hyperlink).
詳しくは\href{https://www.ctan.org/pkg/hyperref}{hyperref のページ}を参照。
% 「hyperref のページ」がリンクになる / the words become the link
ダウンロードは \url{https://www.ctan.org/} から。
% URL がそのまま組版され、かつリンクになる / URL is typeset and linked
リンクなしで URL を見せる: \nolinkurl{https://example.com/a_b#c}
% 等幅で表示、リンクは張らない / monospaced, no linkPDF metadata
hyperref also sets the PDF’s document information (metadata) — the fields shown under “Document Properties” in a PDF viewer and used by search and library tools. You give them via \hypersetup with these keys: **pdftitle (title), pdfauthor (author), pdfsubject (subject), and pdfkeywords** (keywords).
If a value contains a comma or equals sign it collides with the key separators, so it is safest to **wrap each value in braces {}** (e.g. pdftitle={Foundations of Linear Algebra}). Note that this is separate from the document’s own \title, which is not copied into the metadata — to keep them in sync, write the same string by hand or use a mechanism like pdfusetitle.
Bookmarks (the PDF outline)
Bookmarks (the outline) are the collapsible list of headings a PDF viewer shows alongside the page — essential for navigating a long document. hyperref generates them automatically from the document’s headings (chapters, sections, and so on; bookmarks=true is the default). To include section numbers in the bookmarks use **bookmarksnumbered=true, and to show the tree expanded from the start use bookmarksopen=true**.
For more robust handling there is the **bookmark** package (loaded after hyperref). It replaces hyperref’s older bookmark code, lets you set the style and color of bookmarks, and stabilizes how the .out auxiliary file is processed. You can fine-tune behavior with \bookmarksetup{...}. It is the go-to fix when bookmarks misbehave in a complex document.
Japanese bookmarks and avoiding garbled text
Because bookmarks and metadata are written as strings inside the PDF, including Japanese (CJK) can produce garbled text. The key is to write them as Unicode. On modern engines (LuaLaTeX / XeLaTeX) unicode is enabled by default, so Japanese bookmarks usually come out correct with no extra setup. To be explicit, load \usepackage[unicode]{hyperref} or set \hypersetup{unicode}.
In the traditional pLaTeX / upLaTeX + dvipdfmx setup, the standard recipe is to load hyperref as \usepackage[dvipdfmx]{hyperref} and add the **pxjahyper** package. pxjahyper exists precisely to produce Japanese bookmarks without garbling in the (u)pLaTeX environment, and it ships with TeX Live. Depending on the engine it helps convert output to Unicode according to the internal kanji code (the kind of work pdfencoding=auto does).
pdfencoding=auto is the option that decides automatically: keep strings as-is if they fit in ASCII (within ASCII when a Unicode engine is used), and switch to Unicode otherwise (mainly for the pdfTeX family; on Unicode engines Unicode is already the default, so it is usually unnecessary). When in doubt, it is enough to remember: **on LuaLaTeX, no extra setup; on (u)pLaTeX, add pxjahyper.**
% --- pLaTeX / upLaTeX + dvipdfmx の場合 / for pLaTeX-upLaTeX + dvipdfmx ---
\usepackage[dvipdfmx]{hyperref}
\usepackage{pxjahyper} % 日本語しおりの文字化けを防ぐ / fix Japanese bookmarks
% --- LuaLaTeX の場合は unicode が既定 / on LuaLaTeX, unicode is the default ---
% \usepackage{hyperref}Reference commands hyperref adds — \autoref and \nameref
Loading hyperref also gives you two commands that help with cross-referencing. **\autoref{key}** is used in place of \ref: it prepends the word for the target’s kind automatically — “section 3.4,” “Figure 3,” and so on — and makes the whole thing a link. You can change the prepended word by redefining \figureautorefname, \sectionautorefname, and the like, which is also how you localize it to Japanese.
The other, **\nameref{key}, inserts not a number but the title text** of the target (reference the label on \section{Introduction} and it prints “Introduction”). Use it when you want to refer by title rather than number. The full picture of the referencing commands (\ref, \eqref, \cref, and so on) is covered on the cross-references page.
A worked configuration
A configuration commonly used in practice looks like this. It turns off the box and colors text with colorlinks=true, sets distinct colors per kind, builds numbered bookmarks with bookmarksnumbered, and fills in the metadata. For print-first documents, replace the colorlinks=true line with hidelinks and the links become invisible while staying clickable.
\usepackage{hyperref}
\hypersetup{
colorlinks=true, % 枠ではなく文字に色 / color text, not boxes
linkcolor=blue, % 内部リンク / internal links
citecolor=teal, % 文献引用 / citations
urlcolor=magenta, % URL
bookmarksnumbered=true, % しおりに節番号 / numbered bookmarks
pdftitle={線形代数の基礎},
pdfauthor={山田 太郎},
pdfsubject={講義ノート},
pdfkeywords={LaTeX, 線形代数, ベクトル空間},
}
% 印刷向けなら colorlinks の行を hidelinks に置き換える
% for print, swap the colorlinks line for: hidelinks