Displayed and PDF table of contents with different depths

hyperreftable of contents

I am writing a document with several sections and subsections, using the amsart template. I would like the following:

  • A short table of contents at the start of the document, which only includes the sections.
  • Bookmarks on the generated PDF which includes sections and subsections, as is typically done automatically via the hyperref package.

The command \setcounter{tocdepth}{1} modifies both, and there doesn't seem to be a easy way to set them separately. Using the shorttoc package I had a hack solution (involving generating a .toc file first), but it also replaced all of my headers to just display "Contents."

Below is a MWE with the above in mind. I've added a lot of sections and text to ensure the headers are correct (author on even pages, title on odd pages which is the default amsart style).

\documentclass[10pt,a4paper]{amsart}
\usepackage{lipsum}
\usepackage{hyperref}

\begin{document}

\title{Testing}
\author{Me}
\maketitle

\tableofcontents

\section{First section}
\lipsum[1]
\subsection{First subsection}
\lipsum[2-5]
\subsection{Second subsection}
\lipsum[6-9]
\section{Second subsection}
\lipsum[10]
\subsection{First subsection}
\lipsum[11-13]
\subsection{Second subsection}
\lipsum[14-16]

\end{document}

This generates the correct bookmarks/links in the generated PDF (using Zathura for instance), but I would only like it to display "First Section" and "Second Section" in the contents. Any help would be greatly appreciated.

Best Answer

You can set the bookmark depth independantly from tocdepth with the bookmarksdepth key:

\documentclass[10pt,a4paper]{amsart}
\usepackage{lipsum}
\usepackage{hyperref}
\hypersetup{bookmarksdepth=4}
\setcounter{tocdepth}{1}
\begin{document}

\title{Testing}
\author{Me}
\maketitle

\tableofcontents

\section{First section}
\lipsum[1]
\subsection{First subsection}
\lipsum[2-5]
\subsection{Second subsection}
\lipsum[6-9]
\section{Second subsection}
\lipsum[10]
\subsection{First subsection}
\lipsum[11-13]
\subsection{Second subsection}
\lipsum[14-16]

\end{document}

enter image description here

Related Question