# Multiple subequation labels in one \ref

I'm trying to write a macro that puts subequations' labels in parentheses in a compact form. For example, if I have

\begin{subequations}
\begin{align}
y - ax &= b \label{subeq1}\\
x^2 + y^2 &= r^2 \label{subeq2}
\end{align}
\end{subequations}


with the two equations being tagged as (1a) and (1b), then I want to be able to type \ref{subeq1,subeq2} and get (1a,b). Similarly, if I have three subequations, say (2a), (2b) and (2c) with labels subeq3, subeq4 and subeq5 respectively, then I want to be able to type \ref{subeq3,subeq4,subeq5} and get (2a--c). I would like this to work for any number of subequations.

-
Have a look at the cleveref package –  cmhughes Nov 23 '11 at 16:56
I did look at the cleveref package, but I don't think it can do what I'm asking. –  AndyS Nov 23 '11 at 17:10
@AndyS: Do you want to use hyperref? –  Marco Daniel Nov 27 '11 at 19:03
@Marco: Yes, I would like to use hyperref. –  AndyS Nov 27 '11 at 19:16

This isn't exactly what you wanted but is close.

## Note:

• The latest version (V0.18) is not yet on CTAN, but can be obtained from Toby Cubitt's site. Though it does no appear to make a difference in this particular example.

## Code:

\documentclass{article}
\usepackage{amsmath}

\crefname{equation}{equation}{equations}
\Crefname{equation}{Equation}{Equations}% For beginning \Cref
\crefrangelabelformat{equation}{(#3#1#4--#5#2#6)}

\crefmultiformat{equation}{equations (#2#1#3}{, #2#1#3)}{#2#1#3}{#2#1#3}
\Crefmultiformat{equation}{Equations (#2#1#3}{, #2#1#3)}{#2#1#3}{#2#1#3}

\begin{document}

\begin{subequations}
\begin{align}
y - ax &= b \label{eq:subeq1}\\
x^2 + y^2 &= r^2 \label{eq:subeq2}\\
x^2 + y^2 &= r^2 \label{eq:subeq3}\\
x^2 + y^2 &= r^2 \label{eq:subeq5}
\end{align}
\end{subequations}

\noindent
For the case where the label is part of a sentence:\par
Once referenced: \cref{eq:subeq1}\par
Two referenced: \cref{eq:subeq1,eq:subeq2}\par
Three referenced: \cref{eq:subeq1,eq:subeq2,eq:subeq3}\par

\bigskip
\noindent
For the case where the labels beign a sentence:\par
\Cref{eq:subeq1} is one equations.\par
\Cref{eq:subeq1,eq:subeq2} are two equations.\par
\Cref{eq:subeq1,eq:subeq2,eq:subeq3} are three equations.
\end{document}

-
Thanks Peter, I did look into cleveref, but I wasn't able to modify its behavior to fit my needs. Any other ideas? –  AndyS Nov 24 '11 at 17:10
I'd wait to see if someone else comes up with a better solution. Otherwise, it should be possible to post process the output of the above cref to remove duplicated numbers to get exactly what you want, but I think that should be a separate question as I am not able to figure out how to exactly do that. –  Peter Grill Nov 24 '11 at 17:29

I have a solution that isn't quite what you wanted, but it gives more compact label. The code I would use is:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{subequations}\label{eq:subeqns}
\begin{align}
y - ax &= b \label{eq:subeq1}\\
x^2 + y^2 &= r^2 \label{eq:subeq2}
\end{align}
\end{subequations}
\end{document}


I reference the entire set as \eqref{eq:subeqns} to get (1), and individuals as \eqref{eq:subeq1} or \eqref{eq:subeq2} to get (1a) or (1b).

-
Welcome to TeX.SX. You can use backticks (`) to highlight inline code. –  Torbjørn T. May 9 '13 at 18:47