1

in the ME given below, the bookmarks do not point to the correct Appendix chapters:

\documentclass[11pt,fleqn]{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}

\usepackage{lipsum, fancyhdr}

\usepackage[svgnames]{xcolor}
\definecolor{ocre}{RGB}{243,102,25} 
\definecolor{mygray}{RGB}{243,243,244}

\usepackage{avant} 
\usepackage{mathptmx} 
\usepackage{microtype} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 

\usepackage{calc}

\usepackage{textcomp}

\usepackage[refsection=chapter,defernumbers=true,sorting=none,sortcites=true,autopunct=true,babel=hyphen,abbreviate=false,backref=true,backend=biber]{biblatex}

 \defbibheading{bibempty}{}

\usepackage{empheq}
\usepackage[font={color=ocre,bf},figurename=Fig.,labelfont={it}]{caption}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  %colback=ocre!10,
  colback=mygray,
  colframe=ocre,
  boxrule=0.8pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=mygray,
    colframe=red.
    }
  }
}

\newenvironment{spread}[1]{%
  \advance\jot#1% indeed
  }{%
\ignorespacesafterend
}

%===================================================
% Matlab code

\usepackage{inconsolata}

%\usepackage{fontspec}
\usepackage[numbered,framed]{matlab-prettifier}
\newcommand\ph\mlplaceholder
\makeatletter
\renewcommand\phOpDelim@mlpr{$\langle$}
\renewcommand\phClDelim@mlpr{$\rangle$}
\makeatother

%\newfontfamily{\lstconsolas}{Consolas}

%===================================================

\usepackage{caption}
\usepackage[font={color=ocre,bf,it},figurename=Fig.,labelfont={it}]{caption}
\newcommand{\figref}[2][]{% \figref[<sub-figref>]{<figref>}
  \textcolor{ocre}{\bfseries\emph{\figurename\,\ref{#2}#1}}}

\usepackage{calc} 
\usepackage{makeidx} 
\makeindex 

\input{structure}

\newcommand*{\refname}{Bibliography}

\begin{document}
\setcounter{secnumdepth}{3}

\frontmatter

\begingroup
\thispagestyle{empty}
\centering
\vspace*{9cm}
\par\normalfont\fontsize{35}{35}\sffamily\selectfont
Test Book\par
\vspace*{1cm}
{\Huge Author}\par 
\endgroup

\chapterimage{chapter_head_1}

\pagestyle{empty} 

\tableofcontents 

\mainmatter
\chapter{One}
\begin{lstlisting}[
  style=Matlab-editor,
  basicstyle=\mlttfamily\small,
  escapechar=`,
  caption={For educational purposes},
]
% example of while loop using placeholders
while `\ph{condition}`
  if `\ph{something-bad-happens}`
    break
  else
    x = 2015 + 10098 % do something useful
  end
  % do more things
end
\end{lstlisting}

\begin{lstlisting}[
  style=Matlab-editor,
  basicstyle=\mlttfamily\small,
  escapechar=`,
  caption={For educational purposes},
]
% example of while loop using placeholders
while `\ph{condition}`
  if `\ph{something-bad-happens}`
    break
  else
    x = 2015 + 10098 % do something useful
  end
  % do more things
end
\end{lstlisting}

\chapter{Two}
\section{One}
\lipsum

\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}
\chapter{Appendix A}
\section{One}
\lipsum

\chapter{Appendix B}
\section{One}
\lipsum

\cleardoublepage
\setlength{\columnsep}{0.75cm}
\addcontentsline{toc}{chapter}{\textcolor{ocre}{Index}}
\printindex

\end{document} 

I think that the problem occurs when I reset the chapter number to zero by the command \setcounter{chapter}{0} to begin the new numbering for the Appendix. Can you tell me how I can fix this issue so that the bookmarks can point to the correct chapters whilst the Appendix starts from letter A?

5
  • 2
    Have you seen my update and improvements on your other question? The \backmatter is not needed, just use \appendix and \usepackage[hypertexnames=false]{hyperref} ... And sorry, I have to say it again: Your MWE is definitely not minimal -- there is a lot of unneeded stuff in it. If I would be malicious, I would say the document is a mess :-(
    – user31729
    Jun 18, 2015 at 20:47
  • 3
    you shouldn't have to reset the counter for the appendix, simply adding \appendix before the first one should do the trick. It will also change the numbering to \Alph
    – ArTourter
    Jun 18, 2015 at 20:48
  • I am referring to this question: tex.stackexchange.com/questions/251011/…
    – user31729
    Jun 18, 2015 at 20:53
  • @ChristianHupfer. I have been appending changes as I went along to get the code to work hence the "Extented" WE. Can you help me get rid of the uneeded stuff then? I will sincerely appreciate your time and help with this!
    – Joe
    Jun 18, 2015 at 20:57
  • @Joe: I referred to 'unneeded' for the special problem here concerning the bookmarks. I will merge my answer from the code there and your document, trying to get what you want
    – user31729
    Jun 18, 2015 at 21:03

1 Answer 1

6

Package hyperref needs unique counter values for the destination names. After resetting the chapter counter (\setcounter{chapter}{0}), the macro \thechapter is redefined, but not \theHchapter, which hyperref uses.

\usepackage{hyperref}
\usepackage{bookmark}% faster updated bookmarks
...
\setcounter{chapter}{0}
\renewcommand*{\thechapter}{\Alph{chapter}}
\renewcommand*{\theHchapter}{\Alph{chapter}}

For correct links to the index, \phantomsection is needed, e.g.:

\cleardoublepage
\phantomsection % sets anchor for `\addcontentsline`
\addcontentsline{toc}{chapter}{\indexname}

You must log in to answer this question.

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