5

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.

2

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)]
\item answer 1
\item answer 2
\item answer 3
\end{enumerate}
\end{question}

\begin{solution}
\begin{enumerate}[a)]
\item answer 1
\item \textbf{answer 2}
\item answer 3
\end{enumerate}
\end{solution}

\begin{question}[type=exam]
\begin{enumerate}[a)]
\item answer 1
% does not work as this is not in a solution environment
\item \PrintSolutionsTF{\textbf{answer 2}}{answer 2}
\item answer 3
\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.

5

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.

I'll start with my preferred method.


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?
    \begin{tasks}(4)
        \task \correct A
        \task B
        \task C
        \task D
    \end{tasks}
\end{question}
\begin{solution}
    \correct
\end{solution}

\begin{question}
    Which animal is the best?
    \begin{tasks}(4)
        \task cats
        \task dogs
        \task \correct honey badgers
        \task dragons
    \end{tasks}
\end{question}
\begin{solution}
    \correct
\end{solution}

\section*{Answers}
\printsolutions

\end{document}

And the output:

enter image description here

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}

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

\begin{document}

\begin{question}
    Which letter is a vowel?
    \begin{tasks}(3)
        \task \correct A
        \task B
        \task C
    \end{tasks}
\end{question}

\begin{question}
    Which animal is the best?
    \begin{tasks}(3)
        \task cats
        \task \correct honey badgers
        \task dragons
    \end{tasks}
\end{question}

\end{document}

Outputs

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.