1

I'm writing an exam for a class, and I'd like to write the solutions as I write the exam. However, I'd like to be able to go back and from between generating pdfs with solutions included and without them. Ideally, the solutions could be included in some custom environment, which can be "turned off/on" by modifying a small piece of code in the preamble. I.e., when turned off, they should effectively be commented out.

The brute force solution would be to manually comment out every solution when generating the exam without solutions, but it would be nice if there were a cleaner way.

How can I most easily do this?

oxeimon
  • 213
  • There are packages designed for this like xsim, and the exam document class, etc, which have a lot of features. Too many probably, but they definitely do what you ask. – frabjous Oct 06 '22 at 21:09
  • Probably wanting something like https://tex.stackexchange.com/a/15510/1750 and then put your solutions in \begin{solution} ... \end{solution} – Ben Voigt Oct 06 '22 at 21:19
  • in fact as you already said you are willing to use a custom environment, this is a duplicate of that question. – Ben Voigt Oct 06 '22 at 21:20
  • I added an answer to the duplicate focusing a bit more on the exercise/solution part. (https://tex.stackexchange.com/a/660831/38080) – Rmano Oct 07 '22 at 10:43

1 Answers1

0

What about ifdefined?

\documentclass{article}   
\newcommand*{\SHOWSOLUTION}{}  % comment out to hide solution

\begin{document} Problem \ifdefined\SHOWSOLUTION Solution \else Think yourself. \fi \end{document}

As already mentioned by others, the document class exam offers many features in this regard.

Further alternatives you find at a similar question.