3

The cleveref package sorts and compresses cross-references. It also automatically determines the format of references, so that you don't have to type "equation" in the source. However the standard output is space wasting. In the example is references equations like eqs. (1), (2) and (4) to (6), however I want the shorter expression eqs. (1,2,4-6). I am not forced to use the package cleveref but I am not aware of an alternative.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{cleveref}
\begin{document}
\begin{align}
equation 1\label{eq1}\\
equation 2\label{eq2}\\
equation 3\label{eq3}\\
equation 4\label{eq4}\\
equation 5\label{eq5}\\
equation 6\label{eq6}
\end{align}
\\
output of cleveref is \cref{eq2,eq4,eq1,eq5,eq6}\\
I want: eqs.\~(1,2,4-6)
\end{document}
1
  • 1
    You should look at sections 8.2.2 and 8.2.3 of the cleveref manual. The examples given are in terms of equation numbers, so should be fairly simple to modify. Sep 17, 2022 at 14:28

2 Answers 2

3

Adaptations

  • added the commands \crefmultiformat, \crefrangemultiformat and \crefrangeformat (see cleverref manual 8.2.2 "Reference Ranges" and 8.2.3 "Multiple Cross-References")
  • added some test cases
  • (I would recommend using a space after the comma)

Result

enter image description here

Code

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{cleveref}

\crefmultiformat{equation}{eqs.~(#2#1#3}%
{,#2#1#3)}{,#2#1#3}{,#2#1#3)}
\crefrangemultiformat{equation}{eqs.~(#3#1#4--#5#2#6}%
{,#3#1#4--#5#2#6)}{,#3#1#4--#5#2#6}{,#3#1#4--#5#2#6)}
\crefrangeformat{equation}{eqs.~(#3#1#4--#5#2#6)}

\begin{document}
\begin{align}
equation 1\label{eq1}\\
equation 2\label{eq2}\\
equation 3\label{eq3}\\
equation 4\label{eq4}\\
equation 5\label{eq5}\\
equation 6\label{eq6}
\end{align}
\\
output of cleveref is \cref{eq2,eq4,eq1,eq5,eq6}\\
I want: eqs.~(1,2,4-6)\\
Some tests:\\
\cref{eq4,eq5,eq6}\\
\cref{eq1,eq2,eq3,eq6}\\
\cref{eq1,eq3}\\
\cref{eq1,eq3,eq4}\\
\end{document}
3

Something like this? Note that LuaLaTeX is used solely to speed up the process of creating six equation-related \label instructions.

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}

\usepackage{cleveref}
\newcommand{\creflastconjunction}{,}
\crefrangelabelformat{equation}{#3#1#4--#5#2#6)}
\crefrangeformat{equation}{eqs.~(#3#1#4--#5#2#6)}
\crefmultiformat{equation}{eqs.~(#2#1#3}{,#2#1#3)}{,#2#1#3}{,#2#1#3)}

\begin{document}
% create 6 equation-related \label instructions programmatically:
\directlua{
  for i=1,6 do tex.sprint ( '\\refstepcounter{equation}\\label{eq'..i..'}' ) end  
}

\obeylines
eqs.~(1,2,4--6) -- hard-coded
\cref{eq2,eq4,eq1,eq5,eq6} -- with \texttt{\string\cref}
\smallskip
\cref{eq1}
\cref{eq1,eq3}
\cref{eq2,eq4,eq3}
\crefrange{eq1}{eq5}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .