I'm reading in a number (as text) from the aux file and I want to do a numerical test (\ifnum) on it. I can to it using \setcounter and \value, but I really don't want to create a counter just to do a lousy test. Is there a simpler way?
Using pgfmath is not by any stretch of the imagination simpler.
\documentclass{article}
\newcount\test
\newcounter{test}
\begin{document}
\def\temp{1}
\setcounter{test}{\temp}
\ifnum\value{test}>0 Yea!
\else Boo!
\fi
\test=\temp
\ifnum\test>0 Yea!
\else Boo!
\fi
\end{document}
In retrospect, my mistake is obvious. In an expression like
\test=1
the end-of-line terminates both adding digits and conversion of "1" to a count. But with
\test=\temp
the end-of-line is consumed terminating the macro name. I suspect that the final expansion of this is actually
\test=1 Boo!
which is legal but too late. The simplest solution
\test=\temp\relax
uses \relax to force the expression to completion.

\ifnum\temp>0...? Additionally, if you need to operate on the variable, you can use a\numexpras in\ifnum\numexpr\temp-2\relax>0...– Steven B. Segletes Dec 16 '14 at 20:23\ifdim\temp pt>...– percusse Dec 16 '14 at 20:28etoolboxwhich provides a host of numeric comparison functions. – Werner Dec 16 '14 at 20:34\relax, nor would people benefit from such a tag for this question. – Werner Jan 01 '15 at 20:16\relaxto close out the operation. – Steven B. Segletes Jan 07 '15 at 21:06