# Strange side effect between amsmath, hyperref and cleveref

This issue seems rather exotic, but I encountered it in a medium-sized document, and it took me a while to indentify which particular combination of packages was responsible.

When I load amsmath, cleveref and hyperref (implicitly via pdfcomment), ref/autoref to an equation no longer work, i.e., LaTeX throws an Reference ... on page 1 undefined error. See the following MWE:

\documentclass[12pt]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{amsmath}

\usepackage{cleveref}
%% implicitly loads hyperref
\usepackage{pdfcomment}

\begin{document}

\section{Test}
Etwas Fülltext, bevor die Gleichung kommt:
$$E_\mathrm{kin} = \frac{m}{2} v^2 \label{eq:kinErg}$$
Jemand fand heraus, dass \autoref{eq:kinErg} gilt.

\end{document}


If I include hyperref explicitly, then everything works except I get this warning. Not a deal breaker, but I'd prefer to avoid it and just use hypersetup for the additional options for hyperref.

Also, if I omit amsmath, everything works, too. I suppose that each package partially overwrites each other's settings...

If this is a bug, then where should I report it?

• You're loading packages in the wrong order. Each package manipulates at least one aspect of the \label-\ref system, so the correct order of loading is crucial here: amsmathhyperrefcleveref – user31729 Apr 26 '17 at 10:29

Load cleveref always after hyperref as one of the few exception where packages should be loaded after hyperref!

Doing it in the wrong order, the counter information is overwritten and \autoref can't get grip of the counter i.e. the label is 'undefined', leading to wrong references or ?? as output.

\documentclass[12pt]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{amsmath}

%% implicitly loads hyperref
\usepackage{pdfcomment}

\usepackage{cleveref}

\begin{document}

\section{Test}
Etwas Fülltext, bevor die Gleichung kommt:
$$E_\mathrm{kin} = \frac{m}{2} v^2 \label{eq:kinErg}$$
Jemand fand heraus, dass \autoref{eq:kinErg} gilt.

\end{document}

• I see no advantage of \autoref here – user31729 Apr 26 '17 at 10:44