在 xsim 中随机播放问题

在 xsim 中随机播放问题

正如标题所述,我想在使用xsimtasks包时对问题进行打乱。这是我从具有正确选择环境的多项选择题由@cgnieder 编写。

\documentclass[12pt,a4paper]{article}
\usepackage[inline]{enumitem}
\usepackage[no-files]{xsim}
\usepackage{tasks}[newest]

\DeclareExerciseEnvironmentTemplate{item}
  {\item[\textbf{\GetExerciseName~\GetExerciseProperty{counter}}]}
  {}

\DeclareExerciseProperty{answer}

\newcommand*\answer[1]{%
  \XSIMexpandcode{%
    \SetExerciseProperty{answer}
      { \noexpand{\Alph{task}}}}%
  #1%
}

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

\xsimsetup{
  exercise/template = item,
  exercise/name = Q.,
  exercise/the-counter = \arabic{exercise}.
}

\NewTasksEnvironment[
  label = \textbf{\Alph*.},
]{choice}[\choice]

\newenvironment{questions}
   {\enumerate}
   {\endenumerate}

%=========================================================
\begin{document}

\section{Problems}

\begin{questions}
  \begin{exercise}
    What is the product of $-2$ and $3$?
    \begin{choice}(4)
      \choice \answer{$-6$}
      \choice $6$
      \choice $5$
      \choice $-5$
    \end{choice}
  \end{exercise}

  \begin{exercise}
    What is the sum of the sides of a polygon called?
    \begin{choice}(2)
      \choice Leg
      \choice \answer{Perimeter}
      \choice Area
      \choice Volume
    \end{choice}
  \end{exercise}

  \begin{exercise}
    What is the sum of $-2$ and $-3$?
    \begin{choice}(4)
      \choice $-6$
      \choice $6$
      \choice $5$
      \choice \answer{$-5$}
    \end{choice}
  \end{exercise}
\end{questions}

\section{Answers}
\getanswers

\end{document}

另外,是否可以在本地进行 shuffle?更具体地说,假设我有 10 个问题,并将它们分成 2 部分,一部分包含问题 1 到 5,另一部分包含其余问题。我想分别对每个部分进行 shuffle,并按顺序获取问题,例如,2 3 1 4 5 和 8 6 10 9 7。

答案1

这里有一种方法,首先将练习添加到集合中,然后随机输出它们,同时对它们进行打乱。使用多个集合,这还可以分别对练习块进行打乱。

\documentclass[12pt,a4paper]{article}
\usepackage{xsim}
\usepackage{tasks}

\NewTasksEnvironment[
  label = \textbf{\Alph*.} ,
  label-width = 15pt
]{choice}[\choice](4)

\DeclareExerciseEnvironmentTemplate{item}
  {\description\item[\GetExerciseName~\GetExerciseProperty{counter}]}
  {\enddescription}

\DeclareExerciseEnvironmentTemplate{space}
  {\textbf{\GetExerciseProperty{counter}} }
  {\quad}
  
\newcommand*\answer[1]{%
  \XSIMexpandcode{%
    \SetExerciseProperty{solution-body}
      {\noexpand{\Alph{task}}}}%
  #1%
}

\DeclareExerciseCollection{part-A}

\xsimsetup{
  exercise/template = item ,
  solution/template = space ,
  exercise/name = Q. ,
  exercise/the-counter = \arabic{exercise}. ,
  exercise/collect ,
  random/sort = false
}

\begin{document}

\collectexercises{part-A}
\begin{exercise}
  What is the product of $-2$ and $3$?
  \begin{choice}
    \choice \answer{$-6$}
    \choice $6$
    \choice $5$
    \choice $-5$
  \end{choice}
\end{exercise}
\begin{exercise}
  What is the sum of the sides of a polygon called?
  \begin{choice}(2)
    \choice Leg
    \choice \answer{Perimeter}
    \choice Area
    \choice Volume
  \end{choice}
\end{exercise}
\begin{exercise}
  What is the sum of $-2$ and $-3$?
  \begin{choice}
    \choice $-6$
    \choice $6$
    \choice $5$
    \choice \answer{$-5$}
  \end{choice}
\end{exercise}
\begin{exercise}
  Number four
\end{exercise}
\begin{exercise}
  Number five
\end{exercise}
\collectexercisesstop{part-A}

\section{Problems}
\printrandomexercises[collection=part-A]{5}

\section{Answers}
\printsolutions[headings=false]

\end{document}

在此处输入图片描述

相关内容