add tag
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}
```

![document2-1.png](/image?hash=0b2e096bc51f907ff31096d5dda7fa0ff6425db2482243aa0b9f32e55a01b504)
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.

![prawf-1-1.png](/image?hash=ca6e3ce712ae432d4384407306535185e66ea1e69ed572b76722b1e1c57aa5d5)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.