Expected behavior:
- Whole ToC line becomes link to section
Observed behavior:
- xelatex - matches expected behavior
- pdflatex - breaks with "\pdfendlink cannot be used in vertical mode" error
Here is mwe:
\documentclass{article}
\usepackage{hyperref}
\usepackage{titletoc}
\makeatletter
\titlecontents{section}[0cm]
{\hyper@linkstart{link}{\Hy@tocdestname}}
{\bfseries\thecontentslabel\hspace{1em}}
{\bfseries}
{\titlerule*[1pc]{.}\contentspage}
[\hyper@linkend]
\makeatother
\begin{document}
\tableofcontents
\section{Test section}
\end{document}
After some googling found, that \protect is needed somewhere, cannot determine where.
\hyper@linkend
is issued in vertical mode and this is not allowed. It would work if you do something like\leavevmode\hyper@linkend
but then you get additional spaces.\hyper@linkend
?