2

I am trying to write some questions which are of objective or multiple choice format. The tasks package does the job except for two things:

  1. Instead of \begin{tasks} and \task I want to write \begin{choices} and \choice;

  2. I want to include and option \correctchoice and print all the answers et the end.

I tried reading the documentations but I am not able to do this. Please help me.

\documentclass[12pt]{article}
\usepackage{tasks}
\usepackage{exsheets}
\SetupExSheets[question]{type=exam}
\begin{document}
\begin{question}
    Which one of the entries does not fit with the others?
    \begin{tasks}(4)
        \task mercury
        \task iron
        \task lead
        \task zinc
    \end{tasks}
\end{question}
\settasks{
    counter-format=(tsk[a]),
    label-width=4ex
}
\begin{question}
    What is a function?
    \begin{tasks}(2)
        \task A dancing electron
        \task A dancing proton
        \task A dancing neutron
        \task A Dixie Dancing Duck
    \end{tasks}
\end{question}
\end{document}

enter image description here

1 Answer 1

1

Now (more than two years after the question was posted) it is reasonably easy with exsheets' successor xsim to achieve what you want. The example below defines an environment choices like this:

\NewTasksEnvironment[
  label = (\alph*) ,
  label-width = 16pt
]{choices}[\choice]

Then an exercise property answer is defined and a command which saves the answer:

\DeclareExerciseProperty{answer}    
\newcommand*\answer[1]{%
  \SetExpandedExerciseProperty{answer}{ (\alph{task}) \unexpanded{#1}}%
 #1%
}

At last a command is defined which retrieves the answers:

\newcommand*\getanswers{%
  \def\betweenanswers{\def\betweenanswers{\hspace{2em}}}%
  \ForEachUsedExerciseByID{%
    \betweenanswers##3\ExercisePropertyGet{##1}{##2}{answer}%
  }%
}

This is then used like this – the syntax is not exactly as wanted but quite close:

\begin{exercise}
  Which one of the entries does not fit with the others?
  \begin{choices}(4)
    \choice mercury
    \choice iron
    \choice \answer{lead}
    \choice zinc
  \end{choices}
\end{exercise}

enter image description here

The complete code:

\documentclass[12pt]{article}
\usepackage[no-files]{xsim}
\usepackage{tasks}

\NewTasksEnvironment[
  label = (\alph*) ,
  label-width = 16pt
]{choices}[\choice]

\DeclareExerciseProperty{answer}    
\newcommand*\answer[1]{%
  \SetExpandedExerciseProperty{answer}{ (\alph{task}) \unexpanded{#1}}%
 #1%
}

\newcommand*\getanswers{%
  \def\betweenanswers{\def\betweenanswers{\hspace{2em}}}%
  \ForEachUsedExerciseByID{%
    \betweenanswers##3\ExercisePropertyGet{##1}{##2}{answer}%
  }%
}

\xsimsetup{
  exercise/name = Question ,
  exercise/the-counter = \arabic{exercise}.
}

\begin{document}

\section{Questions}
\begin{exercise}
  Which one of the entries does not fit with the others?
  \begin{choices}(4)
    \choice mercury
    \choice iron
    \choice \answer{lead}
    \choice zinc
  \end{choices}
\end{exercise}

\begin{exercise}
  Which one of the entries does not fit with the others?
  \begin{choices}(4)
    \choice argon
    \choice \answer{hydrogen}
    \choice neon
    \choice helium
  \end{choices}
\end{exercise}

\section{Answers}
\getanswers

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .