Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\newif\ifnotfoo
\iffoo\notfoofalse\else\notfootrue\fi

And then use the \ifnotfoo test.

\ifnotfoo\dostuff\fi

The "else" method

Whenever you need to \dostuff, just do:

\iffoo\else\dostuff\fi

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

share|improve this question
4  
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
1  
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

1 Answer 1

up vote 15 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

\def\foofalse{\let\dostuff\realstuff}
\def\footrue{\let\dostuff\relax}

then you can replace the \iffoo construct with simply

 \dostuff

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

Your Answer

 
discard

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.