# Wrong links for subsections in appendix

I noticed a subtle problem while writing an appendix. Here is my code:

\documentclass[12pt]{article}
\usepackage{hyperref}
\let\chapter\section
\begin{document}
\section{One}
ASD
\subsection{One.one}
qwe
\subsubsection{One.one.one}
asda123
\subsection{One.two}
zxc
\newpage
\appendix
\section{A}
\subsection{A.one}
\subsection{A.two}
\subsection{A.three}
\end{document}


The problem happens with the links of the subsection and subsubsection of the appendix, when there is an equivalent chapter in the main matter. In the example, the error happens with subsections A.1 and A.2, which lead to subsections 1.1 and 1.2. The link to subsection A.3, however, works correctly.

Why does it happen? Is there a quick fix for this error? (I wouldn't want to add a new package or change my whole document just to fix this problem).

• Why do you \let\chapter\section? I strongly believe this is causing your troubles. – sheß May 13 '16 at 11:48
• Thank you. That was causing the problem. The template I was given says that it can produce some issues with the package algorithm2e, but so far it seems to work. – Sergio Andrés Figueroa Santos May 13 '16 at 11:53
• Note that hyperref behaves differently if \chapter is defined or not, particularly when appendices are involved. – egreg May 13 '16 at 12:45

\let\chapter\section is no good idea here -- do not use such setups.

hyperref generates wrong anchors from this then.

If it is really needed, defining the relevant chapter counter cures the problem. But again: Don't use this!

\documentclass[12pt]{article}

\newcounter{chapter}
\let\chapter\section
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section{One}
ASD
\subsection{One.one}
qwe
\subsubsection{One.one.one}
asda123
\subsection{One.two}
zxc
\newpage
\appendix
\section{A}
\subsection{A.one}
\subsection{A.two}
\subsection{A.three}
\end{document}