I think that the recently introduced hook interface is an exciting extension of the interactions with LaTeX internals.
They motivated me to resume my efforts to convince LaTeX to process page contents dependent on page number.
Previously, I messed around with atbegshi, everyshi etc., with no success.
I had hopes that an official \AddToHook{shipout/before}{...} might make things like this easier, but to no avail so far.
\documentclass[12pt,a6paper]{scrartcl}
\usepackage{kantlipsum}
\usepackage{xcolor}
\AddToHook{shipout/before}{\color{red!\thepage!blue}Local color scope}
\begin{document}
\kant[1-60]
\end{document}
Above MWE demonstrates that pagenumber-dependent formatting is straightforward within the scope of the \AddToHook itself (the “Local color scope” text slowly changes colour from blue to red throughout this document). But the main page content is not affected by this, and stays black all the time.
I'm out of ideas how to expand the action of commands within hooks to the whole document.
\AddToHook{shipout/before}{\pdfliteral page{1 0 0 rg} Local color scope}) it would work. With xcolor it fails, because the color drivers do what you do: they inject color commands (from the color stack) at the begin of the page but after your code and so they overwrite your color. – Ulrike Fischer Jul 09 '22 at 22:52