# Exam with multiple choice using exsheets

I have seen many examples of multiple choice exams setting the correct with exam. But, is there anyway of doing a mulitple choice with exsheets?

I would like something like:

1. Question 1
a)
b)
c)


And then in the code have something that sets bold the correct answer when I toggle it on.

Since exsheets strictly separates questions from solutions, the only way that adheres to this separation would be something like copying an enumeration environment and marking the correct answer with \textbf in the solution. Using the \PrintSolutionsTF command does not work inside the question environment.

\documentclass{article}

\usepackage{exsheets}
\usepackage{enumerate}

\begin{document}

\begin{question}[type=exam]
\begin{enumerate}[a)]
\end{enumerate}
\end{question}

\begin{solution}
\begin{enumerate}[a)]
\end{enumerate}
\end{solution}

\begin{question}[type=exam]
\begin{enumerate}[a)]
% does not work as this is not in a solution environment
\end{enumerate}
\end{question}

\printsolutions

\end{document}


You could, however, define your own commands to achieve your desired behavior. This would then be independent of the package. See How to avoid the compilation of some of my newcommands in latex for such a solution.

Below I provide:

• An answer to your original question, how to make the correct choice appear bold.
• What I prefer to do: print just the answer in a separate "Answers" section, without repeating the entire question.

## What I Prefer

Edit: original version of this code was missing a %, which ended up putting extra whitespace before the correct answer. That would be undesirable!

Here we define a command \correct using \PrintSolutionsTF{<true code>}{<false code>} that:

• When inside a question, marks its location with a label \label{ans:\CurrentQuestionID}.
• When inside a solution, references \ref{ans:\CurrentQuestionID}.

This requires the auto-label option for exsheets.

Here's the code:

\documentclass{article}
\usepackage[auto-label]{exsheets}

\newcommand{\correct}{
\PrintSolutionsTF{%
\ref{ans:\CurrentQuestionID}%
}{%
\label{ans:\CurrentQuestionID}%
}%
}

\begin{document}

\begin{question}
Which letter is a vowel?
\end{question}
\begin{solution}
\correct
\end{solution}

\begin{question}
Which animal is the best?
\end{question}
\begin{solution}
\correct
\end{solution}

\printsolutions

\end{document}


And the output:

## What you originally asked for

Mark the correct option \correct, and the etoolbox command \ifstrequal switches that option to bold if \ShowAnswers has value true. (This requires expanding \ShowAnswers before \ifstrequal is evaluated. See Comparing an argument to a string when argument is a result of a command with etoolbox )

\documentclass{article}
\usepackage{exsheets}
\usepackage{etoolbox}

\renewcommand{\ShowAnswers}{true} %comment this out if you do not want to show the answers
\newcommand{\correct}{%
}

\begin{document}

\begin{question}
Which letter is a vowel?
\end{question}

\begin{question}
Which animal is the best?