Consider the following macro definitions:
\def\mymacro#1{\mymacroii#1\nil}
\def\mymacroii#1#2\nil{%
\ifx\\#1\\%
empty%
\else
#1%
\fi
}%
\mymacro{foo}% -> f
\mymacro{}
\bye
This is supposed to extract the first character of the parameter to \mymacro
. This works, but only if the argument is not empty.
How must I change my macros, so that the call \mymacro{}
works as expected, i.e. outputs "empty"? Note, that is is only a simplified version. In reality I have several checks in \mymacroii
for the first character, if it is a number, an opening brace, and so on.
This question is for sure related to Why does TeX remove braces around delimited arguments?, but I couldn't apply those informations to my case.
expl3
(we have tests for opening brace, ... plus a very robust 'first token' function)?pst-optexp
package, which doesn't useexpl3
. I don't want to add that dependencies for now, especially because I haven't worked with it at all.pstricks
package. I had a look at theexpl3
files, but couldn't get a good starting point. Where could I start for investigating on these specific tests?