Por que o tikz reclama quando uso \NewDocumentEnvironment?

Por que o tikz reclama quando uso \NewDocumentEnvironment?

Este é o código:

\documentclass{article}
\usepackage{tikz}
\NewDocumentEnvironment{foo}{b}{hello}{}
\AddToHook{env/foo/before}{\obeylines\obeyspaces}
\begin{document}
\begin{tikzpicture}
\node (v) {hi};
\end{tikzpicture}
\begin{foo}
first
second
\end{foo}
\begin{tikzpicture}
\node (v) {hi};
\end{tikzpicture}
\end{document}

Estou recebendo esta mensagem estranha:

! Package tikz Error: A node must have a (possibly empty) label text.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.14 \node
           (v) {hi};

O que está errado?

Responder1

Como notadopelo comentário de @David Carlisle, a confusão do seu código de gato persistirá depois \end{foo}... texdoc lthooksdiz

insira a descrição da imagem aqui

Então você provavelmente deseja usar begino hook:

\documentclass{article}
\usepackage{tikz}
\NewDocumentEnvironment{foo}{b}{hello}{}
\AddToHook{env/foo/begin}{\obeylines\obeyspaces}
\begin{document}
\begin{tikzpicture}
\node (v) {hi};
\end{tikzpicture}
\begin{foo}
first
second
\end{foo}
\begin{tikzpicture}
\node (v) {hi};
\end{tikzpicture}
\end{document}

insira a descrição da imagem aqui

informação relacionada