# How to use the long section caption for bookmarks with hyperref

The package hyperref uses the short caption of a section for the bookmark entry. Is it possible to use the long form instead? I have many sections so manually adding all of them to the bookmarks is not an option.

MWE

\documentclass{article}

\begin{document}

\section[Short title for toc]{A very long title which should also be visible as bookmark}

\end{document}


If all long section, subsection etc. titles should appear in the bookmarks, perhaps the easiest way is to shift the \toclevel@... to something far beyond the real levels, say add 1000, add the normal contentsline and use and explicit \pdfbookmark[...]{...}{...}.

\documentclass{article}

\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@sect}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
}{%
\csletcs{orig@toclevel}{toclevel@#1}%
\expandafter\renewcommand\csname toclevel@#1\endcsname{\the\numexpr#2+1000}
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
\pdfbookmark[#2]{#8}{\csname theH#1\endcsname}%
\expandafter\renewcommand\csname toclevel@#1\endcsname{\orig@toclevel}% Restore
}{}{}
\makeatother

\usepackage{blindtext}

%\usepackage{hyperref}
\usepackage{bookmark}

\begin{document}
\tableofcontents
\clearpage
\section[Short title for toc]{A very long title which should also be visible as bookmark}
\blindtext[5]
\section[Another Short title for toc]{Another very very long title which should also be visible as bookmark}
\blindtext[6]
\subsection{A subsection title}
\section[Yet another Short title for toc]{Yet another very very long title which should also be visible as bookmark}
\blindtext[6]

\subsection{Another subsection title}

\subsubsection[Short subsubsection]{Another long long subsubsection title}

\subsection[Short subsection title one level higher]{Another short subsection title one level higher}

\end{document}


• Yes, hyperref hooks into \addcontentsline for making the bookmark entry, so other approaches would need to modify the whole structure. Jan 25, 2016 at 14:46