使用 xsim 打印多项选择题解决方案

使用 xsim 打印多项选择题解决方案

以下示例中如何打印多项选择题的解决方案?

\documentclass{scrartcl}
\usepackage[clear-aux]{xsim}

\usepackage{enumitem,amssymb,fmtcount}
\newlist{choices}{itemize}{1}
\setlist[choices]{label=$\Box$}
\newcommand*\choice{\item}

\DeclareExerciseProperty{choices}
\DeclareExerciseProperty*{multiple}
\DeclareExerciseEnvironmentTemplate{mc}
  {%
    \UseExerciseTemplate{begin}{default}%
    \IfExerciseBooleanPropertyTF{multiple}
      {Select one or more correct answers}
      {%
        \GetExercisePropertyT{choices}
          {Select \numberstringnum{#1} correct answer\ifnum#1>1 s\fi.}%
      }%
    \begin{choices}
  }
  {%
    \end{choices}
    \UseExerciseTemplate{end}{default}%
  }

\DeclareExerciseType{mc}{
  exercise-env = multiplechoice ,
  solution-env = correctchoices ,
  exercise-name = Question ,
  solution-name = Solution ,
  exercise-template = mc ,
  solution-template = mc ,
  counter = exercise
}

\xsimsetup{
  exercise/name = Question ,
  solution/name = Solution
}

\begin{document}

\section{Questions}
\begin{multiplechoice}[choices=1]
  \choice one
  \choice two
  \choice three
  \choice four
\end{multiplechoice}

\begin{exercise}
  Answer this question on a separate sheet.  
\end{exercise}

\begin{multiplechoice}[multiple]
  \choice one
  \choice two
  \choice three
  \choice four
\end{multiplechoice}

\begin{multiplechoice}[choices=2]
  \choice one
  \choice two
  \choice three
  \choice four
\end{multiplechoice}

\end{document}

我尝试过

%preamble
exercise/print = true,
solution/print = true,

%document
\begin{correctchoices}
    \choice two
\end{correctchoices}

但它给出了奇怪的输出。

另外,打印解决方案时是否可以在问题本身上标记答案?

答案1

从 0.17 版(2020/02/21)开始,xsim具有锻炼属性solution,该属性指示xsim对锻炼和解决方案使用相同的环境体。这在这里非常方便。使用\IfInsideSolutionTFthen 允许我们在需要的地方插入复选标记:

\documentclass{scrartcl}
\usepackage{xsim}[2020/02/21]

\usepackage{enumitem,fontawesome,fmtcount,multicol}
\newlist{choices}{itemize}{1}
\setlist[choices]{label=\faSquareO}

\newcommand*\correct{\IfInsideSolutionTF{\faCheckSquareO}{\faSquareO}}

\newcommand*\choice{\item}

\DeclareExerciseProperty{choices}
\DeclareExerciseProperty*{multiple}
\DeclareExerciseEnvironmentTemplate{mc}
  {%
    \UseExerciseTemplate{begin}{default}%
    \IfExerciseBooleanPropertyTF{multiple}
      {Select one or more correct answers}
      {%
        \GetExercisePropertyT{choices}
          {Select \numberstringnum{#1} correct answer\ifnum#1>1 s\fi.}%
      }%
    \begin{choices}
  }
  {%
    \end{choices}
    \UseExerciseTemplate{end}{default}%
  }

\DeclareExerciseType{mc}{
  exercise-env = multiplechoice ,
  solution-env = correctchoices ,
  exercise-name = Question ,
  solution-name = Solution ,
  exercise-template = mc ,
  solution-template = mc ,
  counter = exercise
}

\xsimsetup{
  exercise/name = Question ,
  solution/name = Solution ,
  print-solutions/headings=false
}

\begin{document}

\begin{multicols}{2}
\section{Questions}
\begin{multiplechoice}[choices=1,solution]
  \choice one
  \choice[\correct] two
  \choice three
  \choice four
\end{multiplechoice}

\begin{exercise}
  Answer this question on a separate sheet.  
\end{exercise}

\begin{multiplechoice}[multiple,solution]
  \choice[\correct] one
  \choice two
  \choice three
  \choice[\correct] four
\end{multiplechoice}

\begin{multiplechoice}[choices=2,solution]
  \choice one
  \choice[\correct] two
  \choice three
  \choice[\correct] four
\end{multiplechoice}

\columnbreak

\section{Answers}
\printsolutions
\end{multicols}

\end{document}

在此处输入图片描述

相关内容