[Tex/LaTex] How to cross-reference several objects simultaneously

compilingcross-referencingmacros

I want to define a macro for referencing equations in an article. I want the equation to be referenced as: " Eq. (3) "
So I defined a command "\eref{}" as:

\def\eref#1{Eq.~\ref{#1}}

But I also have instances where I want to refer to multiple equations like: "Eq. (3,4,5)" and when I try to use:

\eref{label1,label2,label3}

I simply find " Eq. ?? " in the pdf.

Can anyone kindly help me declare a macro which can take as input a list and simply call another function with that list (like how \ref{} command of latex does). I tried to replace "#1" in the definition by "##", it didn't work.

I wish to have similar macros for referring to Lemmas, Theorems, etc, which too have similar problems.

Best Answer

If you have three consecutive equations labeled, say, eq:1, eq:2, and eq:3 and need to cross-reference them jointly, you could do so with the help of the cleveref package and its \cref command:

\cref{eq:1,eq:2,eq:3}

cleveref is clever enough (pun intended) to sort and, if necessary, compress the numbers associated with the equations, generating the typeset output "eqs. (1) to (3)". If you don't want to see the word "equations" abbreviated to "eqs.", load the cleveref package with the noabbrev option.

The only real restriction if using the cleveref package is that you mustn't use a comma (,) as part of a label's name since -- as you can tell from the example above -- commas are used to separate labels from one another.

For much more on the topic of cross-referencing, including various aspects of the cleveref package, see the posting Cross-reference packages: which to use, which conflict? and the associated answers.

Related Question