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
\xdefinstead of\edefas in my original code.\xdefnot only expands but makes a global assignment, rather than a local one. – Andrew Swann Jan 20 '23 at 07:34