How do I test if a given parameter is a number, in order to apply a different style? And if not, just ignore... Like:
\domorestuffifnumber{things} -> things
\domorestuffifnumber{123} -> \emph{123}
Thanks.
|
How do I test if a given parameter is a number, in order to apply a different style? And if not, just ignore... Like:
Thanks. |
|||
|
Here's a slightly flawed, but slightly more generic thing than you're asking for.
It's slightly complicated by checking if the first token in the expansion of the argument is a But from the
|
|||
|
Herbert |
|||||||||
|
|
A LuaTeX solution:
and the
I think the solution is quite readable. |
|||
|
|
|
This is a somewhat late answer, but I am including it here for completeness. When TeX is expecting a number a trailing zero will be ignored if it is followed by another number. However, if the 0 is followed by a non-number it will stop the scanning and insert the letter in the stream. The macro that follows capitalizes on this fact. We set a counter this way within a box. If it is a number the input gets fully absorbed and the width of the box is zero. If it is not a number the box will contain the non-numbers and hence its width will be greater than zero. By testing for the width of the box we can know if the input was a number or not.
Empty input is treated a zero, and this can be useful in many situations. (Edit: simplified as per egreg's comments) |
|||||||||
|
tikz-timingpackage. See the source code if you are interested. – Martin Scharrer♦ May 21 '12 at 7:30