Debian Codegraph @

texmf-dist/source/latex/everyhook/everyhook.dtx

raw
1 % \iffalse The license starting three lines down applies to this file
2 %<*batchfile>
3 \begingroup\input docstrip \preamble
4 Copyright (C) 2010, 2011, 2014 by Stephen Checkoway
5
6 This file may be distributed and/or modified under the
7 conditions of the LaTeX Project Public License, either
8 version 1.3c of this license or (at your option) any later
9 version. The latest version of this license is in:
10
11 http://www.latex-project.org/lppl.txt
12
13 and version 1.3c or later is part of all distributions of
14 LaTeX version 2005/12/01 or later.
15
16 This work has the LPPL maintenance status 'maintained'.
17
18 The Current Maintainer of this work is Stephen Checkoway.
19
20 This work consists of everyhook.dtx and the derived file
21 everyhook.sty.
22 \endpreamble
23 \keepsilent
24 \usedir{tex/latex/everyhook}
25 \askforoverwritefalse
26 \generate{\file{\jobname.sty}{\from{\jobname.dtx}{}}}
27 \endgroup
28
29 \documentclass{ltxdoc}
30 \usepackage{fixltx2e}
31 \usepackage{etoolbox}
32 \usepackage[osf]{mathpazo}
33 \usepackage[scaled=0.86]{berasans}
34 \usepackage[scaled=1.03]{inconsolata}
35 \usepackage[T1]{fontenc}
36 \usepackage{microtype}
37 \usepackage[margin=1.5in]{geometry}
38 \usepackage[excludeor]{everyhook}
39 \usepackage{enumitem}
40 \usepackage[pdfborder={0 0 0}]{hyperref}
41 \usepackage{ifpdf}
42 \usepackage{listings}
43 \usepackage{lipsum}
44 \begingroup
45 \catcode`\^^09\active
46 \gdef\obeytabs{%
47 \catcode`\^^09\active
48 \def^^09{\ \ \ \ \ \ \ \ }%
49 }
50 \endgroup
51 \makeatletter
52 \patchcmd\macrocode{\@vobeyspaces}{\@vobeyspaces\obeytabs}{}{\undefined}
53 \makeatother
54
55 \CheckSum{190}
56 \CharacterTable
57 {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
58 Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
59 Digits \0\1\2\3\4\5\6\7\8\9
60 Exclamation \! Double quote \" Hash (number) \#
61 Dollar \$ Percent \% Ampersand \&
62 Acute accent \' Left paren \( Right paren \)
63 Asterisk \* Plus \+ Comma \,
64 Minus \- Point \. Solidus \/
65 Colon \: Semicolon \; Less than \<
66 Equals \= Greater than \> Question mark \?
67 Commercial at \@ Left bracket \[ Backslash \\
68 Right bracket \] Circumflex \^ Underscore \_
69 Grave accent \` Left brace \{ Vertical bar \|
70 Right brace \} Tilde \~}
71
72 \EnableCrossrefs
73 \CodelineIndex
74 \RecordChanges
75 \GetFileInfo{\jobname.sty}
76 \title{The \textsf{\jobname} package\thanks{This document
77 corresponds to \textsf{\jobname}~\fileversion, dated \filedate.}}
78 \author{Stephen Checkoway\\\texttt{[email protected]}}
79
80 \lstset{language=[LaTeX]TeX,basicstyle=\ttfamily,
81 texcsstyle=*\normalfont\bfseries,
82 moretexcs={paragraph,RequirePackage},xleftmargin=\parindent}
83
84 \renewcommand*\arg[1]{\textsf{\{#1\}}}
85 \makeatletter
86 \renewcommand*\meta@font@select{\normalfont\itshape}
87 % \DescribeOption taken from trivfloat.dtx
88 \newcommand*{\DescribeOption}{%
89 \leavevmode
90 \@bsphack
91 \begingroup
92 \MakePrivateLetters
93 \Describe@Option
94 }
95 \newcommand*{\Describe@Option}[1]{%
96 \endgroup
97 \marginpar{%
98 \raggedleft
99 \PrintDescribeEnv{#1}%
100 }%
101 \@esphack
102 \ignorespaces
103 }
104 \makeatother
105 \begin{document}
106 \maketitle
107
108 \begin{abstract}
109 The \textsf{\jobname} package takes control of the six \TeX\
110 token parameters \cs{everypar}, \cs{everymath}, \cs{everydisplay},
111 \cs{everyhbox}, \cs{everyvbox}, and \cs{everycr}. Real hooks for
112 each of these can be installed using a stack like interface. For
113 compatibility with \LaTeX\ standard classes and packages, each of
114 the \cs{everyX} token lists can be set without interfering with the
115 hooks.
116 \end{abstract}
117 \tableofcontents
118
119 \section{Introduction}
120 \TeX\ contains nine token parameters, seven of which are inserted
121 into the current list at various times. Quoting from \textit{The
122 \TeX book}, the seven token parameters of interest are\footnote{The remaining two
123 token parameters are \cs{output} and \cs{errhelp}.}
124 \begin{description}[labelindent=1em, noitemsep]
125 \item{\cs{everypar}\enskip} tokens to insert when a paragraph begins,
126 \item{\cs{everymath}\enskip} tokens to insert when math in text begins,
127 \item{\cs{everydisplay}\enskip} tokens to insert when display math begins,
128 \item{\cs{everyhbox}\enskip} tokens to insert when an hbox begins,
129 \item{\cs{everyvbox}\enskip} tokens to insert when a vbox begins,
130 \item{\cs{everyjob}\enskip} tokens to insert when the job begins, and
131 \item{\cs{everycr}\enskip} tokens to insert after every \cs{cr} or
132 nonredundant \cs{crcr}.
133 \end{description}
134 Of these, \cs{everyjob} is not very useful outside of INITEX and so
135 it won't be considered further.
136
137 The remaining six token parameters can be used to great effect. For
138 example, the \cs{everypar} is used in \cs{paragraph} to set the title
139 of the paragraph inline allowing constructions like\\
140 \indent\hbox to.45\textwidth{%
141 \begin{lstlisting}[boxpos=b]
142 \paragraph{Paragraph title.}
143
144 A blank line followed by
145 the rest of the paragraph.
146 \end{lstlisting}\hfil
147 }
148 \hfill
149 \parbox[b]{.45\textwidth}{
150 \paragraph{Paragraph title.}
151
152 \strut A blank line followed by the rest of the paragraph.
153 \\[\baselineskip]
154 }\\[\baselineskip]
155 which work properly rather than starting a new paragraph due to the
156 blank line.
157
158 Similarly, \cs{everymath} and \cs{everydisplay} are used by the
159 \LaTeX\ kernel to set up math fonts.
160
161 Using the \TeX\ primitives directly has the major downside that they
162 cannot be used by multiple packages at the same time. Setting
163 \cs{everypar} overwrites a prior usage. Even if one package is careful
164 and always uses
165 \begin{lstlisting}
166 \everypar=\expandafter{\the\everypar new tokens here}
167 \end{lstlisting}
168 so as not to stomp on another's usage, there's no guarantee that the
169 other package will not later set \lstinline!\everypar={}!.
170
171 To get around this, the \textsf{\jobname} package takes control of the
172 six \cs{everyX} primitives listed above and for each one provides a
173 stack like interface for two additional token lists, one to be
174 expanded before the \cs{everyX} and one to be expanded after. For
175 example,
176 \begin{lstlisting}
177 \PushPreHook{hbox}{1}
178 \PushPreHook{hbox}{2}
179 \everyhbox={3}
180 \PushPostHook{hbox}{4}
181 \PushPostHook{hbox}{5}
182 \end{lstlisting}
183 will cause the insertion of the tokens |21345| at the start of an
184 \cs{hbox}. Note that \cs{PushPreHook} adds tokens to the \emph{left}
185 of the list of tokens to appear before those in \cs{everyhbox} whereas
186 \cs{PushPostHook} adds tokens to the \emph{right} of the list of
187 tokens to appear after those in \cs{everyhbox}.
188
189 \section{Usage}
190 The \textsf{\jobname} package has one (rather experimental) option,
191 |excludeor| and is loaded using
192 \begin{lstlisting}
193 \usepackage[excludeor]{everyhook}
194 \end{lstlisting}
195 or
196 \begin{lstlisting}
197 \RequirePackage[excludeor]{everyhook}
198 \end{lstlisting}
199 as required where the option is, of course, optional.
200
201 \subsection{Options}
202 \DescribeOption{excludeor}
203 Some of the hooks described below can cause unwanted behavior when
204 active during the execution of \LaTeX's output routine. The
205 experimental |excludeor| option saves and clears the hooks at
206 the beginning of the output routine and restores them at the end.
207
208 \subsection{Manipulating hooks}
209 There are 12 hooks, a pre and post hook for each of the six token
210 parameters |par|, |math|, |display|, |hbox|, |vbox|, and |cr|. The
211 first argument to all of the macros described in this section must be
212 one of these six. \textbf{All hook manipulation is \emph{global}.}
213
214 \paragraph{Pre hooks.}
215 \DescribeMacro{\PushPreHook}
216 \DescribeMacro{\PopPreHook}
217 Additional tokens \meta{balanced text} are prepended to the pre hook
218 \meta{hook} using \cs{PushPreHook}\arg{\meta{hook}}\arg{\meta{balanced
219 text}}. The most recently pushed tokens can be popped off using
220 \cs{PopPreHook}\arg{\meta{hook}}.
221
222 \paragraph{Post hooks.}
223 \DescribeMacro{\PushPostHook}
224 \DescribeMacro{\PopPostHook}
225 Additional tokens \meta{balanced text} are appended to the post hook
226 \meta{hook} using
227 \cs{PushPostHook}\arg{\meta{hook}}\arg{\meta{balanced text}}. The most
228 recently pushed tokens can be popped off using
229 \cs{PopPostHook}\arg{\meta{hook}}.
230
231 \paragraph{Saving, restoring, and clearing hooks.}
232 \DescribeMacro{\SavePreHook}
233 \DescribeMacro{\SavePostHook}
234 \DescribeMacro{\RestorePreHook}
235 \DescribeMacro{\RestorePostHook}
236 \DescribeMacro{\ClearPreHook}
237 \DescribeMacro{\ClearPostHook}
238 Each of the 12 pre and post hooks can be saved to a macro, restored
239 from a macro, or cleared independently. To save the pre hook
240 \meta{hook} to the macro \cs{cs}, use
241 \cs{SavePreHook}\arg{\meta{hook}}\arg{\cs{cs}}. Restoring is
242 accomplished by \cs{RestorePreHook}\arg{\meta{hook}}\arg{\cs{cs}}. To
243 clear all of the tokens in a pre hook use
244 \cs{ClearPreHook}\arg{\meta{hook}}. The \cs{SavePostHook},
245 \cs{RestorePostHook}, and \cs{ClearPostHook} are analogous.
246
247 \section{Example}
248 As a nontrivial example of where this package can be used, consider
249 the following example.
250 \begin{lstlisting}
251 \documentclass{article}
252 \usepackage{everyhook}
253 \usepackage{lipsum}
254
255 \begin{document}
256 \setlength{\parindent}{0pt}
257 \PushPreHook{par}{\llap{\textbullet\enskip}\null}
258 \paragraph{Lorem ipsum.}
259 \lipsum[1-4]
260 \PopPreHook{par}
261 \end{document}
262 \end{lstlisting}
263 This code will cause each paragraph of the \emph{lorem ipsum} text to
264 have no indentation and instead to place a bullet in the margin. See
265 Figure~\ref{fig:example}. If \cs{everypar} were used instead, the
266 \cs{paragraph} would replace the command to create the bullet with
267 those needed to typeset the paragraph title.
268
269 \begin{figure}[p]
270 \centering
271 \fbox{\makebox[.975\textwidth][c]{\parbox{\dimexpr.975\textwidth-1in\relax}{
272 \vspace*{\dimexpr .5in-3.25ex}
273 \PushPreHook{par}{\llap{\textbullet\enskip}\null}
274 \paragraph{Lorem ipsum.}
275 \lipsum[1-4]
276 \PopPreHook{par}
277
278 \vskip.5in
279 }}}
280 \caption{Example output.}
281 \label{fig:example}
282 \end{figure}
283
284 Note that this package is not a panacea. We had to add a \cs{null} to
285 the |par| hook because \cs{paragraph} uses \cs{lastbox} to remove the
286 indentation box. Without the \cs{null} it ends up removing the box
287 constructed by \cs{llap} instead.
288
289 Using the post |par| hook solves the \cs{lastbox} problem, but then
290 the bullet is placed to the right of the \cs{paragraph} title.
291
292 Perhaps a better way to solve this problem is to remove the
293 indentation box first, insert the bullet, and then place the box
294 after. In this way, the bullet is always to the left of the
295 paragraph indentation.
296 \begin{lstlisting}
297 \PushPreHook{par}{{\setbox0=\lastbox
298 \llap{\textbullet\enskip}\box0}}
299 \end{lstlisting}
300
301 \section{Potential pitfalls}
302 As noted in the previous section, it can be tricky to use the |par|
303 hook correctly. This section contains an (almost certainly) incomplete
304 list of pitfalls to watch out for when using \textsf{\jobname}.
305 \begin{enumerate}
306 \item When using the |par| hooks, be aware that TeX will insert a box
307 with the width of \cs{parindent} before the tokens in the pre hook.
308 One way to handle this is to propogate the box to the right.
309 \item It is probably not a good idea to use the |hbox|, |vbox|, and
310 |par| hooks at any place where TeX's output routine is likely to run.
311 The |excludeor| option \emph{should} help with this, but it might
312 cause problems with other packages that also modify the output
313 routine.
314 \item \LaTeX's kernel takes control of the \cs{everymath} and
315 \cs{everydisplay} token parameters to make its own adjustments in much
316 the same way this package does. The \textsf{trace} package uses the
317 kernel's private macros to insert its own hooks. It is probably best
318 to only use the post |math| and |display| hooks to ensure that the
319 kernel has done what it needs to do before you start typesetting stuff
320 in math mode.
321 \item When using the |hbox| and |vbox| hooks, any hbox or vbox that
322 appears in a \cs{setbox} will have the \cs{afterassignment} token
323 inserted \emph{before} the hooks. This is no different from TeX's
324 normal behavior with \cs{afterassignment} and
325 \cs{everyhbox}/\cs{everyvbox}, but can be surprising.
326 \item I'm sure there are others.
327 \end{enumerate}
328
329 \StopEventually{
330 \typeout{**************************************************}
331 \typeout{*}
332 \typeout{* To finish the installation, you have to move the}
333 \typeout{* following file into a directory searched by TeX:}
334 \typeout{*}
335 \typeout{* \space\space \jobname.sty}
336 \typeout{*}
337 \typeout{* Documentation is in \jobname.\ifpdf pdf\else dvi\fi.}
338 \typeout{*}
339 \typeout{* Happy TeXing!}
340 \typeout{**************************************************}
341 \end{document}
342 }
343
344 \clearpage
345 \DocInput{\jobname.dtx}
346 \clearpage
347 \phantomsection
348 \addcontentsline{toc}{section}{Change History}%
349 \PrintChanges
350 \phantomsection
351 \addcontentsline{toc}{section}{Index}%
352 \PrintIndex
353 \Finale
354 %</batchfile>
355 % \fi
356 % \DoNotIndex{\csdef,\cslet,\csname,\csuse,\def,\endcsname,\endinput,
357 % \every,\expandafter,\gdef,\global,\ifcsdef,\ifcsempty,\ifdefequal,
358 % \letcs,\newrobustcmd,\newtoks,\PackageError,\protect,\RequirePackage,
359 % \space,\the,\undef}
360 %
361 % \section{Implementation}
362 % The package begins with the usual package identification and then it
363 % declares the one option |excludeor| and finally it loads the
364 % \textsf{etoolbox} package. This package is not strictly necessary,
365 % but it does simplify some stuff and provides handy macros for
366 % dealing with control sequence names.
367 %
368 % \changes{v1.0}{2010/09/26}{Initial version}
369 % \changes{v1.1}{2011/02/03}{Add excludeor}
370 % \changes{v1.2}{2014/11/26}{Let everyX be redefined}
371 % \begin{macrocode}
372 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
373 \RequirePackage{svn-prov}
374 \ProvidesPackageSVN
375 {$Id: everyhook.dtx 12 2014-11-26 15:34:56Z steve $}
376 [v1.2 \revinfo\ Hooks for low level TeX everyX primitives.]
377 \DeclareOption{excludeor}{%
378 \AtBeginDocument{%
379 \output\expandafter{%
380 \expandafter\eh@saveclearallhooks
381 \the\output
382 \eh@restoreallhooks
383 }%
384 }%
385 }
386 \ProcessOptions\relax
387 \RequirePackage{etoolbox}
388 % \end{macrocode}
389 %
390 % \begin{macro}{\eh@definehook}
391 % This performs all of the setup work for each hook. First, it takes
392 % control of \TeX's token parameter given in the second argument. Then
393 % it shadows the name of the primitive with a normal token register (and
394 % copies the current definition). The pre and post hooks are defined
395 % to be initially empty.
396 % \begin{macrocode}
397 \def\eh@definehook#1#2{%
398 \cslet{eh@every#1}#2%
399 \newtoks#2%
400 \cslet{eh@private#1}#2%
401 #2\csuse{eh@every#1}%
402 \csdef{eh@pre#1}{}%
403 \csdef{eh@post#1}{}%
404 % \end{macrocode}
405 % This is slightly tricky to get right. Basically, we want to set the
406 % \cs{everyfoo} primitive which we have saved as \cs{eh@everyfoo}
407 % like
408 %
409 % \indent\lstinline!\eh@everyfoo={\eh@prefoo\the\expandafter\everyfoo\eh@postfoo}!.
410 %
411 % The reason for the \cs{expandafter} is to make sure it is expanded
412 % before the the token register \cs{everyfoo} is expanded. Thus if the
413 % post hook is empty, then code in \cs{everyfoo} sees no additional
414 % tokens, in case that is important.
415 %
416 % Unfortunately, some code wants to redefine \cs{everyfoo} itself in
417 % order to prevent \emph{other} code that uses \cs{everyfoo} from
418 % actually setting anything. To deal with that, we use the private
419 % token list
420 %
421 % \indent\lstinline!\eh@everyfoo{\eh@prefoo\the\expandafter\eh@privatefoo\eh@postfoo}!
422 % \begin{macrocode}
423 \csuse{eh@every#1}\expandafter{\csname eh@pre#1\expandafter\endcsname
424 \expandafter\the\csname eh@private#1\expandafter\endcsname
425 \csname eh@post#1\endcsname}%
426 }
427 % \end{macrocode}
428 % \end{macro}
429 % \begin{macro}{\everypar}
430 % Define the hooks for the |par| hook.
431 % \begin{macrocode}
432 \eh@definehook{par}\everypar
433 % \end{macrocode}
434 % \end{macro}
435 % \begin{macro}{\frozen@everymath}
436 % \begin{macro}{\frozen@everydisplay}
437 % Define the |math| and |display| hooks. Since the \LaTeX\ kernel has
438 % already saved \cs{everymath} and \cs{everydisplay} into the frozen
439 % macros, we take control by redefining the frozen ones instead.
440 % \begin{macrocode}
441 \eh@definehook{math}\frozen@everymath
442 \eh@definehook{display}\frozen@everydisplay
443 % \end{macrocode}
444 % \end{macro}
445 % \end{macro}
446 % \begin{macro}{\everyhbox}
447 % \begin{macro}{\everyvbox}
448 % \begin{macro}{\everycr}
449 % Define the |hbox|, |vbox|, and |cr| hooks and free up some used
450 % memory.
451 % \begin{macrocode}
452 \eh@definehook{hbox}\everyhbox
453 \eh@definehook{vbox}\everyvbox
454 \eh@definehook{cr}\everycr
455 \undef\eh@definehook
456 % \end{macrocode}
457 % \end{macro}
458 % \end{macro}
459 % \end{macro}
460 %
461 % \begin{macro}{\eh@hookseparator}
462 % An separator used to separate tokens in each hook.
463 % \begin{macrocode}
464 \def\eh@hookseparator{}
465 % \end{macrocode}
466 % \end{macro}
467 % \begin{macro}{\eh@checkhook}
468 % Check that the hook is one of the six.
469 % \begin{macrocode}
470 \def\eh@checkhook#1#2{%
471 \ifcsdef{eh@every#1}{}{\PackageError{everyhook}{Argument #1 to
472 \protect#2\space is invalid}{There is no hook for
473 \protect\every#1.}}%
474 }
475 % \end{macrocode}
476 % \end{macro}
477 % \begin{macro}{\eh@checkhooknotempty}
478 % Check that the hook is both defined and not empty so that we can
479 % pop.
480 % \begin{macrocode}
481 \def\eh@checkhooknotempty#1#2#3{%
482 \eh@checkhook{#2}#3%
483 \ifcsempty{eh@#1#2}{\PackageError{everyhook}{The #1 hook for
484 \protect\every#2\space is empty}{I have seen too many
485 \protect#3{#2}s.}{}}%
486 }
487 % \end{macrocode}
488 % \end{macro}
489 % \begin{macro}{\PushPreHook}
490 % Prepend tokens to the pre hook, separated via the separator.
491 % \begin{macrocode}
492 \newrobustcmd\PushPreHook[2]{%
493 \eh@checkhook{#1}\PushPreHook
494 \def\eh@tempi{#2}%
495 \letcs\eh@tempii{eh@pre#1}%
496 \expandafter\gdef\csname eh@pre#1\expandafter\expandafter
497 \expandafter\endcsname\expandafter\expandafter
498 \expandafter{\expandafter\eh@tempi\expandafter
499 \eh@hookseparator\eh@tempii}%
500 \undef\eh@tempi
501 \undef\eh@tempii
502 }
503 % \end{macrocode}
504 % \end{macro}
505 % \begin{macro}{\PopPreHook}
506 % \begin{macro}{\eh@popprehook}
507 % Check that the hook is not empty, and then pop off the left tokens
508 % and separator. We can use delimited parameters to strip off the
509 % first set of tokens.
510 % \begin{macrocode}
511 \newrobustcmd\PopPreHook[1]{%
512 \eh@checkhooknotempty{pre}{#1}\PopPreHook
513 \expandafter\eh@popprehook\csname eh@pre#1\expandafter
514 \expandafter\expandafter\endcsname
515 \csname eh@pre#1\endcsname\eh@hookend
516 }
517 \def\eh@popprehook#1#2\eh@hookseparator#3\eh@hookend{\gdef#1{#3}}
518 % \end{macrocode}
519 % \end{macro}
520 % \end{macro}
521 % \begin{macro}{\PushPostHook}
522 % Append a separator and tokens to the post hook.
523 % \begin{macrocode}
524 \newrobustcmd\PushPostHook[2]{%
525 \eh@checkhook{#1}\PushPostHook
526 \letcs\eh@tempi{eh@post#1}%
527 \expandafter\gdef\csname eh@post#1\expandafter\endcsname
528 \expandafter{\eh@tempi\eh@hookseparator#2}%
529 \undef\eh@tempi
530 }
531 % \end{macrocode}
532 % \end{macro}
533 % \begin{macro}{\PopPostHook}
534 % \begin{macro}{\eh@popposthook}
535 % \begin{macro}{\eh@sentinel}
536 % Check that the post hook is not empty. Then, iterate over the tokens
537 % in the list until we reach the end and strip that off.
538 % \begin{macrocode}
539 \newrobustcmd\PopPostHook[1]{%
540 \eh@checkhooknotempty{post}{#1}\PopPostHook
541 \letcs\eh@tempi{eh@post#1}%
542 \expandafter\eh@popposthook\csname eh@post#1\expandafter
543 \endcsname\expandafter{\expandafter}\eh@tempi
544 \eh@hookend\eh@hookseparator\eh@sentinel\eh@hookend
545 \undef\eh@tempi
546 }
547 \def\eh@popposthook#1#2\eh@hookseparator#3\eh@hookseparator#4\eh@hookend{%
548 \def\eh@tempi{#4}%
549 \ifdefequal\eh@sentinel\eh@tempi%
550 {\gdef#1{#2}\undef\eh@tempi}%
551 {\eh@popposthook#1{#2\eh@hookseparator#3}\eh@hookseparator#4\eh@hookend}%
552 }
553 \def\eh@sentinel{\eh@sentinel}
554 % \end{macrocode}
555 % \end{macro}
556 % \end{macro}
557 % \end{macro}
558 % \begin{macro}{\eh@clearhook}
559 % Internal hook reset.
560 % \begin{macrocode}
561 \def\eh@clearhook#1{%
562 \global\csdef{eh@#1}{}%
563 }
564 % \end{macrocode}
565 % \end{macro}
566 % \begin{macro}{\ClearPreHook}
567 % \begin{macro}{\ClearPostHook}
568 % Reset the pre/post hook to empty.
569 % \begin{macrocode}
570 \newrobustcmd\ClearPreHook[1]{%
571 \eh@checkhook{#1}\ClearPreHook
572 \eh@clearhook{pre#1}%
573 }
574 \newrobustcmd\ClearPostHook[1]{%
575 \eh@checkhook{#1}\ClearPostHook
576 \eh@clearhook{post#1}%
577 }
578 % \end{macrocode}
579 % \end{macro}
580 % \end{macro}
581 % \begin{macro}{\eh@savehook}
582 % \begin{macro}{\eh@restorehook}
583 % Internal macros to \cs{let} the hook to the supplied control
584 % sequence to save. Perform the \cs{let} in the other direction to
585 % restore.
586 % \begin{macrocode}
587 \def\eh@savehook#1#2{%
588 \letcs#2{eh@#1}%
589 }
590 \def\eh@restorehook#1#2{%
591 \global\cslet{eh@#1}#2%
592 }
593 % \end{macrocode}
594 % \end{macro}
595 % \end{macro}
596 % \begin{macro}{\SavePreHook}
597 % \begin{macro}{\SavePostHook}
598 % \begin{macro}{\RestorePreHook}
599 % \begin{macro}{\RestorePostHook}
600 % User macros to save and restore hooks.
601 % \begin{macrocode}
602 \newrobustcmd\SavePreHook[2]{%
603 \eh@checkhook{#1}\SavePreHook
604 \eh@savehook{pre#1}#2%
605 }
606 \newrobustcmd\SavePostHook[2]{%
607 \eh@checkhook{#1}\SavePostHook
608 \eh@savehook{post#1}#2%
609 }
610 \newrobustcmd\RestorePreHook[2]{%
611 \eh@checkhook{#1}\RestorePreHook
612 \eh@restorehook{pre#1}#2%
613 }
614 \newrobustcmd\RestorePostHook[2]{%
615 \eh@checkhook{#1}\RestorePostHook
616 \eh@restorehook{post#1}#2%
617 }
618 % \end{macrocode}
619 % \end{macro}
620 % \end{macro}
621 % \end{macro}
622 % \end{macro}
623 % \begin{macro}{\eh@saveclearallhooks}
624 % \begin{macro}{\eh@restoreallhooks}
625 % Internal macros to save and clear (resp.\ restore) all hooks at the
626 % start (resp.\ end) of the output routine.
627 % \begin{macrocode}
628 \def\eh@saveclearallhooks{%
629 \global\eh@savehook{prepar}\eh@or@prepar
630 \global\eh@savehook{postpar}\eh@or@postpar
631 \global\eh@savehook{premath}\eh@or@premath
632 \global\eh@savehook{postmath}\eh@or@postmath
633 \global\eh@savehook{predisplay}\eh@or@predisplay
634 \global\eh@savehook{postdisplay}\eh@or@postdisplay
635 \global\eh@savehook{prehbox}\eh@or@prehbox
636 \global\eh@savehook{posthbox}\eh@or@posthbox
637 \global\eh@savehook{prevbox}\eh@or@prevbox
638 \global\eh@savehook{postvbox}\eh@or@postvbox
639 \global\eh@savehook{precr}\eh@or@precr
640 \global\eh@savehook{postcr}\eh@or@postcr
641 \eh@clearhook{prepar}%
642 \eh@clearhook{postpar}%
643 \eh@clearhook{premath}%
644 \eh@clearhook{postmath}%
645 \eh@clearhook{predisplay}%
646 \eh@clearhook{postdisplay}%
647 \eh@clearhook{prehbox}%
648 \eh@clearhook{posthbox}%
649 \eh@clearhook{prevbox}%
650 \eh@clearhook{postvbox}%
651 \eh@clearhook{precr}%
652 \eh@clearhook{postcr}%
653 }
654 \def\eh@restoreallhooks{%
655 \eh@restorehook{prepar}\eh@or@prepar
656 \eh@restorehook{postpar}\eh@or@postpar
657 \eh@restorehook{premath}\eh@or@premath
658 \eh@restorehook{postmath}\eh@or@postmath
659 \eh@restorehook{predisplay}\eh@or@predisplay
660 \eh@restorehook{postdisplay}\eh@or@postdisplay
661 \eh@restorehook{prehbox}\eh@or@prehbox
662 \eh@restorehook{posthbox}\eh@or@posthbox
663 \eh@restorehook{prevbox}\eh@or@prevbox
664 \eh@restorehook{postvbox}\eh@or@postvbox
665 \eh@restorehook{precr}\eh@or@precr
666 \eh@restorehook{postcr}\eh@or@postcr
667 }
668 \endinput
669 % \end{macrocode}
670 % \end{macro}
671 % \end{macro}
672 \endinput