A hook is simply a name for a group of actions which is executed
in certain places--presumably when it is most useful to allow
customization or modification. TeX already provides many builtin
hooks; for example, the \every ...
token lists are all
examples of hooks.
Eplain provides several macros for adding actions to hooks. They all take two arguments: the name of the hook and the new actions.
hookaction name actions
hookappend name actions
hookprepend name actions
hookactiononce name \cs
\hookactiononce
adds cs to name, like the macros
above, but first it adds
\global\let \cs \relaxto the definition of \cs. (This implies \cs must be a true expandable macro, not a control sequence
\let
to a
primitive or some other such thing.) Thus, \cs is expanded the
next time the hook name is run, but it will disappear after that.
The \global
is useful because \hookactiononce
is most
useful when the grouping structure of the TeX code could be anything.
Neither this nor the other hook macros do global assignments to the hook
variable itself, so TeX's usual grouping rules apply.
The companion macro to defining hook actions is \hookrun
, for
running them. This takes a single argument, the name of the hook. If
no actions for the hook are defined, no error ensues.
Here is a skeleton of general \begin
and \end
macros that
run hooks, and a couple of calls to define actions. The use of
\hookprepend
for the begin action and \hookappend
for the
end action ensures that the actions are executed in proper sequence with
other actions (as long as the other actions use \hookprepend
and
\hookappend
also).
\def\begin#1{ ... \hookrun{begin} ... } \def\end#1{ ... \hookrun{end} ... } \hookprepend{begin}\start_underline \hookappend{end}\finish_underline