I'd like to make a new environment which would store its content in a file, so that I can read that file at another part of the document. More specifically, I want to have an environment {proof} such that its contents can be automatically moved to the appendix.
So far, I tried the following code:
\newwrite\pfs
\openout\pfs=tmp
\newenvironment{proof}{\immediate\write\pfs\bgroup}{\egroup}
\begin{proof}It's obvious.\end{proof}
However it doesn't seem to work: I get the error message File ended while scanning the text of \write. Can anybody help fix this macro?
Edit: I managed to get this macro work to work as a TeX macro:
\newwrite\pfs
\immediate\openout\pfs=tmp
\long\def\writetofile#1{\immediate\write\pfs{#1}}
\long\def\proof#1{\writetofile{\noexpand\par\noexpand\textbf{Proof:} #1}}
\proof{It's obvious.} Theorem: $0.999\ldots=1$
\immediate\closeout\pfs
\input tmp
However, I'd much prefer this macro to be converted into an environment, since most proofs will be very long...