I try do define a macro \onoff
, which alternatively prints "on" and "off" each time it's used. For example the sequence \onoff \onoff \onoff
would print on off on
My first guess would be to use the following code:
\def\a{on}
\def\b{off}
\newcommand\onoff{\a\def\c{\a}\def\a{\b}\def\b{\c}}
However this code doesn't work. Is there an elegant way to code this?
Best Answer
One way
Another way (was a now deleted separate answer)
A third way