3

I am using exam package to typeset few problems along with its solutions.

\question Evaluate $\int \frac{x^{4}}{x^{2}+1} d x$
\begin{solution}
Solution: $\int \frac{\mathrm{x}^{4}}{\mathrm{x}^{2}+1} \mathrm{~d} \mathrm{x}=\int \frac{\mathrm{x}^{4}-1+1}{\mathrm{x}^{2}+1} \mathrm{~d} \mathrm{x}$
$$
\begin{aligned}
    &=\int \frac{x^{4}-1}{x^{2}+1}+\frac{1}{x^{2}+1} d x \\
    &=\int\left(x^{2}-1\right) d x+\int \frac{1}{x^{2}+1} d x \\
    &=\frac{x^{3}}{3}-x+\tan ^{-1} x+C
\end{aligned}
$$
\end{solution}

I want to separate "final answer" from the "solution".

So that I can give a handout containing:

  1. just questions & final answers. enter image description here
  2. Or sometimes just the questions (without answers or solutions).
  3. Or sometimes questions and solutions.

I am hoping for something like this:

\question question
\answer answer %or even \begin{answer} \end{answer} <-- for final answer
\begin{solution}
  solution
\end{solution}

Now, I should be able to print just final answers using \printanswers (or some command like that) and printing of solutions controlled by \printsolutions.

I don't have any preference for exampackage, I am using it because it has \printanswers and nice solution environment. I am open to use any other package.

EDIT: Adding some custom code to any latex packages/classes is also okay. I just need this thing to work. It would be ideal if there is a facility to deferred print the options.

6
  • Take a look at the xsim package Sep 25 at 10:46
  • @HafidBoukhoulda: I am a latex newbie, I have gone through the documentation. I found it bit difficult to comprehend. Can you please show me how its done using that package?
    – claws
    Sep 25 at 10:57
  • 1
    What is the difference between answer and solution? Can you edit your question to provide an example ? Sep 25 at 11:36
  • @HafidBoukhoulda: Answer = final answer of the problem. Solution = the entire mathematical process involved in reaching the final answer.
    – claws
    Sep 27 at 5:03
  • @HafidBoukhoulda I have added a picture for clarificiation, I hope my intent is clear now.
    – claws
    Sep 27 at 5:05
1
+50

Adding the following code to your preamble should do the trick

\usepackage{environ}
\newif\ifshortanswers%
\NewEnviron{shortanswer}{\ifshortanswers Ans. \BODY\fi}% Customize here
\def\printshortanswers{\shortanswerstrue}

Then you use

\begin{shortanswer}
42
\end{shortanswer}

to add answers and \printshortanswers to print the answers.

You can change how the answers are displayed by changing the line marked with % Customize here

1
  • Thank you for your answer, it opened up a slew of possibilities.
    – claws
    Oct 3 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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