# The Goal

To have a memoir document with several chapters with the running story, a set of appendices called Appendices, with additional data in the main document, and a second set of appendices called Attachments, with additional maps etc that are provided separately, with only a small description of the attachment in the main document. Preferably the Appendices are numbered with \Alph (by default), and the Attachments numbered with \Roman.

# The Problem

Redefining the \appendix[|toc|page]name commands is no problem, and either a second \appendix or a \setcounter{chapter}{0} restarts numbering, and \renewcommand{\thechapter}{\Roman{chapter}} works fine to update the titles. However, bookmarks adds the page anchors as Appendix.[A|B|C|...], for both the Appendices and Attachments, and thus complains

destination with the same identifier (name{appendix.A}) has been already used, duplicate ignored

# The Question

How can I either rename the identifier prefix to attachment, or the change identifier numbering to Roman numerals such that the bookmarks in the TOC are correct?

The Code

\documentclass{memoir}

\usepackage{bookmark}

\begin{document}
\tableofcontents
\chapter{Foo}

\appendix
\appendixpage
\chapter{First appendix}

%\backmatter % Really only a temporary workaround, no real solution
\renewcommand{\appendixname}{Attachment}
\renewcommand{\appendixpagename}{Attachments}
\renewcommand{\appendixtocname}{Attachments}
% Either of the following two lines resets the chapter numbers, neither fixes the problem
%\appendix
\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Roman{chapter}}
\appendixpage
\chapter{A Separate File}

\end{document}


## A Workaround

A workaround to get correct bookmarks in the TOC is to move the \backmatter command before the Attachments. However, this disables numbering altogether, and I do need them. Also this only works if there are two sets of appendices, but perhaps someone else might need three or four sets of appendices, and then this does not work anymore.

-

The workaround is to add the line

\renewcommand{\theHchapter}{\Roman{chapter}}


just after

\setcounter{chapter}{0}


Hchapter is the counter used internally by hyperref (loaded by bookmark) corresponding to chapter.

MWE

\documentclass{memoir}

\usepackage{bookmark}

\begin{document}
\tableofcontents
\chapter{Foo}

\appendix
\appendixpage
\chapter{First appendix}

%\backmatter % Really only a temporary workaround, no real solution
\renewcommand{\appendixname}{Attachment}
\renewcommand{\appendixpagename}{Attachments}
\renewcommand{\appendixtocname}{Attachments}
% Either of the following two lines resets the chapter numbers, neither fixes the problem
%\appendix
\setcounter{chapter}{0}
\renewcommand{\theHchapter}{\Roman{chapter}}
\renewcommand{\thechapter}{\Roman{chapter}}
\appendixpage
\chapter{A Separate File}

\end{document}


Output:

If you now click on " I A Separate File" you will get to the right chapter.

Otherwise this can be solved loading hyperref with the option hypertexnames=false instead of loading bookmark:

\usepackage[hypertexnames=false]{hyperref}


or loading bookmark and passing that option to hyperref:

\PassOptionsToPackage{hypertexnames=false}{hyperref}
\usepackage{bookmark}

-
I think I could go with the hypertexnames=false option, but to me that feels a bit too much like treating a symptom instead of solving the problem. I did try something like renewing \theHchapter but for some reason that failed back then, I'm glad it works. However, as I explain in my own answer this isn't entirely foolproof either and I was really hoping to provide a more general and flexible solution. –  hugovdberg Mar 28 '14 at 13:51

This answer is heavily inspired by karlkoeller's answer, but takes a more flexible and robust approach, IMHO.

His proposed solution:

\renewcommand{\theHchapter}{\Roman{chapter}}


works most of the time, but is not entirely foolproof either. Suppose I have a large document with nine or more Appendices, then the first Attachment will clash with Appendix 9 because both have number I.

To fix this we can prepend \theHchapter with a unique string such that all sets of appendices are numbered independently. Since I didn't like the big bunch of \renewcommands at the start of a new set I decided to wrap it all up in a single macro. This can probably be optimized even further, see below for a small list.

The advantage is that you could also group your appendices with the same numbering within each group (such as A1, A2, A3, B1, B2. B3, or AA, AB, AC), without worrying about clashing appendixnumbers.

\documentclass{memoir}

\usepackage{bookmark}

% Usage: \newappendixset[<number_prefix>]{<appendixname>}{<pagename>}{<tocname>}{<numbering>}
\newcommand{\newappendixset}[5][]{
\renewcommand{\appendixname}{#2}
\renewcommand{\appendixpagename}{#3}
\renewcommand{\appendixtocname}{#4}
\setcounter{chapter}{0}
\ifx&#1&% Only add the prefix if it isn't empty
\renewcommand{\theHchapter}{#5}
\else
\renewcommand{\theHchapter}{#1.#5}
\fi
\renewcommand{\thechapter}{#5}
}

\begin{document}
\tableofcontents
\chapter{Foo}

\appendix
\appendixpage
\chapter{First appendix}
\chapter{Second appendix}
\chapter{Third appendix}
\chapter{Fourth appendix}
\chapter{Fifth appendix}
\chapter{Sixth appendix}
\chapter{Seventh appendix}
\chapter{Eighth appendix}
\chapter{Ninth appendix}

\newappendixset[att]{Attachment}{Attachments}{Attachments}{\Roman{chapter}}
\appendixpage
\chapter{Separate File}

\end{document}


Possible improvements

• Use pgfkeys to automatically add the current set to the TOC, insert an \appendixpage etc.
• Not entirely sure about the robustness of passing the numbering style this way.
• Maybe insert a simple counter as the prefix, instead of the optional argument, that's increased at every call to \newappendixset.
-