I am looking for a conditional command with the next structure
ifnum x is even DO THIS \else DO THIS \fi
usually ifnum
command have the options = < >
, but I would like to have the option even and odd.
conditionals
I am looking for a conditional command with the next structure
ifnum x is even DO THIS \else DO THIS \fi
usually ifnum
command have the options = < >
, but I would like to have the option even and odd.
Best Answer
Among its primitive conditionals, TeX has
\ifodd
:Be careful though that testing
(in LaTeX, it would be
\ifodd\pageno
in Plain TeX) is not reliable due to the asynchronous page breaking mechanism. Refer to If Then Else for odd page/even page for this specific problem.On the other hand if you want to test whether another LaTeX counter is even or odd, you can safely test
(in Plain TeX,
\ifodd\counter
;<counter>
or\counter
stand for the specific name).Anything that satisfies the syntax for a
<number>
can follow\ifodd
; the usual caveat about expansion in this context apply; a space token following an explicit constant is looked for (with expansion) and ignored.