I'd like to have a command that can write multiple lines to a .log file; in particular, I wonder if there is a way to avoid using \string to escape the \ character.
I've pasted a MWE below- any help would be greatly appreciated.
Chris
Code: Select all
\documentclass[10pt,letter]{report}
% set up the answer file
\newwrite\answerfile
\immediate\openout\answerfile solutions.log\relax
% write answer
\newcommand{\writesolution}[1]{
\immediate\write\answerfile{#1^^J}
}
\begin{document}
\section*{Questions}
Here is a question.
\writesolution{Here is an answer.}
I'd like to write tables (and other things) to solutions.log without using $\backslash$string.
\writesolution{
\string\begin{tabular}{c|c}
$x$ & $y$ \string\\
$1$ & $2$
\string\end{tabular}
}
% close the solutions file
\immediate\closeout\answerfile
\section*{Answers}
\IfFileExists{solutions.log}{\input{solutions.log}}{}
\end{document}