I try to store the result of an xstring
pagckage’s command in another command (or variable, I don’t care), to reuse it in another xstring
’s command, as you can see in the following MWE:
\documentclass{article}
\usepackage{xstring}
\begin{document}
%extract the first letter of the string “Abbbbbbb” and store it on the command “\temp”
\newcommand\temp{\StrChar{Abbbbbbb}{1}}
% Printing the contente of the command “\temp”, normaly it should be “A”
\temp
% Test if the content of the command “\temp” is “A”
\IfStrEq{\temp}{A}{True}{False}
\end{document}
When I compile it, I get the following message
! TeX capacity exceeded, sorry [parameter stack size=10000].
\@xs@IfStrEq@@ #1#2->
\@xs@assign \@xs@arg@i {#1}\@xs@assign \@xs@arg@ii {#2}...
l.9 \IfStrEq{\temp}{A}
{True}{False}
No pages of output.
Transcript written on test.log.
I also try to store the \StrChar
output in a variable instead of command, unfortunately I have the same behavior at the compilation as you can see in this second MWE:
\documentclass{article}
\usepackage{xstring}
\begin{document}
%extract the first letter of the string “Abbbbbbb” and store it on the variable “\temp”
\def\temp{\StrChar{Abbbbbbb}{1}} % ← It’s only this line who is different from the first MWE
% Printing the contente of the command “\temp”, normaly it should be “A”
\temp
% Test if the content of the command “\temp” is “A”
\IfStrEq{\temp}{A}{True}{False}
\end{document}
And I have the same compilation error output.
I think that \StrChar
produce in his output some formating not-visible commands which disturb \IfStrEq
. And It would be probably needed to erase this formating not-visible commands before the \IfStrEq
proceeding. But it’s just an hypothesis.
So how can I store an \StrChar
output by a way witch can allow me to use this output as in imput of another xstring
’s command?
\documentclass{article} \newcommand\getfirst[1]{\getfirstaux#1\relax} \def\getfirstaux#1#2\relax{#1} \begin{document} \def\temp{\getfirst{Abbbbbbb}} \temp\par \if A\temp True\else False\fi \end{document}
n
a fixed number known in advance, or isn
the totality of the string? Also, there is thestringstrings
package which can do this, though (as the author) I can say the package has other issues making it less than ideal.