2

How to properly reference equations in an IEEEeqnarray with the cleveref package?

Here is possible MWE:

\documentclass[a4paper,10pt,conference,twocolumn,twoside]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[cmex10]{amsmath}
\usepackage{mathtools}
\usepackage{cleveref}
\crefname{equation}{eq.}{eqs.}
\crefname{figure}{fig.}{figs.}

\begin{document}
While referencing is not working for \Cref{Eq:not_working}, it is for \Cref{Eq:working}
\begin{IEEEeqnarray}{rCl}
  a &=& b\nonumber\\
  c &=& d
\label{Eq:not_working}
\end{IEEEeqnarray}

\begin{subequations}
\begin{IEEEeqnarray}{rCl}
  a &=& b\\
  c &=& d
\end{IEEEeqnarray}
\label{Eq:working}
\end{subequations}
\end{document}
  • Simply put: IEEEtrantools.sty uses \stepcounter{equation} instead of \refstepcounter{equation}, so cleveref can't guess what counter is involved. – egreg Jun 17 '15 at 11:04
2

The IEEEtrantools.sty package uses \stepcounter{equation} and \stepcounter{IEEEsubequation} instead of \refstepcounter, so cleveref cannot guess what counter is involved.

Here's a patch that changes all \stepcounter commands to \refstepcounter. It has no influence on the macros of IEEEtrantools, because they set “manually” \@currentlabel.

\documentclass[a4paper,10pt,conference,twocolumn,twoside]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\@IEEEyesnumber}
  {\stepcounter}
  {\refstepcounter}
  {}{}
\patchcmd{\@@IEEEeqnarray}
  {\stepcounter}
  {\refstepcounter}
  {}{}
\patchcmd{\@@IEEEeqnarraycr}
  {\stepcounter{IEEEsubequation}}
  {\refstepcounter{IEEEsubequation}}
  {}{}
\patchcmd{\@@IEEEeqnarraycr}
  {\stepcounter{IEEEsubequation}}
  {\refstepcounter{IEEEsubequation}}
  {}{}
\patchcmd{\@@IEEEeqnarraycr}
  {\stepcounter{IEEEequation}}
  {\refstepcounter{IEEEequation}}
  {}{}
\patchcmd{\@@IEEEeqnarraycr}
  {\stepcounter{IEEEequation}}
  {\refstepcounter{IEEEequation}}
  {}{}
\makeatother

\usepackage{cleveref}
\crefname{equation}{eq.}{eqs.}
\crefname{figure}{fig.}{figs.}


\begin{document}

While referencing is not working for \Cref{Eq:not_working}, 
it is for \cref{Eq:working}
\begin{IEEEeqnarray}{rCl}
  a &=& b\nonumber\\
  c &=& d
\label{Eq:not_working}
\end{IEEEeqnarray}

\begin{subequations}
\begin{IEEEeqnarray}{rCl}
  a &=& b\\
  c &=& d
\end{IEEEeqnarray}
\label{Eq:working}
\end{subequations}

\end{document}

enter image description here

  • Great. Works perfectly! – s__C Jun 17 '15 at 11:20
  • Just out of curiosity: Do you have a hunch as to why the IEEEtran document class and the IEEEtrantools package would use \stepcounter and change \@currentlabel "by hand" rather than use the \refstepcounter machinery? – Mico Jun 17 '15 at 12:58
  • @Mico I believe just because it sets \@currentlabel globally rather than locally as the LaTeX kernel does. – egreg Jun 17 '15 at 13:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.