[Tex/LaTex] Multiple subequation labels in one \ref

cross-referencingequationsnumbering

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.

Best Answer

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

enter image description here

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}
\usepackage{cleveref}% load last


\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}
Related Question