# Why does hyperref bookmark work?

The \appendix command resets the section counter to zero:

*\documentclass{article}

*\show\appendix
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo))
> \appendix=\long macro:
->\par \setcounter {section}{0}\setcounter {subsection}{0}\gdef \thesection {\@
Alph \c@section }.


My understanding of \section is that it creates a bookmark based on the current counter number? In the following, I feel that I reproduce the critical parts of what \appendix does before declaring \section{six}, but it does not work.

\documentclass{article}
\usepackage[final]{hyperref}
\begin{document}
\tableofcontents
\newpage
\section{one}
\newpage
\section{two}
\newpage
\section{three}
\newpage
\appendix
\section{four}
\newpage
\section{five}
\setcounter{section}{0}
\setcounter{subsection}{0}
\section{six}
\end{document}


Instead, \section{six} has a bookmark which leads to \section{four}. The output of LaTeX understandably shows:

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


So I don't understand why this is happening. Does \appendix do more than what I think it is doing? The redefinition \thesection does not seem relevant here.

-

The hyperref package modifies \appendix, so that it does indeed more than just resetting the counters and changing \thesection.

\documentclass{article}
\usepackage{hyperref}
\show\appendix


yields

> \appendix=macro:
->\ltx@IfUndefined {chapter}{\gdef \theHsection {\Alph {section}}}{\gdef \theHc
hapter {\Alph {chapter}}}\xdef \Hy@chapapp {\Hy@appendixstring }\HyOrg@appendix


So it also sets \Hy@chapapp to the value of \Hy@appendixstring (which defaults to appendix). I suppose (but haven't checked) that the links hyperref creates are called \Hy@chapapp.\theH⟨current sectional unit⟩.

\HyOrg@appendix just contains the original definition of \appendix, which is also executed.

-