I'm writing up solutions to some exercises, and having problems with the bookmarks produced in the resulting pdf file. In the document I'm using \section (slightly modified) and \exercise (based on \subsection) - I'd like these to appear in the bookmarks in exactly the same way they appear in the document, including the numbering. Without the numbering, \exercise appears as a blank bookmark...

I know I could use the optional parameter for the \section and \exercise commands to manually specify the text used in the bookmarks, but I'd like to avoid it!

Code - main file



\usepackage{xcolor} % Use colour!
\usepackage{titlesec} % Allow creation of new sectioning commands
\usepackage{amsmath} % Needed for splitting equations over multiple lines
\usepackage{ulem} % Underlining effects
\usepackage{environ} % Tinkering with environments
\usepackage{gensymb} % Degree symbol
\usepackage{bookmark} %PDF Bookmarks

\titleformat{\section}{\normalfont\large\bfseries}{Chapter }{0em}{\thesection: }

\titleclass{\exercise}{straight}[\section]  % Create new 'section' command for exercises - this replaces \subsection
\titleformat{\exercise}{\normalfont\large\bfseries}{Exercise }{0em}{\theexercise}
\titlespacing*{\exercise}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\providecommand*{\toclevel@exercise}{2} % Make sure exercises appear below sections in bookmarks

\pagestyle{headandfoot} % Let's have both
\header{\oddeven{Exercise \theexercise}{Chapter \thesection: \rightmark}}{Core 1}{\oddeven{Chapter \thesection: \rightmark}{Exercise \theexercise}}

\renewcommand\sectionmark[1]{\markright{#1}} % Set up \rightmark


\unframedsolutions % Print solutions as plain text
\SolutionEmphasis{\color{blue}} % Print solutions in blue
\renewcommand{\thepartno}{\roman{partno}} % Format part numbers as lower-case roman numerals
\renewcommand\theexercise{\thesection\Alph{exercise}} % Print exercise numbers as 1A, etc...
\renewcommand{\solutiontitle}{\noindent} % Format solution - just print solution as entered
\newcommand{\ans}[1]{\uuline{#1}} % Double underline final answer

\NewEnviron{sol}{ % Align solutions sensibly



Code - Chapter1.tex

\section{Basic Algebra}

Some text...

1 Answer 1


Bookmark are numbered with option numbered of package bookmark:


Of without bookmark with hyperref only:


Adding prefixes Chapter and Exercise can be done via a trick:

  \texorpdfstring{}{Chapter }%

  \texorpdfstring{}{Exercise }%
  • That adds the numbers (how did I miss that option!) - but it doesn't format them exactly the same way as they are in the document. \section needs to be like Chapter 1: Basic Algebra; \exercise needs to be like Exercise 1A.
    – JustinT
    May 18, 2013 at 22:25
  • That's an improvement - it gives me the correct bookmark for the \section headings. However, the \exercise headings show up as Chapter 1:A, Chapter 1:B, etc.
    – JustinT
    May 18, 2013 at 23:36
  • 1
    @JustinT The old \renewcommand{\theexercise} needs to be replaced by the new version. May 19, 2013 at 5:04
  • Nowadays also works with '\usepackage[bookmarksnumbered]{hyperref}'.
    – Keks Dose
    Sep 2, 2021 at 10:04

You must log in to answer this question.

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