I store some strings in a variable \def\nomVAR{A12Z4E}
and I want to create some other command using the content of \nomVAR
. LaTeX doesn't accept to declare variable with number in its name. So the idea will be to convert all the number in the string using \numberstringnum
command (fmtcount
package). The xstring
can extract some specific string in a string but I have to precise the position of each one.
Do you think it is possible to write a function to convert each number to a string in a string and to rebuilt it?
Thus A12Z4E
will become AonetwoZfourE
.
MNWE
\documentclass{minimal}
\usepackage{xstring}
\usepackage{fmtcount}
\begin{document}
\def\nomVAR {A12Z4E}
\nomVAR
\numberstringnum{1}
\numberstringnum{\nomVAR} %not working
\end{document}
SOLUTION (thanks egreg)
\documentclass{minimal}
\usepackage{xstring}
\begin{document}
\def\nomVAR {A12Z4E}
\nomVAR
\numberstringnum{1}
\newcommand{\changestep}[2]{%
\expandafter\StrSubstitute\expandafter{\x}{#1}{#2}[\x]%
}
\newcommand{\changeall}[1]{
% suppress expansions made by xstring
\StrSubstitute{#1}{0}{zero}[\x]%
\x
\noexpandarg
\changestep{1}{one}
\changestep{2}{two}
\changestep{3}{three}
\changestep{4}{four}
\changestep{5}{five}
\changestep{6}{six}
\changestep{7}{seven}
\changestep{8}{eight}
\changestep{9}{nine}
\x
}
\changeall{\nomVAR}
\end{document}
Best Answer
You can do it expandably, provided the string only has alphanumeric ASCII characters:
A different
expl3
implementation: the argument to\convertdigits
is fully expanded before being examined and scanned item by item.