# Strip section number from equation range reference

I am trying to adjust equation range numbering from (1.10)-(1.15) to (1.10-15).

By calling this in the preamble:

\crefrangelabelformat{equation}{(#3#1#4-#5#2#6)}

and then this in the document:

\Crefrange{eq:1-10}{eq:1-15}

I have gotten the range in side the same brackets, i.e. (1.10-1.15), but I am having trouble stripping the section number from the second label in the range. Is there some way to adjust the {eq:1-15} label prior to calling \Crefrange (i.e. changing 1.15 to 15), and then change it back after the call? I need to change it back as in other locations I reference 1.15 individually and so need to retain the section number. Alternately can I strip the section number from the formatted text (#2) passed to \crefrangelabelformat?

Any help appreciated.

• Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – karlkoeller Jul 31 '13 at 5:36
• Is there a chance you'll need to cross-reference a range of equations across sections, e.g., something such as (1.15-2.5)? – Mico Jul 31 '13 at 6:08

#1 and #2 of \crefrangelabelformat contains the formatted equation number. The following example expands them and stores them in \eq@ref@a and \eq@ref@b. Then both are analyzed, whether the equation numbers have a dot separator. If yes, then the first parts are compared and omitted in \eq@ref@b, if the first parts are equal.

\documentclass{report}
\usepackage{cleveref}

\makeatletter
\crefrangelabelformat{equation}{%
\protected@edef\eq@ref@a{#1}%
\protected@edef\eq@ref@b{#2}%
\expandafter\expandafter\expandafter
\eq@ref@check\expandafter\eq@ref@a\expandafter.\expandafter\@nil
\eq@ref@b.\@nil
(%
#3\eq@ref@a#4%
--%
#5\eq@ref@b#6%
)%
}
\def\eq@ref@check#1.#2\@nil#3.#4\@nil{%
\def\eq@tmp{#2}%
\ifx\eq@tmp\@empty
\else
\def\eq@tmp{#4}%
\ifx\eq@tmp\@empty
\else
\def\eq@tmp@a{#1}%
\def\eq@tmp@b{#3}%
\ifx\eq@tmp@a\eq@tmp@b
\expandafter\def\expandafter\eq@ref@b\expandafter{%
\eq@strip@dot#4\@nil
}%
\fi
\fi
\fi
}
\def\eq@strip@dot#1.\@nil{#1}
\makeatother

\begin{document}
\crefrange{eq:first}{eq:second} and \crefrange{eq:second}{eq:third}
\chapter{First chapter}
$$\label{eq:first} 1=1$$
$$\label{eq:second} 2=2$$
$$\label{eq:third} 3=3$$