Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

2 Answers 2

up vote 5 down vote accepted

Same idea, with newcommand:

\documentclass{scrartcl}

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

\begin{document}
The question goes here\\
\answer{This is the answer}
\end{document}

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:

\documentclass{scrartcl}
\let\answer\phantom
\let\answer\textnormal
\begin{document}
The question goes here\\
\answer{This is the answer}
\end{document}

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

 
discard

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.