3

I'm designing a book with an elaborate ToC. I'd like to keep the ToC the way it is, but would like to make the bookmarks in the PDF a little less overwhelming, by grouping chapter together.

MWE:

\usepackage[utf8]{inputenc}
\usepackage[hidelinks, bookmarksopen=false]{hyperref}
\usepackage{bookmark}

\title{Question PDF bookmarks}
\author{Alex Dijk}
\date{April 2022}

\begin{document}

\chapter{1 jan}First January lecture
\chapter{2 jan}Another January lecture
\chapter{3 jan}Another January lecture
\chapter{4 jan}Another January lecture
\chapter{5 jan}Another January lecture
\chapter{6 jan}Another January lecture
\chapter{7 jan}Another January lecture
\chapter{8 jan}Another January lecture
\chapter{1 feb}First February lecture
\chapter{2 feb}Another February lecture
\chapter{3 feb}Another February lecture
\chapter{4 feb}Another February lecture
\chapter{5 feb}Another February lecture
\chapter{6 feb}Another February lecture
\chapter{7 feb}Another February lecture
\chapter{8 feb}Another February lecture

\end{document} 

So here, I would like to add bookmarks called 'January' and 'February' to the resulting PDF (but not to the ToC). These additional bookmarks then need to be unopened by default, under which all of the individual January and February chapters are ordered. How do I accomplish this?

1 Answer 1

6

With a current hyperref you can do this (inputenc is no longer needed in a current latex, utf8 is the default since a few years anyway):

\documentclass{book}
\usepackage[hidelinks, bookmarksopen=false]{hyperref}
\usepackage{bookmark}

\title{Question PDF bookmarks}
\author{Alex Dijk}
\date{April 2022}

\begin{document}

\bookmark[level=part,dest=\hyperget{anchor}{chap:jan}]{January}
\chapter{1 jan}\label{chap:jan}First January lecture
\chapter{2 jan}Another January lecture
\chapter{3 jan}Another January lecture
\chapter{4 jan}Another January lecture
\chapter{5 jan}Another January lecture
\chapter{6 jan}Another January lecture
\chapter{7 jan}Another January lecture
\chapter{8 jan}Another January lecture
\cleardoublepage
\bookmark[level=part,dest=\hyperget{anchor}{chap:feb}]{February}
\chapter{1 feb}\label{chap:feb}First February lecture
\chapter{2 feb}Another February lecture
\chapter{3 feb}Another February lecture
\chapter{4 feb}Another February lecture
\chapter{5 feb}Another February lecture
\chapter{6 feb}Another February lecture
\chapter{7 feb}Another February lecture
\chapter{8 feb}Another February lecture

\end{document} 

enter image description here

On older systems you must create targets manually:

\documentclass{book}
\usepackage[hidelinks, bookmarksopen=false]{hyperref}
\usepackage{bookmark}

\title{Question PDF bookmarks}
\author{Alex Dijk}
\date{April 2022}

\begin{document}

\hypertarget{jan}{}
\bookmark[level=part,dest=jan]{January}
\chapter{1 jan}First January lecture
\chapter{2 jan}Another January lecture
\chapter{3 jan}Another January lecture
\chapter{4 jan}Another January lecture
\chapter{5 jan}Another January lecture
\chapter{6 jan}Another January lecture
\chapter{7 jan}Another January lecture
\chapter{8 jan}Another January lecture
\cleardoublepage
\hypertarget{feb}{}
\bookmark[level=part,dest=feb]{February}
\chapter{1 feb}\label{chap:feb}First February lecture
\chapter{2 feb}Another February lecture
\chapter{3 feb}Another February lecture
\chapter{4 feb}Another February lecture
\chapter{5 feb}Another February lecture
\chapter{6 feb}Another February lecture
\chapter{7 feb}Another February lecture
\chapter{8 feb}Another February lecture

\end{document} 
7
  • Thanks, but I tried this in my scrbook environment, but now the compiling times out, which it didn't do before... I have many \addchap{} entries, instead of \chapter. Could that be the issue?
    – Parvana
    Commented Apr 14, 2022 at 10:31
  • @Parvana It should work in scrbook to. Ask a new question with a small, but complete example demonstrating the problem. Did you test my example? Does it work for you? Commented Apr 14, 2022 at 10:40
  • I'll do that. Yes, your answer did work, although I did get this 'Undefined control sequence'-error log: \BKM@dest ->\hyperget {anchor}{chap:jan} l.11 ...dest=\hyperget{anchor}{chap:jan}]{January} The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., '\hobx'), type 'I' and the correct spelling (e.g., 'I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.
    – Parvana
    Commented Apr 14, 2022 at 11:35
  • If you get an error then it didn't work. As I wrote this requires a current hyperref, yours is to old. Commented Apr 14, 2022 at 11:37
  • I'm not sure what it means that my hyperref is too old and how to resolve that as a user of Overleaf...
    – Parvana
    Commented Apr 14, 2022 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .