[Tex/LaTex] 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

\usepackage{cleveref} %for cref
\usepackage{amsmath} %for sub equation numbers and words within equations (\text)



    x^2 - 5 x + 6 = 0 

    Ref: \ref{eq:solve}

    CRef: \cref{eq:solve}


I get the output:

enter image description here

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

enter image description here

Is it possible to use both together successfully?

Best Answer

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


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.

Related Question