samcarter
I would like to add content to a hook throughout my document. Just on one occasion, I would like to ignore the content of the hook. Is there any possibility to skip the hook once?
For example, I would like to add a background to all bears except the second bear:
```
\documentclass{standalone}
\usepackage{tikzlings}
\AddToHook{tikzlings/background}{
\fill[red] (-1,0) rectangle (1,2);
}
\begin{document}
\tikz{\bear}
\begingroup
\RemoveFromHook{tikzlings/background}
\tikz{\bear}
\endgroup
\tikz{\bear}
\end{document}
```

Top Answer
cfr
Unfortunately, there is no `\RemoveFromHookNext`, but we can provide one which will permit removing labelled code chunks from the next hook. This will not work with unlabelled chunks since the format refuses to allow one to interfere with `top-level` chunks. It would, however, work with unlabelled chunk in a class or package, since only document-level code gets the `top-level` label.
```
\documentclass{standalone}
\ExplSyntaxOn
\NewDocumentCommand\RemoveFromHookNext { m O {.} }{
\hook_gset_rule:nnnn {#1} {samcarter-null} {voids} {#2}
\cs_if_free:cT {samcarter__#1_null:} {
\cs_new:cpn {samcarter__#1_null:} {}
\hook_gput_code:nnn {#1} {samcarter-null} {}
}
\hook_gput_next_code:nn {#1} {
\hook_gset_rule:nnnn {#1} {samcarter-null} {unrelated} {#2}
}
}
\ExplSyntaxOff
\usepackage{tikzlings}
\AddToHook{tikzlings/background}[red]{
\fill[red] (-1,0) rectangle (1,2);
}
\begin{document}
\tikz{\bear}
\RemoveFromHookNext {tikzlings/background}[red]
\tikz{\bear}
\tikz{\bear}
\end{document}
```
This works because the `voids` relation is non-destructive i.e. unlike `\RemoveFromHook`, it leaves the voided code chunk in place.
