What exactly is meant by this and how could it be used?
Best Answer
Programmers call "hooks" pieces of code that are executed every time something happens, and that can be "added to" by other programmers. This is like a hook you may have on your bag: you can put your phone or your camera on it. What exactly you hook there can be decided later; the hook is there for anything.
For example, you may print on every page a draft mark. Or send yourself an e-mail "Page 2 is printed". You add the program that does this to a page hook, and it is done every time you ship out a page.
\def\foo{\message{Here is the original \string\foo}}
\def\foohook{\message{Whatever.}}
% Add a hook to \foo (\foohook does not have be predefined):
\toks0\expandafter{\expandafter\foohook\foo}
\edef\foo{\the\toks0}
% Demo:
\foo
\def\foohook{\message{Redefined \string\foohook}}
\foo
\bye
(Complete working example; to turn it into latex, remove \bye and add necessary latex cruft.)
% 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.
Best Answer
Programmers call "hooks" pieces of code that are executed every time something happens, and that can be "added to" by other programmers. This is like a hook you may have on your bag: you can put your phone or your camera on it. What exactly you hook there can be decided later; the hook is there for anything.
For example, you may print on every page a draft mark. Or send yourself an e-mail "Page 2 is printed". You add the program that does this to a page hook, and it is done every time you ship out a page.