# TOC / Bookmark and hyperlink inside a chapter / section title

This is a followup question on hyperlink inside chapter / section title in respect to the display in the TOC and bookmarks section of the resulting pdf.

\documentclass[twoside]{book}

\usepackage[pdftex,pagebackref=true]{hyperref}
\begin{document}
\tableofcontents

\chapter{documentation for link to Section 1}
\chapter{documentation for link to \hyperref[sec1]{Section 1}}

\hypertarget{sec1}{}\section{Section 1 Reference}
\label{sec1}\index{ref1@{ref1}}

\hypertarget{sec2}{}\section{Section 2 Reference}

\end{document}


This results in the contents page:

and a Bookmark section:

In the contents page we see for chapter 2 and 3 (\protect and \hyperref implementation) an extra vertical red bar before the "Section 1" text, this is a an extra hyperref when clicking on "documentation for link" we jump to the relevant chapter, but wen clicking on the "Section 1" part we jump to the subsection. I think that in the the TOC part it is not good that depending on where one clicks on the line a different jump is made.

Looking at the bookmarks section we see here for the chapters 2 and 3 the texts "sec1Section" and "[sec1]Section" so with extra "sec1" and "[sec1]".

How can I get a "clean" TOC / Bookmarks part?

• Have a look at tex.stackexchange.com/q/227086/35864 May 31, 2018 at 13:59
• is there a reason you can't use the optional "short title" for these titles, e.g., \chapter[documentation for link to Section 1]{<full title>} ? May 31, 2018 at 14:18
• @barbarabeeton Thanks for the suggestion, very interesting possibility, I have to investigate but first test looks like to work for me as well. May 31, 2018 at 14:54
• the "short title" option is the canonical mechanism for specifying an entry for the table of contents and running head, and that should be the first thing tried for the book class. but some document classes do things differently, and it's worth knowing that that's the case. May 31, 2018 at 15:56

\texorpdfstring is your friend to put the TeX stuff in its first argument and the stuff that belongs to the PDF bookmark to the second:

\documentclass[twoside]{book}

\usepackage{hyperref}
\begin{document}
\tableofcontents

\chapter{documentation for link to Section 1}
\texorpdfstring{\hyperref[sec1]{Section \ref*{sec1}}}{Section \ref{sec1}}}

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

\section{Section 2 Reference}
documentation for \autoref{sec1}

\end{document}


Workaround A: Option linktocpage of package hyperref to make the page numbers instead of the chapter/section titles to links.

Workaround B:

\documentclass[twoside]{book}

\usepackage[pagebackref=true]{hyperref}

\newif\ifInToc
\ifInToc
\begin{NoHyper}#1\end{NoHyper}%
\else
#1%
\fi
}

\begin{document}

\InToctrue
\tableofcontents
\InTocfalse

\chapter{documentation for link to Section 1}
\texorpdfstring{%