# Problem with quotes and AtEndDocument

Consider the following code:

\documentclass{article}

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

\usepackage{etoolbox}
\usepackage{environ}

\newtheorem{pr}{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}


If I comment out the "Solution" part, it works, else I get the following error message:

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.


That's the same problem you get everytime if you don't load the babel library.

How can I fix this? Is there another way to set the label in the pic command than using the quotes library?

If I use the option ngerman of the article class everything works, but I want to use the babel package.

The problem is that inside a tikzpicture environment the character " is not a shorthand marker any more, but when this is absorbed in the solutions it still is.
\AtEndDocument{\clearpage\begin{center}\Large Solutions \end{center}