TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

Same idea, with newcommand:


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

The question goes here\\
\answer{This is the answer}

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

share|improve this answer
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:

The question goes here\\
\answer{This is the answer}

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.