GeneralQuestions and Solutions

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
kapowza
Posts: 19
Joined: Fri Jan 30, 2009 3:32 pm

Questions and Solutions

Post by kapowza »

I'm making a study guide for my students with several practice questions. I'm also working on a separate solution manual. Until now, I was using two separate documents. The problem is that if I rearrange the questions in the study guide, I have to sort through the solution manual and find the corresponding solution and move it accordingly. It occurred to me that there might be a way to combine the two into a single document and possibly have the questions and solutions "attached" to each other in some way. Something like:

\item {Question}{Solution}

And then "tell" latex to only print out the questions (without solutions) for the study guide and then to print out only solutions (without the questions) when I'm creating the solution manual.

However, I'm still relatively new to latex and I don't know if this capability exists. So, I'm wondering if there's some built-in function or something I could add on to do this. If anyone can point me in the right direction, I'd appreciate it. Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

Questions and Solutions

Post by magicmoose »

Hi,

I think this (messy) code should do what you want:

Code: Select all

\newcommand{\answers}{yes} %put 'yes' if you want answers displayed or leave blank if you don't want answers displayed
\newcommand{\questions}{yes} %put 'yes' if you want questions displayed or leave blank if you don't want questions displayed

\newcommand{\question}[4]{\ifthenelse{\equal{\questions}{yes}}{\textbf{#1} #2\newline}{} \ifthenelse{\equal{\answers}{yes}}{\textbf{#3} #4\newline}{}}

\question{Question 1}{question goes here}{Answer to Question 1}{answer goes here}
\question{Question 2}{question goes here}{Answer to Question 2}{answer goes here}
(you will need the ifthen package)

All you do is set questions or answers to 'yes' and they will display.
You can add counters and things to get the numbering right, but this will allow you to turn the questions and answers on or off.

There is probably a better way, but this will work ;)

Hope that helps
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Questions and Solutions

Post by nlct »

You could try the probsoln package or the examdesign class.

Regards
Nicola Talbot
Post Reply