I have equations and I want to reference some of them. Also, I would like to number only the equations that I reference. For some reason when I use \mathtoolsset{showonlyrefs=true} - nothing works and when I use \eqref it just references the section and not the equation. If I delete \mathtoolsset{showonlyrefs=true}, then all equations are being numbered no matter if I reference them or not.
For example, with the line \mathtoolsset{showonlyrefs=true}:
\documentclass[peerreview]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{url}
\usepackage{ifthen}
\usepackage{cite}
\usepackage[cmex10]{amsmath} % Use the [cmex10] option to ensure complicance
% with IEEE Xplore (see bare_conf.tex)
\usepackage{subcaption}
%% Please note that the amsthm package must not be loaded with
%% IEEEtran.cls because IEEEtran provides its own versions of
%% theorems. Also note that IEEEXplore does not accepts submissions
%% with hyperlinks, i.e., hyperref cannot be used.
\usepackage{cleveref}
\usepackage{graphicx}
\usepackage{amsmath }
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{dsfont}
\mathtoolsset{showonlyrefs=true}
\interdisplaylinepenalty=2500 % As explained in bare_conf.tex
%%%%%%
% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\renewcommand{\baselinestretch}{1.48} % use only for one column version
% ------------------------------------------------------------
\begin{document}
\title{test}
\author{%
\IEEEauthorblockN{test}\
\IEEEauthorblockA{test}
}
\maketitle
\begin{abstract}
pass
\end{abstract}
\section{Introduction} \label{sec:intro}
test equation,
\begin{equation} \label{eq:eq1}
2 = 1 + 1
\end{equation}
\begin{equation} \label{eq:eq2}
3 = 1 + 2
\end{equation}
equation num \eqref{eq:eq1}
\end{document}
result:
without:
\documentclass[peerreview]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{url}
\usepackage{ifthen}
\usepackage{cite}
\usepackage[cmex10]{amsmath} % Use the [cmex10] option to ensure complicance
% with IEEE Xplore (see bare_conf.tex)
\usepackage{subcaption}
%% Please note that the amsthm package must not be loaded with
%% IEEEtran.cls because IEEEtran provides its own versions of
%% theorems. Also note that IEEEXplore does not accepts submissions
%% with hyperlinks, i.e., hyperref cannot be used.
\usepackage{cleveref}
\usepackage{graphicx}
\usepackage{amsmath }
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{dsfont}
\interdisplaylinepenalty=2500 % As explained in bare_conf.tex
%%%%%%
% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\renewcommand{\baselinestretch}{1.48} % use only for one column version
% ------------------------------------------------------------
\begin{document}
\title{test}
\author{%
\IEEEauthorblockN{test}\
\IEEEauthorblockA{test}
}
\maketitle
\begin{abstract}
pass
\end{abstract}
\section{Introduction} \label{sec:intro}
test equation,
\begin{equation} \label{eq:eq1}
2 = 1 + 1
\end{equation}
\begin{equation} \label{eq:eq2}
3 = 1 + 2
\end{equation}
equation num \eqref{eq:eq1}
\end{document}
result:


cleveref] package is seriously incompatible with theshowonlyrefsoption of themathtoolspackage. By "seriously incompatible" I mean that ifcleverefis loaded together with\usepackage[showonlyrefs]{mathtools}, not only will the\crefcommands containing labels of equation objects be messed up, but many other cross-referencing packages will also experience major problems" [emphasis added]. – Mico Jun 30 '20 at 15:39cleverefpackage, or (b) don't employ the optionshowonlyrefs=trueof themathtoolspackage. As an alternative toshowonlyrefs=true, do consider loading and using the autonum package, That package offers features similar to those ofshowonlyrefs, but it does so in acleveref-compatible way. – Mico Jun 30 '20 at 16:08