I have a large collection of macros that do different things but all eventually use the same macro internally (call this macro \tasks). Sort of like this, but with better macro names:

\newcommand{\aa}{... \tasks}
\newcommand{\bb}{... \tasks}
\newcommand{\zz}{... \tasks}

The \tasks macro has several parts which should be executed conditionally. This could be done using etoolbox or just plain \if, something like this:

\newcommand{\aa}{... \booltrue{subtaska}\boolfalse{subtaskb} ... \tasks}
\newcommand{\bb}{... \booltrue{subtaska}\booltrue{subtaskb} ... \tasks}

But all of this could also be performed using \let.

\newcommand{\aa}{... \let\xsubtaska\subtaska\let\xsubtaskb\relax ... \tasks}
\newcommand{\bb}{... \let\xsubtaska\subtaska\let\xsubtaskb\subtaskb ... \tasks}

I know that the approach using \let won't work if arguments need to be passed to the subtasks, since \relax (or \@empty) wouldn't be happy with that, but that isn't an issue for me.

Is there any advantage in taking the conditional approach versus the \let approach (ignoring the issue of arguments with \let)? For example, are there any performance benefits (yes, avoid premature optimization...) or special additional pitfalls one way or the other?

2 Answers 2


If you wanted to eat arguments you could still use \let but use \@gobble (or similar for more arguments) rather than \relax. It's clear that \let version is more efficient after that it's just a matter of personal style I think. The main reason etoolbox \ifbool is less efficient is that it does some sanity check that the first argument is a declared boolean switch. But if you are sure you won't mis-type and you always \let assign the intended thing then that's probably what I'd do.

  • 1
    On the other hand, the approach with booleans allows for \ifboolexpr which can be handy in many situations.
    – egreg
    Jun 21, 2012 at 16:33
  • Certainly in a few situations. I have discovered that 99 per cent of the calls to the costly \ifboolexpr are not necessary. It could almost always be done more efficiently. You may wish to give some contra-indications here.
    – Ahmed Musa
    Jun 21, 2012 at 19:33

As a practical matter, it may depend on how complex your conditionals are. In your simple situation, subtaska and subtaskb are independent of whether they appear in the context of \aa or \bb; however, you may need to make further decisions based on which of these macros was expanded, and then it's probably best to have a conditional that says "we are in this case".

More philosophically, you may be in the design situation where you are not yet sure of the structure of your tasks; then, you can model your own mental processes better using conditionals. Using the \let method is extremely rigid in terms of code structure. Once the code stabilizes you may find opportunities for streamlining it by using named subtasks.

And most philosophically, there is the question of whether the different code branches are really "doing the same thing" but in different ways, or are doing basically different things. The first situation sounds like a candidate for named subtasks; the second sounds like a case for conditionals.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .