I would like to take the contents of a box generated with \begin{lrbox} ... \end{lrbox} and write it to a file.
The use case is a question and answer environment, where the answer should be collected and showed at different location in the document. In addition I would like to show the answer next to the question. Therefore I pack the question into a box, and then I assume that the contents of this box can both be used inside the environment and for storing the data in an external file. But the last part is the reason for this question.
The approach I have used this far is the newfile package and the code below. The problem is that what is written to test3.comment is the following
\unhbox \voidb@x \copy \myboxquestion \relax Almost working code
\documentclass{article} \usepackage{newfile} \newoutputstream{comment} \openoutputfile{\jobname.comment}{comment} \newsavebox{\myboxquestion} \newenvironment{question}{% \begin{lrbox}{\myboxquestion}\begin{minipage}{\linewidth}}{% \end{minipage}\end{lrbox} \par\usebox{\myboxquestion} % What to do here? \addtostream{comment}{\usebox{\myboxquestion}}} \setlength{\parindent}{0.0cm} \begin{document} Testing \begin{question} What is 3 + 4 \end{question} \section{Collected} \input{\jobname.comment} \end{document} 
