Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

\documentclass[answers]{exam}

\addtolength{\textwidth}{1cm}
\addtolength{\hoffset}{-0.5cm}
\addtolength{\textheight}{1cm}
\addtolength{\voffset}{-0.5cm}

\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[pdfstartview=FitH,bookmarks=true]{hyperref} 
\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
\newcounter{exercise}
\titleformat{\exercise}{\normalfont\large\bfseries}{Exercise }{0em}{\theexercise}
\titlespacing*{\exercise}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\exerciseautorefname}{exercise}
\makeatletter
\providecommand*{\toclevel@exercise}{2} % Make sure exercises appear below sections in bookmarks
\makeatother

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

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

\begin{document}

\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
    \begin{solution}
        $\begin{aligned}
            \BODY
        \end{aligned}$
    \end{solution}
}

\include{Chapter1}

\end{document}

Code - Chapter1.tex

\section{Basic Algebra}

\exercise{}
Some text...
share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

Bookmark are numbered with option numbered of package bookmark:

\usepackage{bookmark}
\bookmarksetup{numbered}

Of without bookmark with hyperref only:

\hypersetup{bookmarksnumbered}

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

\renewcommand*{\thesection}{%
  \texorpdfstring{}{Chapter }%
  \arabic{section}%
  \texorpdfstring{}{:}%
}

\renewcommand*{\theexercise}{%
  \texorpdfstring{}{Exercise }%
  \arabic{section}%
  \Alph{exercise}%
}
share|improve this answer
    
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 '13 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 '13 at 23:36
1  
@JustinT The old \renewcommand{\theexercise} needs to be replaced by the new version. –  Heiko Oberdiek May 19 '13 at 5:04
    
D'oh! Thanks, couldn't see for looking! –  JustinT May 19 '13 at 16:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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