
코드는 다음과 같습니다.
\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}