1

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:

reference to the section

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:

all equations are numbered although only eq (1) is referenced

2
  • An excerpt from this answer: "The [cleveref] package is seriously incompatible with the showonlyrefs option of the mathtools package. By "seriously incompatible" I mean that if cleveref is loaded together with \usepackage[showonlyrefs]{mathtools}, not only will the \cref commands 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:39
  • 1
    AFAICT, you have two choices: (a) don't load the cleveref package, or (b) don't employ the option showonlyrefs=true of the mathtools package. As an alternative to showonlyrefs=true, do consider loading and using the autonum package, That package offers features similar to those of showonlyrefs, but it does so in a cleveref-compatible way. – Mico Jun 30 '20 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.