Expanding on the LaTeX3 side of things, I guess this is a place where I'd expect to provide a different input syntax to LaTeX2e. As the question points out, the current implementation uses the token register syntax
\everyfoo{tokens}
which overwrites whatever was in \everyfoo
unless you do
\everyfoo\expandafter{\the\everyfoo tokens}
which is not exactly obvious. So a better approach would be something like the current \AtBeginDocument
, something like:
\AtEveryFoo{tokens}
where this is additive. The implementation of such an approach would be easy enough.
Proof of concept A short piece of concept code that might be an approach for LaTeX3. The idea here is that the TeX primitive is only used by the kernel, with two separate hooks provided. First, settings that the kernel needs are applied, then ones from programmers and finally those from the user. In the demo I've only considered the \everymath
concept. I've provided an interface for the user to both add to and clear the list, plus an alias to the LaTeX2e \everymath
interface. (In a pure LaTeX3 approach I'd drop this TeX-like interface, or at least mark it depreciated.)
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\makeatletter
\tl_new:N \l_every_math_programmers_tl
\tl_new:N \l_every_math_users_tl
\toks_set:Nn \tex_everymath:D {
\check@mathfonts % LaTeX2e's requirement
\tl_use:N \l_every_math_programmers_tl
\tl_use:N \l_every_math_users_tl
}
\NewDocumentCommand \InsertForEvery { m +m } {
\tl_put_right:cn { l_every_ #1 _users_tl } {#2}
}
\NewDocumentCommand \ClearForEvery { m } {
\tl_clear:c { l_every_ #1 _users_tl }
}
\RenewDocumentCommand \everymath { +m } { \InsertForEvery { math } {#1} }
\ExplSyntaxOff
\begin{document}
\InsertForEvery{math}{\mathrm{Look!\,}}
\( y = mx + c \)
\ClearForEvery{math}
\( y = mx + c \)
\end{document}
I should add that a real implementation would need error-checking and so on.
\everycr
, &c, "token list parameters", to contrast them with \toks0..., which he calls "token list registers". – Charles Stewart Aug 19 '10 at 20:14\toks0
... and not\everycr
, &c. – Charles Stewart Aug 19 '10 at 20:38\everycr
works like any other token register, for example the\everycr{tokens}
business. Perhaps this is because I'm a TeX programmer, and so used to having to think in terms of toks and macros as the two ways to store tokens in TeX. – Joseph Wright♦ Aug 19 '10 at 20:40