3

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}

\usepackage[plainpages=false,pdfpagelabels=true,pdfencoding=auto,hidelinks]{hyperref}

\begin{document}

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


\end{document}
2

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}{%
  \addcontentsline{toc}{#1}{%
    \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}
  \addcontentsline{toc}{#1}{%
    \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[plainpages=false,pdfpagelabels=true,pdfencoding=auto,hidelinks]{hyperref}
%\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}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.