19

I understand well the \apptocmd and related tools of etoolbox package. However, I still not understand what \appto<hook>{<code>} and related do, even reading three time the handbook ?

Should package programmer define hook as a macro without argument (like \myhook) ? In this case, what is the difference with command patched by \apptocmd and related ?

15

The definition of \appto is

% etoolbox.sty, line 891:
\newrobustcmd{\appto}[2]{%
  \ifundef{#1}
    {\edef#1{\unexpanded{#2}}}
    {\edef#1{\expandonce#1\unexpanded{#2}}}}

The first argument should be a parameterless macro. Why not using \apptocmd? Because it is much less efficient and it may even not succeed if the replacement text has “non standard” tokens (for instance, characters with a different category code than usual).

Apart from this, the only other difference between \appto and \apptocmd is that the latter preserves the status of a \long (parameterless) macro, whereas \appto will always change it to non-\long.

| improve this answer | |
  • so \appto is recommaned for parameterless macro and \apptocmd for other macros? – Maïeul May 14 '16 at 21:33
  • @Maïeul Exactly so – egreg May 14 '16 at 21:34

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.