2

It is odd to see that \cref does not work when Eq. (2) is removed from its range. When I remove another equation, it just works perfectly. Reordering the equations labels does not seem to work.

Referring to all equations individually by using ,, among labels works. However, I want the text to be as compact as possible, so using ,, to separate labels and explicitly refer to each equation is not desired.

enter image description here

My source code:

\documentclass[11pt, a4paper]{IEEEtran}

\usepackage{amsmath}
\usepackage{amssymb, amsfonts}

\usepackage{cleveref}
\crefformat{equation}{Eq. (#1)}
\crefrangeformat{equation}{Eqs. (#1) to (#2)}
\crefmultiformat{equation}{Eqs. (#1)}{ and (#1)}{, (#1)}{ and (#1)}
\crefrangemultiformat{equation}{Eqs. (#1) to (#2)}{}{}{}


\begin{document}


\begin{align}
    y &= x_{1} + x_{2}
    \label{eq:1}
    \\
    y &= a \thinspace x + b
    \label{eq:2}
    \\
    e &= m \thinspace c^{2}
    \label{eq:3}
    \\
    y^{2} + x^{2} &= r^{2} 
    \label{eq:4}
    \\
    \int\limits_{0}^{\inf} e^{-x^{2}} &= \sqrt{\pi}
    \label{eq:5}
\end{align}


\rule{0pt}{1\normalbaselineskip}

Referring to the whole range of equation works

Some remarks on \cref{eq:1,eq:2,eq:3,eq:4,eq:5}

\rule{0pt}{1\normalbaselineskip}

Referring to all equations as a range except \cref{eq:2} does not work

Some remarks on \cref{eq:1,eq:3,eq:4,eq:5}

\rule{0pt}{1\normalbaselineskip}

Referring to all equations individually works 

Some remarks on \cref{eq:1,,eq:3,,eq:4,,eq:5}



\end{document}
  • Your syntax is wrong: you should have more arguments than those in your definitions. I don't see why that would have the effect shown, though. Does it work with a regular class? – cfr Jul 17 '18 at 1:00
  • Oh, you're just throwing the information away. Don't do that! :-) – cfr Jul 17 '18 at 1:17
2

Your definition just throws everything but a single reference or reference range away, so if there is a gap after the first reference, nothing else is typeset because that's what you've told cleveref to do in that case.

Your first three custom formats work OK, although they will fail if you use hyperref. However, the fourth, \crefrangemultiformat{}{}{}{}{} throws away not only the anchoring information for links, but all cross-reference information apart from the first.

Changing that definition to

\crefrangemultiformat{equation}{#3Eqs. ((#1))#4 to #5((#2))#6}{ and #3(#1)#4 to #5(#2)#6}{, #3(#1)#4 to #5(#2)#6}{ and #3(#1)#4 to #5(#2)#6}

produces what I assume is the expected result.

\documentclass[11pt, a4paper]{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{cleveref}
\crefformat{equation}{#2Eq. (#1)#3}
\crefrangeformat{equation}{#3Eqs. (#1)#4 to #5(#2)#6}
\crefmultiformat{equation}{#2Eqs. (#1)#3}{ and #2(#1)#3}{, #2(#1)#3}{ and #2(#1)#3}
\crefrangemultiformat{equation}{#3Eqs. ((#1))#4 to #5((#2))#6}{ and #3(#1)#4 to #5(#2)#6}{, #3(#1)#4 to #5(#2)#6}{ and #3(#1)#4 to #5(#2)#6}

\begin{document}


\begin{align}
    y &= x_{1} + x_{2}
    \label{eq:1}
    \\
    y &= a \thinspace x + b
    \label{eq:2}
    \\
    e &= m \thinspace c^{2}
    \label{eq:3}
    \\
    y^{2} + x^{2} &= r^{2} 
    \label{eq:4}
    \\
    \int\limits_{0}^{\inf} e^{-x^{2}} &= \sqrt{\pi}
    \label{eq:5}
\end{align}



Referring to the whole range of equation works.

Some remarks on \cref{eq:1,eq:2,eq:3,eq:4,eq:5}.
\bigskip

Referring to all equations as a range except \cref{eq:2} works fine when the definition doesn't throw the information away.

Some remarks on \cref{eq:1,eq:3,eq:4,eq:5}.

\bigskip

Referring to all equations individually works.

Some remarks on \cref{eq:1,,eq:3,,eq:4,,eq:5}.



\end{document}

all present and correct

  • Thanks for the answer, but what is the need for #3 to #6 entries? Also, why did you order them in this particular way? – Al-Motasem Aldaoudeyeh Jul 17 '18 at 2:28
  • @Al-MotasemAldaoudeyeh They are necessary in case you use hyperref. The ordering is just based on their meaning e.g. with one reference #2#1#3 gives the target, with more than one #1 and #2 are the references and the anchors are #3, #4, #5 and #6. See the manual for details. I just copied from my cleveref.cfg (which I wrote reading the manual). – cfr Jul 17 '18 at 2:40

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.