# 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
\begin{tasks}(2)
\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{tasks}
\end{question}

\begin{solution}
\begin{tasks}(1)
\task TODO
\end{tasks}
\end{solution}

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

\begin{solution}
\begin{tasks}(1)
\task TODO
\end{tasks}
\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

## 1 Answer

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{%
\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}
\usepackage{exsheets,tasks}

\newif\ifshortsolution

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

\begin{document}

\begin{question}
\end{question}
\begin{solution}
\begin{tasks}(1)
\task \shortlongsolution{first short}{first long}
\end{tasks}
\end{solution}

\begin{question}
\end{question}

\begin{solution}
\begin{tasks}(1)
\task \shortlongsolution{second short}{second long}
\end{tasks}
\end{solution}

\newpage
\shortsolutiontrue

\section*{Short Solutions}
\printsolutions

\shortsolutionfalse

\section*{Long Solutions}
\printsolutions

\end{document} 