Fragen und Antworten für einen mit LaTeX erstellten Test nach der Kompilierung automatisch schütteln

Fragen und Antworten für einen mit LaTeX erstellten Test nach der Kompilierung automatisch schütteln

Wir gehen davon aus, dass wir 30 Fragen zu einem Text für die Schüler lösen müssen, statt 2 wie bei diesem MWE:

\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}

Besteht die Möglichkeit, die Reihenfolge der Fragen und der dazugehörigen Antworten nach der Zusammenstellung durch einen technischen Kunstgriff automatisch zu vertauschen?

Bezüglich:Felder für Antwortmöglichkeiten und perfekte Ausrichtung auf mathematische Antworten

Antwort1

Ich schlage hier einen möglichen Weg vor:

  • Zuerst definiere ich ein Makro \definequestion, das 6 Argumente akzeptiert: das erste ist ein „Label“ zur Identifizierung der Frage; das zweite ist der Fragetext; das dritte bis sechste sind die möglichen Antworten. Die Frage wird in einer festen Breite tausgerichtet , die je nach Seite und Schriftgröße angepasst werden kann.\parbox\questionwidth
  • Das Makro \usequestion{label}druckt die entsprechende Frage aus.
  • Das Makro \printrandomquestionsverwendet das randomlistPaket, um die Fragen in pseudozufälliger Reihenfolge auszudrucken. Das optionale Argument ist der Seed, das obligatorische Argument muss eine durch Kommas getrennte Liste von Fragenbezeichnungen sein.

Eine Version mit neu gemischten Antworten finden Sie unten.

\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}

Ausgabe (im Querformat mit 3 Spalten zur besseren Übersicht)

Bildbeschreibung hier eingeben

BEARBEITENMit der Neuordnung der Antworten.

\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}

Bildbeschreibung hier eingeben

Antwort2

Sie können Erleichterungen nutzen expl3. Das Speichern der Antworten in einer Reihenfolge ermöglicht das Mischen.

Außerdem habe ich eine testUmgebung definiert, die so viele Kopien des Tests erstellt, wie angefordert.

\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}

Bildbeschreibung hier eingeben

verwandte Informationen