Alles, wo @ in einem Befehlsnamen etc. vorkommt, muß mit \makeatletter ... \makeatother geklammert werden, oder aber in eine .sty-Datei verfrachtet werden.
Probiere also mal:
Code:
\makeatletter
% Datei zum Schreiben oeffnen:
\newwrite\ex@file
\immediate\openout\ex@file=\jobname.sol
% Wird bei \begin{solution} ausgefuehrt:
\newcommand*{\solution}{\@bsphack
\let\do\@makeother\dospecials
\catcode`\^^M\active
\def\verbatim@processline{%
\immediate\write\ex@file{\the\verbatim@line}}%
\immediate\write\ex@file{%
\string\begin{ex@solution}{\theexercise}}%
\verbatim@start}
% Wird bei \end{solution} ausgefuehrt:
\def\endsolution{%
\immediate\write\ex@file{%
\string\end{ex@solution}}\@esphack}
\makeatother
Liebe Grüße,
Axel
Lesezeichen