引号和 AtEndDocument 的问题

引号和 AtEndDocument 的问题

考虑以下代码:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{babel,quotes,angles}

\usepackage{etoolbox}
\usepackage{environ}


\newtheorem{pr}{Problem}
\newtheorem{solinn}{ad Problem}

\newtoks\prsoltoks

\NewEnviron{Solution}{%
  \global\prsoltoks=\expandafter{\the\prsoltoks\begin{solinn}}%
    \global\prsoltoks=\expandafter{\the\expandafter\prsoltoks\BODY\end{solinn}}%
}


\usepackage{multicol}
\AtEndDocument{\clearpage\begin{center}\Large Solutions \end{center}
  \setcounter{pr}{0}
  \begin{multicols}{2}
    \the\prsoltoks
  \end{multicols}
}

\begin{document}

\begin{pr}~

  \begin{tikzpicture}
  \coordinate (O) at (0,0);%
  \coordinate (P) at (0,2);%
  \coordinate (Q) at (2,2);%

  \draw (O) -- (P);%
  \draw (O) -- (Q);%

  \pic["$\alpha$",draw,angle radius=1.5cm] {angle=Q--O--P};%"
\end{tikzpicture}
\end{pr}

\begin{Solution}~
\begin{tikzpicture}
  \coordinate (O) at (0,0);%
  \coordinate (P) at (0,2);%
  \coordinate (Q) at (2,2);%

  \draw (O) -- (P);%
  \draw (O) -- (Q);%

  \pic["$\alpha$",draw,angle radius=1.5cm] {angle=Q--O--P};%"
\end{tikzpicture}
\end{Solution}

\begin{tikzpicture}
  \coordinate (O) at (0,0);%
  \coordinate (P) at (0,2);%
  \coordinate (Q) at (2,2);%

  \draw (O) -- (P);%
  \draw (O) -- (Q);%

  \pic["$\alpha$",draw,angle radius=1.5cm] {angle=Q--O--P};%"
\end{tikzpicture}

\end{document}

如果我注释掉“解决方案”部分,它就会起作用,否则我会收到以下错误消息:

ERROR: Argument of \language@active@arg" has an extra }.

--- TeX said ---
<inserted text> 
                \par 
l.72 \end{document}

--- HELP ---
From the .log file...

I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.

如果您不加载 babel 库,每次都会遇到同样的问题。

我该如何解决这个问题?除了使用 quotes 库之外,还有其他方法可以在 pic 命令中设置标签吗?

如果我使用文章类的选项,ngerman一切都可以正常工作,但我想使用 babel 包。

答案1

问题在于,在tikzpicture环境中,字符"不再是一个简写标记,但当它被吸收到解决方案中时,它仍然是一个简写标记。

解决方法:

\AtEndDocument{\clearpage\begin{center}\Large Solutions \end{center}
  \setcounter{pr}{0}
  \begin{multicols}{2}
    \scantokens\expandafter{\the\prsoltoks}%
  \end{multicols}

这使得 TeX 将标记视为从文件输入,因此类别代码不再固定。

相关内容