This MWE works perfectly when the I comment out equation in the teacher environment. With that equation in place I get this error:
(C:\Users\Ethan.Bolker\AppData\Roaming\MiKTeX\2.9\tex\latex\trimspaces\trimspac
es.sty))
Output from handle answersout going to answersout.tex
! Missing \endcsname inserted.
<to be read again>
\csname\endcsname
l.30 \end{teacher}
The code:
\documentclass{article}
\usepackage{answers}
\usepackage{amsmath}
\usepackage{environ}
\newcommand{\answersout}{answersout}
\NewEnviron{teacher}{%
\Writetofile{\answersout}{\BODY }
}
\begin{document}
\Opensolutionfile{\answersout}
An equation in the master file:
%
\begin{equation}
2+2 = 4
\end{equation}
\begin{teacher}
In answersout: expand a macro: \LaTeX.
Try an equation:
% comment out the next three lines and the document compiles
\begin{equation}
2+2 = 4
\end{equation}
\end{teacher}
\Closesolutionfile{\answersout}
\input{\answersout}
\end{document}
Some history. A previous problem with the answers package led me to this question:
Incomplete \iffalse error using answers package
In fact that was the first error I saw when I encountered this problem. That error message was replaced by the one above when I made my example minimal.
