tags:

views:

52

answers:

3

Hello everyone.

I want to typeset Mathematical problem-sets in Latex. My requirements are as follows:

When I type them in, I want the questions and the answers to be next to each other in the source-code so that fixing errors, etc. can be done easily.

However, when the document is typeset, I want the answers to appear in a separate "Answers" section just the way they do in textbooks.

Does anyone know of a way to do this?

Many thanks in advance!

A: 

Define a 'question' and a 'solution' environment in your questions.tex file (say). Include questions.tex twice. The first time, include questions only. The second time, include solutions only.

\usepackage{version}

% Include questions but not solutions:
\includeversion{question}\excludeversion{solution}

% Include solutions but not questions:
%\excludeversion{question}\includeversion{solution}

\begin{document}

\begin{enumerate}

\item  % Shared question marker.
\begin{question}
Question goes here.
\end{question}
\begin{solution}
solution goes here
\end{solution}
Peter
@Pieter's answer is better, but I leave this here for reference anyway.
Peter
A: 

I developed a lot of code to do this. There are two approaches. One is you can have a function that keeps adding the answers to a variable that just gets bigger and bigger. The second is you can have function that writes to a file and then, later, reads the file into your document. Frankly, the variable method is easier, even though it seems grosser.

vy32
+5  A: 

You are looking for deferred printing. There are packages that can handle this problem, for instance exercise. This does exactly what you're looking for.

Pieter
woah, time to change my approach :)
Peter
Thank you! It seem to do everything I want - will explore in detail!
ARV