8

I managed to get cross-referencing with cleveref to examples in the format "examples (1a-1c)" using

\crefrangeformat{xnumi}{examples~(#3#1#4--#5#2#6)}

but how can I get "examples (1a-c)"?

I found this question, but I'm afraid the solution is dependent to the package in use, in this case gb4e, so I decided to post my answer anyway.

Here's my MWE:

\documentclass[a4paper]{article}
\usepackage{gb4e}
\usepackage{cleveref}
\newcommand{\crefrangeconjunction}{--}
\crefname{xnumi}{example}{examples}
\creflabelformat{xnumi}{(#2#1#3)}
\crefname{xnumii}{example}{examples}
\creflabelformat{xnumii}{(#2#1#3)}
\crefname{xnumiii}{example}{examples}
\creflabelformat{xnumiii}{(#2#1#3)}
\crefname{xnumiv}{example}{examples}
\creflabelformat{xnumiv}{(#2#1#3)}
\crefrangeformat{xnumi}{examples~(#3#1#4--#5#2#6)}
\crefrangeformat{xnumii}{examples~(#3#1#4--#5#2#6)}
\crefrangemultiformat{xnumii}{examples~(#3#1#4--#5#2#6)}{ and~(#3#1#4--#5#2#6)}{, (#3#1#4--#5#2#6)}{ and~(#3#1#4--#5#2#6)}

\begin{document}

\section{Prova}

\begin{exe}
\ex\label{e:pro} uno due tre
\begin{xlist}
\ex\label{e:1} uno
\ex\label{e:2} due
\ex\label{e:3} tre
\ex\label{e:4} quattro
\end{xlist}
\end{exe}

In \cref{e:pro}, in \crefrange{e:1}{e:3}.

\end{document}
6

This is a bit of a hack, and doesn't quite work at the moment, since it only works in the case that there are no other examples between the referenced examples in the text. This is obviously unacceptable as a general solution.

\documentclass[a4paper]{article}
\usepackage{gb4e}
\makeatletter
\renewcommand\p@xnumii{}
\makeatother

\usepackage[sort&compress]{cleveref}
\newcommand{\crefrangeconjunction}{--}
\crefname{xnumi}{example}{examples}
\creflabelformat{xnumi}{(#2#1#3)}
\crefname{xnumii}{example}{examples}
\creflabelformat{xnumii}{(#2#1#3)}
\crefname{xnumiii}{example}{examples}
\creflabelformat{xnumiii}{(#2#1#3)}
\crefname{xnumiv}{example}{examples}
\creflabelformat{xnumiv}{(#2#1#3)}
\crefrangeformat{xnumi}{examples~(#3#1#4--#5#2#6)}
\crefrangeformat{xnumii}{examples~(#3\arabic{xnumi}#1#4--#5#2#6)}
\crefrangemultiformat{xnumii}{examples~(#3\arabic{xnumi}#1#4--#5#2#6)}
{ and~(#3\arabic{xnumi}#1#4--#5#2#6)}{, (#3\arabic{xnumi}#1#4--#5#2#6)}
{ and~(#3\arabic{xnumi}#1#4--#5#2#6)}


\begin{document}

\section{Prova}

\begin{exe}
\ex\label{e:pro} uno due tre
\begin{xlist}
\ex\label{e:1} uno
\ex\label{e:2} due
\ex\label{e:3} tre
\ex\label{e:4} quattro 
\end{xlist}
\end{exe}

In \cref{e:pro}, in \crefrange{e:1}{e:3}.

\end{document}

output of code

  • @Mico The wonders of cut and paste. :) – Alan Munn Oct 16 '13 at 0:45
  • @AlanMunn No, it doesn't work. Try setting another exe environment between the original one and the references. Your \crefrangeformat command always uses the current value of xnumi. – egreg Oct 16 '13 at 6:39
  • @egreg: It worked for me. But when you use \cref with subexamples you get only the letter now. \cref{e:1} = example (a). – Stefano Oct 16 '13 at 9:19
  • EDIT: Stupid of me. I've changed xnumii format to \creflabelformat{xnumii}{(#2\arabic{xnumi}#1#3)} and now it works correctly. – Stefano Oct 16 '13 at 9:25
  • @Stefano egreg is right. It doesn't work. Can you unaccept the answer? I'd like to delete it if I can't fix it. – Alan Munn Oct 16 '13 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.