# Toggle visibility of solutions in LaTeX output for exams

So I have my own layout for my exams based on scrartcl and to prevent anomalies during some changes I want to have only one file per exam which holds both questions/excercises and solutions. Yet I would like to be able to set a variable etc. whichever method might be more convenient so that I can chose for one compilation whether solutions should be visible or not. What is the suggested approach for this?

-

Same idea, with newcommand:

\documentclass{scrartcl}

\emph{Answer}: % comment out these two lines
#1            % to make answer invisible
}
% or comment in

\begin{document}
The question goes here\\
\end{document}


For a more sophisticated solution (writing the answers to another document, or appending them), you can \usepackage{answers}.

-
This doesn't work for me - probably because I have an enumerate environment in there. I am getting the error File ended while scanning use of \@argdef [...] suspect you have forgotten a '}'. –  Christian Ivicevic Feb 12 '13 at 17:41
I edited my answer to remove an extra { . Shame on me for not compiling first to test. Sorry. –  Ethan Bolker Feb 12 '13 at 17:56
+1. Shame I didn't notice it either - it works as expected! –  Christian Ivicevic Feb 12 '13 at 17:57

You could simply use something along the lines of:

\documentclass{scrartcl}

The second \let\answer line redefines the new macro answer again. If it is in there, the answer will be printed, in normal font.
If you comment that line out, the answers will not show up in the Pdf (or dvi, or...). The phantom macro is capable of holding more than just a line of text.
With this, it is of course tempting to \let\answer\textsc, so the answers show up in a font that is distinguishable from the questions.