I was wondering if there is some LaTeX macro/command (I don't know the exact term) that, given a list of labels, gives the lowest/largest label value and has the same behaviour as \ref{}
(i.e., inserting a hyperlink to the referenced object in the pdf).
Consider the following simple example, in which are defined 4 different equations.
\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}
\begin{equation}
\label{eq:energy_mass_lightspeed}
E = mc^2
\end{equation}
\begin{equation}
\label{eq:basic_arithmetics}
2 + 2 = 4
\end{equation}
\begin{equation}
\label{eq:pythagorean_theorem}
a^2 + b^2 = c^2
\end{equation}
\begin{equation}
\label{eq:handshaking_lemma}
\sum_{v\in V(G)} d_G(u) = 2|E(G)|
\end{equation}
In the following sections we use Equations from
\firstlabel{eq:energy_mass_lightspeed,eq:basic_arithmetics,eq:pythagorean_theorem,eq:handshaking_lemma}
to
\lastlabel{eq:energy_mass_lightspeed,eq:basic_arithmetics,eq:pythagorean_theorem,eq:handshaking_lemma}.
\end{document}
In the last four lines of the example the hypothetical macros \firstlabel
and \lastlabel
have as parameter a list of labels (the labels of the four equations). The first, \minimumlabel{..}
, should have the same behaviour (in this case) as \ref{eq:energy_mass_lightspeed}
since eq:energy_mass_lightspeed
is the label that is defined first. The second, \lastlabel{..}
, should have the same behaviour as \ref{eq:handshaking_lemma}
since eq:handshaking_lemma
is the label that is defined last.
Question Can this be done? If so, does there exist something like this?
The motivation is that sometimes the equations can be rearranged in a document in order to enhance readability, or even to be able to streamline explanations. If, then, the writer wants to refer to an equation range, they could use the first and last labels at the moment of referring to the range, but that can change in a future modification of the document. Writing the numbers of the equations is not an option since the authors may decide to add more equations before the first, thus changing the number of the equations. Command \vrefrange
helps a bit but it needs the parameters to always be the first and the last (notice that equations may be reordered at some point).
Best Answer
As mentioned in a comment, a solution is to use the package
cleveref
. In order to do what I asked in the post, first include the packageand use the appropriate command in the last sentence of the document
Notice that the labels are not given to
\cref
in the order they were defined. The command above producesTwo interesting options are
capitalize
andnoabbrev
which, when passed to the packagethe command above will produce
(Notice that it went from
eqs.
toEquations
).