1

I have a book with a number of empty numbered chapter headings, and am using hyperref to generate bookmarks in my PDF index. I would like those bookmarks to include the word Chapter as well as the number. Consider this example:

\documentclass[a4paper, oneside, final, fontsize=12]{report}

\usepackage[bookmarks=true,colorlinks=true,linkcolor=black]{hyperref} % appearance of links

% toc and index formatting \usepackage{titletoc} \titlecontents{chapter}[0pt] {} {\chaptername\ \thecontentslabel\quad} % Numbered format {} % Numberless format {} \hypersetup{bookmarksnumbered}

\begin{document}

\vbox{\tableofcontents}

\chapter{}

\chapter{}

\end{document}

The PDF index I would like to generate would contain:

Chapter 1            2

Chapter 2            3

What the above code snippet produces is:

1                    2

2                    3

I am thinking of something like titletoc but really any solution would be great!

sfyn
  • 113
  • This may help you: http://tex.stackexchange.com/questions/33696/no-section-numbers-but-still-have-pdf-bookmarks-with-hyperref – Michael Palmer Nov 26 '16 at 19:01

1 Answers1

4

In order to sneak something before the chapter number, you can update how \Hy@writebookmark processes its second argument. The second argument is that part written to the ToC, which in the case of \chapter{} would be \numberline{<chapnum>} only:

enter image description here

\documentclass{report}

\usepackage[bookmarks=true]{hyperref}

\hypersetup{bookmarksnumbered}

\begin{document}

\tableofcontents

\makeatletter
\let\oldHy@writebookmark\Hy@writebookmark
\renewcommand{\Hy@writebookmark}[2]{%
  \oldHy@writebookmark{#1}{Chapter #2}%
}
\makeatother

\chapter{}

\chapter{}

\end{document}

Another method may be to distinguish between the fact that this change relates specifically to PDF settings. As such, we can change the chapter counter representation - given by \thechapter - to condition based on this via \texorpdfstring:

\renewcommand{\thechapter}{\texorpdfstring{}{Chapter }\arabic{chapter}}

The above should be placed in lieu of the \makeatletter...\makeatother construction above.

The above solution should also function under

\usepackage[numbered]{bookmark}
Werner
  • 603,163
  • @Werner Would this also generate the "Chapter " prefix in the Adobe Acrobat section-links sidebar? Is there also a way to add a period immediately after the number, before the chaptername is inserted? And, since I don't have a TOC, where in the document should this command-cluster be placed? Somewhere in the Memoir chapter style, perhaps? (I would also like to do this with Part numbers and names.) Or should I start a new question and link it to this one? – Stonefeather Grubbs Dec 03 '16 at 06:35
  • @StonefeatherGrubbs: You seem to request a number of things. Perhaps a follow-up question is better. Remember to provide the community with a minimal working example (MWE) so they can replicate the current behaviour, and be clear about the current and expected output. – Werner Dec 03 '16 at 06:43
  • @Warner Yes, the more I wrote, the more I was thinking that. However, I've just hit on another solution, which also fixes the problem of LaTeX formatting code inserting itself into the Acrobat titles: I will make separate titles for Acrobat, including "Part I," etc., with the hyperref macro \texorpdfstring. But thanks for the reply. – Stonefeather Grubbs Dec 03 '16 at 07:11
  • @StonefeatherGrubbs: Great! I added something to that effect in my answer. – Werner Dec 03 '16 at 07:24