# Equation reference undefined when using \cref and package{amsmath}

When I attempt to reference an equation using \cref{..} while also using the package amsmath the references appear as ?? in the outputted pdf. For example

\documentclass[]{article}
\usepackage{graphicx}
\usepackage{cleveref} %for cref
\usepackage{amsmath} %for sub equation numbers and words within equations (\text)

\begin{document}

\section{Introduction}

$$\label{eq:solve} x^2 - 5 x + 6 = 0$$

Ref: \ref{eq:solve}

CRef: \cref{eq:solve}

\end{document}


I get the output:

However if the \usepackage{amsmath} is commented out the \cref works correctly.

Is it possible to use both together successfully?

• You have to load cleveref last, even after hyperref. Dec 6 '13 at 15:10
• @egreg Thank you! That solved the problem. If you post that as an answer I will accept it Dec 6 '13 at 15:11
• you might want to consider using amsmath's \eqref instead of just \ref. \eqref adds parentheses around the reference, and ensures that they (and the reference itself) are always upright. Dec 6 '13 at 17:17
• @barbarabeeton Are you refering to my line Ref: \ref{eq:solve}, if so thats just in there to prove that normal references are still working; that only cref that was troublesome Dec 6 '13 at 17:18
• @RichardTingle -- yes, that's what i was referring to, and i understand that it was only for illustration. but some authors find the parenthesized cross reference preferable to the "eq." representation. (it can probably be changed, but not everyone knows about that.) Dec 6 '13 at 17:58

I tried to look for other questions with the same problem and found none. So here's an answer: load cleveref last.

From the documentation:

The cleveref package is loaded in the usual way, by putting the line

\usepackage{cleveref}


in your document’s preamble. However, care must be taken when using cleveref in conjunction with other packages that modify LaTeX’s referencing system (see Section 11). Basically, cleveref must be loaded last.

The problem is that amsmath modifies the referencing system, in order to cope with \tag, for instance. So cleveref has to hook into the redefined macros, rather than the original ones. By loading amsmath after cleveref you don't give the package the chance to know amsmath is also requested.

• In my case it was below amsmath, but above mathtools and a couple of \newtheorem definitions. Frustrating to have the order matter like that. Mar 13 '19 at 21:03
• @ThomasAhle As a general rule, I recommend to first load all packages (cleveref last, of course) and then do settings. Mar 13 '19 at 21:12
• Makes sense, but then there are other packages, like autonum that also want to be loaded last :( Mar 13 '19 at 22:23