Is it possible to have a command alternate its behaviour?

My idea is something like this:


\def \current {c}

\def \abc {

    \abc \abc \abc

I'd expect this to output a b c, but instead I get:

enter image description here

I'm guessing that the logic inside is only run when the \abc is being defined, and that's why it's always stuck at a. How can I write something with the desired behaviour?

  • 1
    no the expression inside a command definition is not evaluated at all (the replacement text can use undefined commands and there is no error if the command is not used) – David Carlisle Feb 11 '20 at 23:18
  • 1
    You've fallen in the XY problem fallacy :-) It's usually best not to edit a question in a way that invalidates existing answers. In such cases it's best to ask a new question altogether – Phelype Oleinik Feb 11 '20 at 23:34
  • @PhelypeOleinik Will do so :) – Luke Collins Feb 11 '20 at 23:35
  • @PhelypeOleinik actually it was only a minor tweak here I edited the answer to match – David Carlisle Feb 11 '20 at 23:38
  • @LukeCollins Thanks! Though David was faster :-) Seems like I caused a big mess with one single comment... – Phelype Oleinik Feb 11 '20 at 23:43

compares \current against { which is not what you intended,



    \abc \abc \abc

For the updated case note that the argument of \color has to expand to a name, so can not have assignments, and the tikz for loop groups each iteration so you need a global assignmet




        \foreach \i in {1,...,10} {
            \node at (\i,\i) {\currentcol \i};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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