# Exsheets: Having two solutions to a question and printing them out separately

I'm using exsheets to write up a document that contains math questions and prints out the numerical solutions to each of the questions at the end. However, I would also like to include the worked solutions to selected questions in another section. So effectively what I want to do is to be able to write two sets of solutions for selected questions. Print out one set of solution in one section, and print out the other set of (worked) solutions in another section.

I could write down the worked solution set manually, however I believe that might cause a lot of trouble down the road with edits as the question counters will be out of sync.

How would I go about that?

Currently I have something like this:

\begin{question}%Y11C7G1
Differentiate each function using the quotient rule. Express your answer in fully factored form and state any values of $x$ for which the tangent is horizontal
\task $y=\dfrac{x+1}{x-1}$
\task $y=\dfrac{x^2-1}{x^2+1}$
\task $y=\dfrac{x^2-a}{x^2-b}$
\task $y=\dfrac{x^n-3}{x^n+3}$
\end{question}

\begin{solution}
\end{solution}

\begin{question}%Y11C7G5
Differentiate, stating any zeroes of the derivative:
\task $\dfrac{\sqrt{x}+1}{\sqrt{x}+2}$
\task $\dfrac{x-3}{\sqrt{x+1}}$
\end{question}

\begin{solution}
\end{solution}

\newpage
\section*{Solutions}
\printsolutions

• Thanks clemens for the quick reply! Do you know of any alternatives that will allow me to do that? – Kevin Feb 16 '17 at 13:30
• A dirty workaround would be to use 2 classes: one with the actual questions and the short answers and the other with dummy questions and the long (worked) answers. Then have a script to compile the code using the first class, change the code to use the second class and with no printed questions, and concatenate the resulting pdfs. It won't work if you need to include page refs from the second run in ToC. – alwaysask Feb 16 '17 at 14:08
• @alwaysask there is a simpler way, see my answer :) – clemens Feb 16 '17 at 16:05

You can use a boolean switch:

\newif\ifshortsolution


Then you can define a command \ifshortsolution{<short>}{<long>} which you use in the solution environments:

\makeatletter
\newcommand\shortlongsolution[2]{%
\ifshortsolution
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{#1}%
{#2}%
}
\makeatother


For printing the solutions you then set the switch with \shortsolutionstrue or \shortsolutionsfalse prior to \printsolutions:

\newpage
\shortsolutiontrue

\section*{Short Solutions}
\printsolutions

\shortsolutionfalse

\section*{Long Solutions}
\printsolutions


A complete example:

\documentclass{article}

\newif\ifshortsolution

\makeatletter
\newcommand\shortlongsolution[2]{%
\ifshortsolution
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{#1}%
{#2}%
}
\makeatother

\begin{document}

\begin{question}
\end{question}
\begin{solution}
\end{solution}

\begin{question}
\end{question}

\begin{solution}
\end{solution}

\newpage
\shortsolutiontrue

\section*{Short Solutions}
\printsolutions

\shortsolutionfalse

\section*{Long Solutions}
\printsolutions

\end{document}