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: