# What could go wrong if I don't use * in my \hyperref command?

The Latex manual on wikibooks says that you should use the \hyperref command as follows:

We use \hyperref[mainlemma]{lemma \ref*{mainlemma} }.


Where "mainlemma" is the labelname. It then says:

Note the * after \ref for avoiding nested hyperlinks.

I've implemented this line in my document, once with and once without the * and I did not notice any difference.

So what could be the harm in not using the *?

• I think using autoref is a much better and cleaner way. We use \autoref{mainlemma}. – Johannes_B Oct 3 '14 at 9:03
• I find the LaTeX manual on Wikibooks not completely trustworthy, in general. It's possible, though, that the implementation of \hyperref has changed to make \ref inside its argument to work like \ref*. – egreg Oct 3 '14 at 9:11
• @Johannes_B \autoref does not work desirable in combination with a lemma defined by a \newtheorem-command... – gebruiker Oct 3 '14 at 9:31
• You might want to be a bit more specific on used packages and the not desirable part. Maybe post a minimal working example (MWE). – Johannes_B Oct 3 '14 at 9:37
• You have to keep in mind, that you have to introduce your new theorem/lemma to hyperref. \documentclass{article} \usepackage{hyperref} \newtheorem{lma}{Lemma} \newcommand{\lmaautorefname}{lemma} \begin{document} \begin{lma} a test\label{thm:test} \end{lma} see \autoref{thm:test} \end{document}  – Johannes_B Oct 3 '14 at 9:57

The key issue is that without using the starred version, the document ends up with a nested hyperlink. Since PDF viewers don't have a consistent way of dealing with nested hyperlinks this can lead to unexpected results.

To illustrate this, consider the MWE:

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\section{Sample}
\label{sample}

\section{Another Sample}

\hyperref[sample]{section~\ref{sample}}

\end{document}


In okular this is displayed as:

The use of hidelinks or colorlinks can appear to solve this:

\documentclass{article}

\begin{document}

\section{Sample}
\label{sample}

\section{Another Sample}

\hyperref[sample]{section~\ref{sample}}

\end{document}


In okular this looks like:

But if I change okular's accessibility setting so that links are border it's then displayed as

Since both the inner and outer links point to the same location, the actual hyperlinks in okular will send you to the same place, but it may confuse other PDF viewers. If the inner link points to a different location to the outer link, then there's even more confusion. This can happen when \ref is used in a sectioning command that ends up in the table of contents.

For example:

\documentclass{article}

\begin{document}

\tableofcontents

\section{Sample}
\label{sample}

\section{Another Sample Following on from section \ref{sample}}

\end{document}


Now the table of contents has a nested link but where that link takes you depends on the PDF viewer and whether you used the PDF or DVI format to generate your document. If I compile with pdflatex and then view the document with okular if I click on the inner link I get sent to section 2 but if I view the document in evince the inner link will send me to section 1. If I build the document using latex+dvips+ps2pdf the reverse happens.