0

I have a command like this:

\def\command#1{%
    \calc{#1}%
    \doStuff%
}

\calc sets certain lengths based on the current size. As such it cannot be executed in the preamble. This works as expected.

However, I want to define a new command

\def\command2{%
    \command{default}%
}

How can I do that? I can’t put the above in the preamble since the compiler is trying to evaluate \calc and the expected errors occur.

Peter Grill
  • 223,288

2 Answers2

1

If you want to defer something to not executed in the preable you can use \AtBeginDocument{} or \AtEndPreamble{}.

References:

Peter Grill
  • 223,288
0
\def\command#1{%
    \calc{#1}%
    \doStuff%
}
% ...
\def\command2{%
    \command{default}%
}

I suppose you are misinterpreting error-messages:

\def does not trigger but does prevent evaluation.

But when reading/tokenizing the .tex-input file TeX does tokenize the sequence \command2 as control-word-token \command trailed by the explicit character token 2 of category 12(other).

Thus with \def\command2{\command{default}} the control-word-token \command is redefined to be something that is delimited by 2 and that as replacement-text delivers the control-word-token \command for calling itself (which implies unwanted recursion), trailed by character-tokens {, d, e, f, a, u, l, t and }.

Any attempt at expanding the macro \command without a trailing 2 yields a message about usage of \command not matching its definition.

Even if the first instance of \command is trailed by 2 you get this message because in this case expansion of \command 2 yields \command {default} where you have an instance of the control-word-token \command which is not trailed by 2.


Between \makeatletter..\makeatother you can probably do something like

\def\command#1{%
    \calc{#1}%
    \doStuff%
}%
% ... 
% defining the command:
\@namedef{command2}{%
    \command{default}%
}%
% ...
% calling/using the command:
\@nameuse{command2}%

(\@namedef / \@nameuse internally use \csname..\endcsname for constructing control-word-tokens whose names may also contain digits like 2.)

Ulrich Diez
  • 28,770