Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating problem-sets with answers in Latex

Tags:

latex

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!

like image 993
ARV Avatar asked May 27 '10 19:05

ARV


2 Answers

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.

like image 131
Pieter Avatar answered Oct 23 '22 23:10

Pieter


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}
like image 23
Peter Avatar answered Oct 23 '22 23:10

Peter