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:

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
