[texhax] "Programming" in LaTeX
Heiko Oberdiek
heiko.oberdiek at googlemail.com
Thu Feb 22 20:07:36 CET 2018
Hello,
On 2018-02-22 15:48, Malte Thoma wrote:
> \documentclass{article}
> \usepackage{xstring,ifthen}
> \newcommand{\mytest}[1]{%
> \newcommand{\s}{\StrChar{#1}{3}}
This stores the complete macro \StrChar with
parameters in macro \s. Because macro \StrChar
is not full expandable, \s does *not* expand to "c"
in the example.
Use the optional argument of \StrChar to store the
result in \s:
\StrChar{#1}{3}[\s]%
> \newcommand{\x}{c}
> 3rd charactor of input is: \s ~equal to \x \\
> 1st test: \IfStrEq{\x}{c}{true}{false} \\
> 2nd test: \IfStrEq{\s}{c}{true}{false}
> }
> \begin{document}
> \mytest{abcd}
> \end{document}
Yours sincerely
Heiko
More information about the texhax
mailing list