Subverting a token register

A common requirement is to “subvert” a token register that other macros may use. The requirement arises when you want to add something to a system token register (\output or \every*), but know that other macros use the token register, too. (A common requirement is to work on \everypar, but LaTeX changes \everypar at every touch and turn.)

The following technique, due to David Kastrup, does what you need, and allows an independent package to play the exact same game: <!– {% raw %} –

>

snippet.latex
\let\mypkg@@everypar\everypar
\newtoks\mypkg@everypar
\mypkg@everypar\expandafter{\the\everypar}
\mypkg@@everypar{\mypkgs@ownstuff\the\mypkg@everypar}
\def\mypkgs@ownstuff{%
<stuff to do at the start of the token register>%
}
\let\everypar\mypkg@everypar

<

!– {% endraw %} –

>

A

s you can see, the package (mypkg)

and away we go.

The form \mypkg@... is (sort of) blessed for LaTeX package internal names, which is why this example uses macros of that form.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

Creative Commons Lizenzvertrag Edit this page Old revisions Sitemap Backlinks RSS feed Impressum Flattr this