I am currently trying to create new commands to add the correct French article in front of the cross-references when required (for example "la figure XX" or "le chapitre XX").
My initial idea was to create commands like \acref and \Acref somehow like that:
\newcommand{\acref}[1]{%
\def\rtype{\namecref{#1}}% namecref will produce something like "figure"
\def\article{{\bf error:[\rtype](#1)} }% default value to help debugging
\ifstrequal{\rtype}{figure}{\def\article{la }}{}%
\article\cref{#1}\xspace
}
I also tried adding \expandafter around \ifstrequal like that:
\expandafter\ifstrequal\expandafter{\rtype}{figure}{\def\article{la }}{}%
And I tried some other combinations of commands that I do not master, with bad results.
All my attempts produced an invalid output, either always using the article for figure (as it is currently the only one I try to test) because both branches of the conditional statement are executed (with too much \expandafter) or it never enters the true branch.
Minimal compiling and not working example:
\documentclass{paper}
\usepackage{cleveref}
\usepackage{etoolbox}
\usepackage{xspace}
\crefname{figure}{figure}{figures} % instead of fig.
\newcommand{\acref}[1]{%
\def\rtype{\namecref{#1}}% namecref will produce something like "figure"
\def\article{{\bf error:[\rtype](#1)} }% default value to help debugging
\ifstrequal{\rtype}{figure}{\def\article{la }}{}%
\article\cref{#1}\xspace
}
\begin{document}
\section{Title}
\label{sec:title}
\begin{figure}
\caption{Caption}
\label{fig:caption}
\end{figure}
Test with figure: \acref{fig:caption}. % should print "la figure" but prints error:...
Test with section: \acref{sec:title}. % should print error:...
\end{document}
I read that etoolbox does not expand its arguments in most of its tests, including \ifstrequal.
I had the idea to create a list containing the result of \namecref as there is \listeadd which expands its item argument and then test if that list contains the text "figure".
However, when I tried (\listeadd{\mylist}{\namecref{#1}}), pdflatex stopped compiling and returned (filtered):
! Argument of \@firstoftwo has an extra }
! Paragraph ended before \@firstoftwo was complete.
! TeX capacity exceeded, sorry [parameter stack size=10000].
So, is \namecref unexpandable?
Really close questions that I failed to make work in my case:


\crefname{figure}{la figure}{les figures}? – Mico Apr 17 '20 at 13:25\ref. – Bernard Apr 17 '20 at 13:32\creflikesome text (\cref{fig:lbl})which would be incorrectly expanded as "some text (la figure 2)". @Bernard and, I find using\refdefeats one advantage of\crefthat allows to change easily all prefixes for a given label type. – Soko Apr 17 '20 at 13:45pdflatexproduces a PDF with??. The second one throws the errorUndefined control sequence. <recently read> \text_titlecase:nnon line 109 of the french example (... via \textsf{xcref} \fxcref{sec-exemples}. – Soko Apr 20 '20 at 09:29expl3is too old .\text_titlecase:nnwas introduced inLaTeX2e <2020-02-02> patch level 1(previously, there were other functions for the same thing inexpl3, but they behaved differently; this is the name changing I mentioned above). Besides, requiring at least two compilations when using references is quite normal—this is how references work and explains the??after only one compilation run. – frougon Apr 20 '20 at 09:43expl3, xcref commit 68342b43f24 should work for you, but beware that it will break when your LaTeX becomes up-to-date. – frougon Apr 20 '20 at 09:57nameinlinkthing is one of the biggest things I'm unhappy about, but I believe it can't be fixed using my approach without hackingcleveref(the other being that it is a brute force approach). The answer to your question is “the former”: when they know the circumstances (combination offormandprepositionfor French, but for German, thecasealso matters), my commands call\crefnameand\Crefnamefor all known ref types (this is where it is brute force), which locally changes the results produced bycleveref. – frougon Apr 20 '20 at 13:01\@@_call_crefname:nnnand\@@_call_Crefname:nnnin my code, maybe this will help you understand. I believe what you wanted to do can't be done this way becausecleverefdoesn't produce its results in an “expandable” manner (you can't get the result in\xusing\edef\x{...}, where...contains simple calls tocleverefmacros). – frougon Apr 20 '20 at 13:02cleverefname (theorem, proposition, etc.) associated to a given ref, programmatically transform it depending on which one it is, and also retrieve the number/letter/etc. (whatcleverefcalls the “label”) associated to the ref. In fact, I think the first part is exactly what you need for this question. – frougon Apr 20 '20 at 13:12