开发者

Creating problem-sets with answers in 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" sec开发者_运维技巧tion just the way they do in textbooks.

Does anyone know of a way to do this?

Many thanks in advance!


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.


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}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