3

I am using the package utdiss2.sty in a paper. When I use the package like this example:

\documentclass[12pt]{book}
\usepackage{lipsum}
\usepackage{bookmark}
\usepackage{utdiss2}
\usepackage{hyperref}
%\usepackage{appendix}


\begin{document}
\chapter{Ch1}
\lipsum
\chapter{Ch2} 
\lipsum

%\bookmarksetupnext{level=part}
\begin{appendices}
\chapter{Hello}
\lipsum
\chapter{World}
\lipsum
\end{appendices}
\end{document}

Eveything's OK, but the PDF does not have a correct matching in bookmark. The first appendix matches to Chapter 1, not the first appendix.

enter image description here

I looked into the appendices environment in the utdiss2.sty package and commented out \setcounter{chapter}{0}.

\def\appendices{\clearpage
    \typeout{Appendices.}
    \short@page \setcounter{regular@short}{1}   % <- 9/13/96 (MAL)
        \markboth{}{}\pagestyle{myheadings} % <- The appendices must
        \thispagestyle{plain}           % <- be numbered.
    \vspace*{\fill}
    \centerline{\large\bf Appendices}
    \vspace*{\fill}

    \addcontentsline{toc}{chapter}{Appendices}  % <-

    \setcounter{chapter}{0} % <---
    \setcounter{section}{0} 
    \def\@chapapp{\appendixname}
    \chap@or@app=2
    \def\thechapter{\Alph{chapter}}}

Now, the bookmark works fine, but the numbering is wrong; Appendix C and D instead of Appendix A and B.

Without the utdiss2.sty package, there is no problem, so there is something changed in this package.

enter image description here

What might be wrong? What might be causing this kind of issue (wrong bookmark mapping) when redefining appendices or chapters?

Werner
  • 603,163
prosseek
  • 6,033
  • 1
    Try to load utdiss2 before hyperref (which should be loaded last anyway in 99.9% of all cases. –  Jun 27 '16 at 14:03
  • @Christian Hupfer: I tried but I have the same results. – prosseek Jun 27 '16 at 14:13
  • Actually, I don't see what the fix '%\setcounter{chapter}{0}does really solve in your bookmark issue? What is the issue? Do you want to have individual appendix chapters grouped belowAppendices`, i.e. indented in the bookmarks? Or is the hyperlink wrong? –  Jun 27 '16 at 16:12

1 Answers1

3

The issue is most likely the well-known problem:

\setcounter{chapter}{0} leads to wrong hyperref anchors, since counter values are used to build such anchors.

One solution is to provide another \theHchapter setup, say

\renewcommand{\theHchapter}{\appendixname.\thechapter}

This will write names like

   \@writefile{toc}{\contentsline {chapter}{Appendix A.\hspace  *{1em}Hello}{10}{chapter.Appendix.A}}

to the .aux file, given correct hyperlinks like chapter.Appendix.A and not chapter.1 again, which is there already for the real first chapter.

\documentclass[12pt]{book}
\usepackage{lipsum}

\usepackage{xpatch}
\usepackage{utdiss2}
\usepackage{hyperref}

\xapptocmd{\appendices}{%
  \renewcommand{\theHchapter}{\appendixname.\thechapter}
}{}{}

\usepackage{bookmark}



\begin{document}
\chapter{Ch1}
\lipsum
\chapter{Ch2} 
\lipsum

\bookmarksetupnext{level=part}


\begin{appendices}
\chapter{Hello}
\lipsum
\chapter{World}
\lipsum
\end{appendices}
\end{document}

enter image description here