Consider the following MWE that creates a TOC with three entries, all are linked to their respective sections in the document.
\documentclass{scrartcl}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\clearpage
\section{Section with link}
\clearpage
\section{Section without link}
% \section*{Section without link}
% \addcontentsline{toc}{section}{Section without link}
\clearpage
\section{Section without link 2}
\end{document}
I would like to disable the links only for the latter entries. Is there a solution for this that I can't find? I'm glad for any hints!
Background:
In my final document the latter sections will include external PDFs (reference letters). This means I will throw away the page with the actual section headings and merge the document with the other PDFs. This way the page numbers in the TOC will be correct but the link would lead to page one (since the actual page does no longer exist) – therefore I'd rather have no link at all.
I know I could use something like pdfpages
to just include the PDFs directly but this destroys hyperlinks in the included documents and therefore is not an option for me.
Best Answer
There is a package option
linktoc=none
in hyperref that disables links in the TOC. You can turn on this option midway through the TOC by changing the value of the corresponding macro\Hy@linktoc
from within the.toc
file.This can be done by using the low-level
\addtocontents{ext}{...}
macro that writes the second argument into the file with the extensionext
. In this case:Full MWE, including
\makeatletter
and\makeatother
:This creates the following
.toc
file:The link targets
section.2
andsection.3
are still generated, but because of the option setting they will not show as actual links.Result: