Menu

HowTo_Links

How to insert hyperlinks and similar elements (especially in PDFs).

Hyperlinks or clickable cross-references are also among the most common requests. However, strictly speaking, these are only really useful in online or electronic documents. Nevertheless, they can be useful in the design phase. For this you can use the package hyperref. As a special rule, hyperref should be loaded as the last package. As always, there are deviations from this rule of thumb. These are explicitly documented in the instructions for the packages concerned, for example bookmark or cleveref.

By default, links from hyperref are provided with a colored frame which is not printed when printing. This makes the preset best suited for design and print phases. Instead of frames, you can also choose underscores (see the pdfborderstyle option in the hyperref manual), which will also not be printed. This is then useful for documents that should be used both as an online document and as a print version.

For a pure online/electronic document it might be better if the text of the link itself is colored. This is also provided by hyperref. Besides that you can set additional information for the document properties and outlines (aka bookmarks) are created. For the latter, however, the package bookmark is also recommended as an extension. The KOMA-Script classes load the bookmark package automatically when using hyperref. This also avoids some potential problems. Of course this automatism can also be switched off by option.See the KOMA-Script manual.

It should be noted that the hyperref package itself is very good at detecting which TeX engine is being used. Therefore options like pdftex, luatex or xetex are superfluous when using hyperref. In most cases it is therefore also superfluous to distinguish between the different engines in the document preamble and then load hyperref with explicitly different options. Options that are not supported by an engine would be ignored anyway.

Often you will also find that hyperref is loaded with options to explicitly color links black. This is usually done in ignorance of the fact that the colored frames of the default and the alternatively available colored underlining (see above) are not printed as well. Both options are preferable to completely unmarked links, because then you don't have to search for links with the mouse in the PDF version.

Another common mistake is to include information options in \usepackage[...]{hyperref}. Information options are options which have text as their value. Since special encoding requirements apply to such text in PDFs, but the necessary recoding cannot be done reliably with \usepackage, these options should always be set via \hypersetup after loading hyperref, for example:

\usepackage[pdfborderstyle={/S/U/W 1}]{hyperref}
\hypersetup{%
  pdftitle={Mächtige Frauen und Männer},
  pdfauthor={Männe Fräulein},
  pdfsubject={Müßiggang aus Macht}
}

Related

Wiki (English): HowTo_Template

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.