I'm referring to chapters and sections in a description list. I want the link to include the chapter or section part as well.

I found two options to achieve this: use \protect or use \texorpdfstring. Both appear to work and do the same thing.

Are there differences between these two, and should I prefer one over the other?



Both options work:

  \item [Section~\ref{sec:label}] foo 1

  % This fails, need braces for protected contents:
  %\item [\protect\hyperref[sec:label]{Section~\ref*{sec:label}}{}] foo 2

  \item [\protect{\hyperref[sec:label]{Section~\ref*{sec:label}}{}}] foo 2

  \item [\texorpdfstring{\hyperref[sec:label]{Section~\ref*{sec:label}}{}}{}] foo 3

\section{First Section is Here}

enter image description here


You need neither one, because the cause of the problem is the optional argument inside an optional argument:


Now, the optional argument of \item is formally closed, but the closing bracket belongs rather to \hyperref and therefore \hyperref will fail, because of the incomplete syntax.

Fix: Just add a pair of braces:

\item[{\hyperref[sec:label]{Section~\ref*{sec:label}}}] foo 2

Then, the TeX macro argument parser does not disrupt the argument group and the optional argument for \item becomes the full \hyperref[sec:label]{...}. The outmost argument braces are automatically removed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.