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.
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.
Among its primitive conditionals, TeX has \ifodd:
\ifodd<number><true text>\else<false text>\fi
Be careful though that testing
\ifodd\value{page}
(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
\ifodd\value{<counter>}
(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.
\unless\ifodd; but you can't do \def\ifeven{\unless\ifodd} if you plan to nest it in other conditionals. You could do \def\even{TT\fi\unless\ifodd} and use \if\even, though. Using \ifodd seems simpler. ;-)
– egreg
Sep 17 '18 at 17:54
\unless\ifodd could come in handy! One for the toolbox. Thanks egreg.
– PatrickT
Sep 17 '18 at 18:03
\ifodd<number><true>\else<false>\fi– egreg Feb 05 '15 at 20:39\ifoddor similar in the answers to the linked question? I can't. – egreg Feb 05 '15 at 20:44ifodd is:answer [conditionals], but most references page numbers. – Werner Feb 05 '15 at 20:46