[Tex/LaTex] hyperlink inside chapter / section title

chaptershyperrefsectioning

I would like to have the possibility to have a hyperlink inside a chapter / section title.

MWE:

 \documentclass[twoside]{book}

 \usepackage[pdftex,pagebackref=true]{hyperref}
 \begin{document}
 \chapter{documentation for link to Section 1}
 %%\chapter{documentation for link to \hyperlink{sec1}{Section 1}}

 \hypertarget{sec1}{}\section{Section 1 Reference}

 \hypertarget{sec2}{}\section{Section 2 Reference}
 documentation for \hyperlink{sec1}{Section 1}

 \end{document}

This results in the following output:
enter image description here

We see in section 1.2 the hyperlink to section 1.1, but I want to have the link also in the chapter title. When adding a second chapter with a hyperlink (remove %% ) I get the error message:

Chapter 1.

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing `\<let>-command' on input line 6.


Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing `\Hy@reserved@a' on input line 6.


Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing `\@ifnextchar' on input line 6.

! Undefined control sequence.
\hyper@@link ->\let \Hy@reserved@a
                                   \relax \@ifnextchar [{\hyper@link@ }{\hyp...
l.6 ...on for link to \hyperlink{sec1}{Section 1}}

?
! Emergency stop.
\hyper@@link ->\let \Hy@reserved@a
                                   \relax \@ifnextchar [{\hyper@link@ }{\hyp...
l.6 ...on for link to \hyperlink{sec1}{Section 1}}

!  ==> Fatal error occurred, no output PDF file produced!

Question:
How to get the hyperlink in the chapter (/section) title.

Best Answer

I would use \labels and then \hyperref[<label>]{<text>} for custom text or maybe even cleveref's \cref.

\documentclass[twoside]{book}

\usepackage[pdftex,pagebackref=true]{hyperref}
\begin{document}
\chapter{documentation for link to \hyperref[sec1]{Section 1}}

\section{Section 1 Reference}\label{sec1}

\section{Section 2 Reference}\label{sec2}
documentation for \hyperref[sec1]{Section 1}
\end{document}

If you want to stick to \hyperlink you need to \protect it because it is a fragile command.

\chapter{documentation for link to \protect\hyperlink{sec1}{Section 1}}

You didn't need to protect \hyperref in the example above because it is a robust command. See What is the difference between Fragile and Robust commands? for an in-depth explanation of fragile vs. robust commands.