I need to check several macros and do some actions only if their expansion is not empty nor space only.
In pseudo code I would look like this
\if\macroToBeTested
\doSomething
\doSomethingElse
\fi
macros \doSomething
and \doSomethingElse
should only execute if \macroToBeTested
expands to something that contains at least one character which is not space.
How can I implement that? I prefer using something like this
\if\test{\macroToBeTested}%
\doSomething%
\doSomethingElse%
\fi
rather then anything like this
\test{\macroToBeTested}{%
\doSomething%
\doSomethingElse%
}
EDIT
Here is example (pseudocode)
\newcommand{\macroToBeTested}{ }%
Hello%
\if\test{\macro}%
World!%
\fi
This would print only "Hello", while this
\newcommand{\macroToBeTested}{ s }%
Hello%
\if\test{\macro}%
World!%
\fi
should print "Hello World!".
Best Answer
Just use the code by D. Arsenau mentioned in Is "conditionals" name of package? with an additional macro:
Now
will do.
You can define similarly
\expnil
and\expgiven
.Complete example
The log shows