TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, here are two ways you might set things up such that \dostuff is done when foo is false.

The "new conditional" method

If you know when foo is going to be set, then after that do:


And then use the \ifnotfoo test.


The "else" method

Whenever you need to \dostuff, just do:


Is either method recommended over the other? If so, why? (Or is there another method which is even better?

share|improve this question
The first is really inferior, because it needs an additional assignment. So for instance, it can't be used in expandable contexts. As a third alternative, there is \unless\iffoo. – Stephan Lehmke Jul 2 '12 at 11:50
AFAIK there is also an \unless primitive in e-TeX which negates a following \if.... Then you still can use \else as well. – Martin Scharrer Jul 2 '12 at 11:50
up vote 19 down vote accepted

Hard to comment on efficiency (one of your tags) without knowing more context. \footrue and \foofalse are really each just a \let. So if the only reason that this token is let to one definition or another is so that you can decide whether or not to "do stuff" then you don't need the if token at all, then you don't need the test.

Just define


then you can replace the \iffoo construct with simply


and it will either do nothing or the real definition depending on whether \foofalse or \footrue was most recently executed. Since this saves expanding \iffoo and skipping over the conditional text it is more efficient in principle but whether the difference is measurable on modern machines I haven't checked. It is unlikely that any of these make any real difference unless you do (literally) millions of tests.

share|improve this answer

You asked for a "better" method. I find the method using the package ifthen (thanks to David Carlisle :-)) quite easy to read and to adapt. Take a look:

\ifthenelse{\NOT \boolean{foo}}{\dostuff}{}

(no idea about efficiency, though)

The empty braces at the end {} are the empty else option. You can leave them out and write simply \ifthenelse{\NOT \boolean{foo}}{\dostuff} if you leave an empty line after the command to avoid any unexpected result.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.