\NewDocumentEnvironment를 사용할 때 tikz가 불평하는 이유는 무엇입니까?

\NewDocumentEnvironment를 사용할 때 tikz가 불평하는 이유는 무엇입니까?

코드는 다음과 같습니다.

\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}

다음과 같은 이상한 메시지가 나타납니다.

! 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};

뭐가 문제 야?

답변1

주목한 바와 같이@David Carlisle의 코멘트, 귀하의 catcode 뒤죽박죽은 다음 후에도 지속됩니다 \end{foo}... texdoc lthooks말한다

여기에 이미지 설명을 입력하세요

따라서 아마도 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}

여기에 이미지 설명을 입력하세요

관련 정보