[Tex/LaTex] A more elegant version of the \ifnot macro


A TUGboat article of 15 years ago mentions an \ifnot macro by David Kastrup whose implementation is:


However, this macro looks a bit weird when it is applied to an \ifSomething macro, i.e., \ifnot{\ifeof\stream}. For the purpose of making TeX code a bit more readable, it might be useful to have a macro which negates the "condition" itself, without the if prefix.

Here is a minimal example, which does not work.

  \if@not\@to@be@ Not to be! \fi
  \if@not\@to@be@ Not to be! \fi

Best Answer

Possibly something like this? It preserves the OP's desired syntax \ifnot\tobe, while at the same time not demanding that \tobe be predefined. Additionally, for those who don't like using \tobe without defining it, it allows the alternate syntax \ifnot{tobe}, without any changes whatsoever.

% Following 3 lines thanks to Prof. Enrico Gregorio, from:
% http://tex.stackexchange.com/questions/42318/
% removing-a-backslash-from-a-character-sequence
  \ifnot\tobe Not to be! \else To be!\fi\par
  \ifnot\tobe Not to be! \else To be!\fi

enter image description here

Related Question