0

I am trying to implement this solution: https://tex.stackexchange.com/a/418261/194338 or this solution: https://tex.stackexchange.com/a/416838/194338

but both fail in my case. Here is a minimal example:

\documentclass{article}
\usepackage{subcaption}
\usepackage{cleveref}
\crefrangelabelformat{figure}{#3#1#4 to #5\crefstripprefix{#1}{#2}#6}

\crefmultiformat{figure}% {\edef\mycrefprefixinfo{#1}figs.~#2#1#3}% { and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}% <- cannot access \mycrefprefixinfo when there is a range created {, #2\crefstripprefix{\mycrefprefixinfo}{#1}#3}% {, and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}

\begin{document}

\cref{fig:test:1,fig:test:2,fig:test:3} % works: figs. 1a to c \cref{fig:test:1,fig:test:3} % works: figs. 1a and c \cref{fig:test:1,fig:test:3,fig:test:4} % works: figs. 1a, c, and d \cref{fig:test:1,fig:test:2,fig:test:3,fig:test:5} % fails, should be figs. 1a to c and e

\begin{figure} \centering {\phantomsubcaption\label{fig:test:1}}% {\phantomsubcaption\label{fig:test:2}}% {\phantomsubcaption\label{fig:test:3}}% {\phantomsubcaption\label{fig:test:4}}% {\phantomsubcaption\label{fig:test:5}}% \caption{General caption} \end{figure}

\end{document}

Basically it seems to fail when it creates a range. From my tests, it seems that when there is a range, the parameter \mycrefprefixinfo is not anymore accessible in the third argument of \crefmultiformat

Chachni
  • 183

1 Answers1

0

So based on @AndrewSwann comment and @AndrewSwann's updated answer here: customizing cleveref for pair of subfigure references: [1a and b] instead of [1a and 1b]

2 modifications are necessary: change \edef to \xdef and also add the definition of the variable \mycrefprefixinfo inside \crefrangelabelformat:

\crefrangelabelformat{figure}%
  {\xdef\mycrefprefixinfo{#1}#3#1#4 to #5\crefstripprefix{#1}{#2}#6}

\crefmultiformat{figure}% {\xdef\mycrefprefixinfo{#1}figs.~#2#1#3}% { and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}% {, #2\crefstripprefix{\mycrefprefixinfo}{#1}#3}% {, and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}

Depending on usecase, one might also need to redefine \crefrangemultiformat

Adding the definition of the variable \mycrefprefixinfo inside \crefrangelabelformat is necessary for the code above if one only calls \cref{fig:test:1,fig:test:2,fig:test:3,fig:test:5}, without calling \cref{fig:test:1,fig:test:3}, which puts the definition of \mycrefprefixinfo in the global space.

Chachni
  • 183