Go to the first, previous, next, last section, table of contents.

Hooks

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
Each of these adds actions to the hook name. (Any previously-defined actions are retained.) name is not a control sequence, but rather the characters of the name.
hookactiononce name \cs
\hookactiononce adds cs to name, like the macros above, but first it adds
\global\let \cs \relax
to 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

Go to the first, previous, next, last section, table of contents.