编译后自动摇动使用 LaTeX 创建的测试的问题和答案

编译后自动摇动使用 LaTeX 创建的测试的问题和答案

我们假设我们有 30 个问题需要为学生解决,而不是像这个 MWE 那样只有 2 个:

\documentclass[leqno,11pt,landscape,a3paper]{extarticle}
\usepackage{multicol,mathtools}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}

\begin{multicols}{1}
\begin{enumerate}
\item La velocità di 1,00$\cdot 10^2$ m/s espressa in km/h è:

$\fbox{A}$  36 km/h.\\
$\fbox{B}$    360 km/h.\\
$\fbox{C}$  27,8 km/h.\\
$\fbox{D}$    $3,\!60\cdot 10^{8}$ km/h.\\
$\fbox{E}$ \begin{tabular}{lllllllllllll}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{6}{c}{} \\
\hline
\end{tabular}

\item In fisica nucleare si usa l'angstrom (simbolo: 1\AA=$10^{-10}$ m) e il fermi o femtometro (1 fm= $10^{-15}$ m). Qual è la relazione tra queste due unità di misura?

$\fbox{A}$  1 \AA = $10^5$ fm.\\
$\fbox{B}$    1 \AA = $10^{-5}$ fm.\\
$\fbox{C}$    1 \AA = $10^{-15}$ fm.\\
$\fbox{D}$    1 \AA = $10^{3}$ fm.\\
$\fbox{E}$ \begin{tabular}{lllllllllllll}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{6}{c}{} \\
\hline
\end{tabular}
\end{enumerate}
\end{multicols}
\end{document}

编译之后,是否有可能利用一些技术手段自动交换问题和答案的相对顺序?

相关:方格用于选择答案,与数学答案完美对齐

答案1

我在这里提出一种可能的方法:

  • 首先我定义了一个宏\definequestion,它有 6 个参数:第一个是一些“标签”,用于标识问题;第二个是问题文本;第三到第六个是可能的答案。问题被放在一个固定宽度的t中,可以根据页面和字体大小进行调整。\parbox\questionwidth
  • \usequestion{label}打印相应的问题。
  • 该宏\printrandomquestions使用该randomlist包以伪随机顺序打印问题。可选参数是种子,强制参数必须是以逗号分隔的问题标签列表。

请参阅下文查看重新排列答案的版本。

\documentclass{article}

\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{randomlist}

\newlength{\questionwidth}
\setlength{\questionwidth}{6cm}

\makeatletter

\newcommand{\definequestion}[6]{% #1=label; #2: text; #3...#6 multiple choices
   \@namedef{question@#1}{%
     \parbox[t]{\questionwidth}{%
        #2\par\smallskip
        \framebox[1.3em]{A}~#3\par
        \framebox[1.3em]{B}~#4\par
        \framebox[1.3em]{C}~#5\par
        \framebox[1.3em]{D}~#6\par
        \framebox[1.3em]{E}~\rule{\dimexpr\questionwidth-2em}{0.4pt}
        }}
}

