I have a command with a parameter. I want to check if its value is a positive number and perform actions based on that.
\newcommand{\mycommand}[1]{
\ifnum#1>0%
%some actions
\fi
}
But I receive errors when the value of the parameter is not a number, e.g.:
\mycommand{*}
How can I check if the value of #1 is a number?
Best Answer
Update:
Since it appears that the
\IfInteger
from thextring
package perceives blank strings as integers (the empty string{}
is ok, but not{ }
), I have defined a modified macro\IsInteger
which handles that case:You can use
IfInteger
from thexstring
package to test if it is an integer number:There is also
\IfDecimal
which works similarly.