[Tex/LaTex] How to cross-reference an inequality with \cref

cleverefcross-referencing

I have inequalities being cross-referenced by \cref as equations.

1-) How can I change that? (and still have inequalities with the same numbering as equations)

2-) How can I change that and have inequalities with their own numbering?

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage[letterpaper]{geometry}
\begin{document}

\begin{flalign}
&f(x) \geq g(x)& \label{i:positivity}
\end{flalign}

Admitting that \cref{i:positivity} has a solution, ...  

\end{document}

Best Answer

Assuming you want to use the same counter variable for both equation-like and inequality-like environments, you can proceed by informing cleveref (i) that certain environments are "special" (specifically, that they are inequalities) and (ii) what to do in terms of typesetting the cross-references to these "special" objects. The former can be achieved by providing an optional argument to the \label command. (cleveref cleverly redefines \label to make this possible.) The latter can be achieved by executing appropriate \crefname and \creflabelformat instructions.

enter image description here

\documentclass[12pt,letterpaper]{article}
\usepackage{amsmath,geometry}
\usepackage[colorlinks]{hyperref} %%  just for this example

\usepackage[nameinlink]{cleveref} 
\crefname{ineq}{inequality}{inequalities}
\creflabelformat{ineq}{#2{\upshape(#1)}#3} 
 %% \upshape ensures that the number and surrounding parens are typeset in upright mode

\setlength\parindent{0pt} %%  just for this example
\setlength\textwidth{4in} %%  just for this example

\begin{document}
\begin{flalign}
&f(x) \geq g(x)& \label[ineq]{i:positivity} %% note optional argument of \label
\end{flalign}
Admitting that \cref{i:positivity} has a solution, \dots 
\end{document}

Section 6 of the user guide of the cleveref package provides a fuller explanation of how this works. In that section, it's also explained how to automate this a bit if you have lots and lots of inequalities, in which case it might become tedious to have to remember to supply the option ineq to \label whenever the object is an inequality.

Related Question