
Dies ist der Code:
\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}
Ich erhalte diese seltsame Meldung:
! 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};
Was ist falsch?
Antwort1
Wie bemerktvon @David Carlisle's Kommentar, Ihr Catcode-Durcheinander wird auch nach \end{foo}
... bestehen bleiben, texdoc lthooks
sagt
Sie möchten also wahrscheinlich einen Hook verwenden begin
:
\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}