\newcommand*{\usequestion}[1]{\@nameuse{question@#1}}

\newcommand*{\printrandomquestions}[2][0]%
  {%
   \RLsetrandomseed{#1}%
   \def\@tempa{}%
   \@for\x:=#2\do{%
                  \edef\y{\noexpand\g@addto@macro\noexpand\@tempa{{\noexpand\@nameuse{question@\x}}}}%
                  \y
                 }%
   \expandafter\RandomEnumerateList\@tempa
  }

\makeatother

\definequestion{v}
{La velocità di $1,00\cdot 10^2$\,m$/$s espressa in km$/$h è:}
{36\,km$/$h}
{360\,km$/$h}
{27,8\,km$/$h}
{$3{,}60\cdot 10^{8}$\,km$/$h.}

\definequestion{A-fm}
{In fisica nucleare si usano l'angstrom (simbolo: $1\,\text{\AA}=10^{-10}$\,m)
 e il fermi o femtometro ($1\,\mathrm{fm} = 10^{-15}\,\mathrm{m}$). Qual è la
 relazione tra queste due unità di misura?}
{$1\,\text{\AA} = 10^5$\,fm.}
{$1\,\text{\AA} = 10^{-5}$\,fm}
{$1\,\text{\AA} = 10^{-15}$\,fm.}
{$1\,\text{\AA} = 10^{3}$\,fm.}

\definequestion{foo}{Foo}{}{}{}{}
\definequestion{baz}{Baz}{}{}{}{}


\begin{document}

Manually:
\usequestion{A-fm}

\printrandomquestions{v,A-fm,foo,baz}

\printrandomquestions[5]{v,A-fm,foo,baz}

\printrandomquestions[3]{v,A-fm,foo,baz}

\end{document}

输出(为清晰起见,横向显示 3 列)

在此处输入图片描述

编辑答案重新调整。

\documentclass[landscape]{article}

\usepackage[margin=1cm]{geometry} % for preview
\usepackage{multicol}

\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{randomlist}

\newlength{\questionwidth}
\setlength{\questionwidth}{6cm}

\makeatletter

\newcommand{\definequestion}[6]{% #1=label; #2: text; #3...#6 multiple choices
   \@namedef{question@#1}%
      {%
       \parbox[t]{\questionwidth}%
          {%
           \NewList{answers}%
           \SetList{answers}{{#3},{#4},{#5},{#6}}% extra grouping to protect commas in arguments
           #2\par\smallskip
           \count@=65
           \ForEachRandomItem{answers}{ans}{\framebox[1.3em]{\char\count@}~\ans\par\advance\count@\@ne}%
           \framebox[1.3em]{E}~\rule{\dimexpr\questionwidth-2em}{0.4pt}% last one
          }%
      }%
}

\newcommand*{\usequestion}[1]{\@nameuse{question@#1}} % provided but not quite useful

\newcommand*{\printrandomquestions}[2][0]%
  {%
   \RLsetrandomseed{#1}%
   \def\@tempa{}%
   \@for\x:=#2\do{%
                  \edef\y{\noexpand\g@addto@macro\noexpand\@tempa{{\noexpand\@nameuse{question@\x}}}}%
                  \y
                 }%
   \expandafter\RandomEnumerateList\@tempa
  }

\makeatother

\definequestion{v}
{La velocità di $1,00\cdot 10^2$\,m$/$s espressa in km$/$h è:}
{36\,km$/$h}
{360\,km$/$h}
{27,8\,km$/$h}
{$3{,}60\cdot 10^{8}$\,km$/$h.}

\definequestion{A-fm}
{In fisica nucleare si usano l'angstrom (simbolo: $1\,\text{\AA}=10^{-10}$\,m)
 e il fermi o femtometro ($1\,\mathrm{fm} = 10^{-15}\,\mathrm{m}$). Qual è la
 relazione tra queste due unità di misura?}
{$1\,\text{\AA} = 10^5$\,fm.}
{$1\,\text{\AA} = 10^{-5}$\,fm}
{$1\,\text{\AA} = 10^{-15}$\,fm.}
{$1\,\text{\AA} = 10^{3}$\,fm.}

\definequestion{foo}{Foo}{a}{b}{c}{d}
\definequestion{baz}{Baz}{$\alpha$}{$\beta$}{$\gamma$}{$\delta$}

\begin{document}

\begin{multicols}{3}
\printrandomquestions{v,A-fm,foo,baz}

\printrandomquestions[5]{v,A-fm,foo,baz}

\printrandomquestions[3]{v,A-fm,foo,baz}
\end{multicols}

\end{document}

在此处输入图片描述

答案2

您可以使用expl3设施。按顺序存储答案可以对其进行打乱。

我还定义了一个test环境,可以根据要求制作尽可能多的测试副本。

\documentclass{article}
\usepackage[a5paper,margin=1cm]{geometry} % just to make smaller images
\usepackage{multicol,mathtools}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{siunitx}

\pagestyle{empty}

\sisetup{output-decimal-marker={,}}

\ExplSyntaxOn
\NewDocumentCommand{\question}{mm}
 {
  \seq_clear:N \l__sebastiano_question_body_seq
  \tl_map_inline:nn { #2 } { \seq_put_right:Nn \l__sebastiano_question_body_seq { ##1 } }
  \seq_shuffle:N \l__sebastiano_question_body_seq

  \item #1 \\[2ex]

  \seq_indexed_map_inline:Nn \l__sebastiano_question_body_seq
   {
    \fbox { \int_to_Alph:n { ##1 } } ~ ##2 \\[0.5ex]
   }

  \fbox { \int_to_Alph:n { \seq_count:N \l__sebastiano_question_body_seq + 1 } } ~
  \makebox[9em]{\hrulefill}
 }

\NewDocumentEnvironment{test}{m+b}
 {
  \prg_replicate:nn { #1 } { #2 \clearpage }
 }
 {}
\ExplSyntaxOff

\begin{document}

\begin{test}{4}

\begin{enumerate}
\question{La velocità di \SI{1,00e2}{m/s} espressa in \si{km/h} è:}{
  {\SI{36}{km/h}.}
  {\SI{360}{km/h}.}
  {\SI{27,8}{km/h}.}
  {\SI{3,60e8}{km/h}.}
}

\question{In fisica nucleare si usa l'angstrom (simbolo: $\SI{1}{\angstrom}=\SI{1e-10}{m}$) 
e il fermi o femtometro ($\SI{1}{fm}=\SI{1e-15}{m}$). Qual è la relazione tra queste due 
unità di misura?}{
  {$\SI{1}{\angstrom}=\SI{1e5}{fm}$.}
  {$\SI{1}{\angstrom}=\SI{1e-5}{fm}$.}
  {$\SI{1}{\angstrom}=\SI{1e-15}{fm}$.}
  {$\SI{1}{\angstrom}=\SI{1e3}{fm}$.}
}

\end{enumerate}

\end{test}

\end{document}

在此处输入图片描述

相关内容