3

We suppose that we have 30 question to solve a text for students instead of 2 as this 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}

Is there a possibility of automatically being able to interchange, with some technical artifice, the order of questions and answers relative to them, after the compilation?

Related to: Squares for answer choice options and perfect alignment to mathematical answers

Sebastiano
  • 54,118
  • 1
    If you use Linux, Auto Multiple Choice make exactly that, and it is included in official packages at least in Debian based distros., so try it will be not a problem. In windows, you cannot use their GUI to control the exams projects, correct the scanned tests and so, but what produce the exam is no more than a LateX document with a LaTeX package ( automultiplechoice.sty), so I suppose that is possible use to produce the PDF also in Windows (but scoring it manually without the AMC GUI will be a nightmare) . – Fran Dec 10 '19 at 22:56
  • @Fran Very kind Fran, I am a scarce user :-). I think to have understood your comment, but for me is an impossible adventure. I should examine your comment in detail and do some research on it. My problem is that I am always too busy and I should still finish the book with my teacher. – Sebastiano Dec 10 '19 at 23:01
  • 1
    Impossible? It take much less than five minutes test if this work in your computer: Put automultiplechoice.sty in your working directory and the first MWE of this answer. You can compile that as usual? You see two test in the PDF?. Then change \onecopy{2}{\insertgroup{code}} to \onecopy{102}{\insertgroup{code}} and compile it again. Have you now more that one hundred different test? – Fran Dec 10 '19 at 23:26
  • @Fran I have to prevent my students from copying :-) The sheet I use is an A3 (I have to economize the paper). I am pleased to have your additional answer if you prefer. I have previously upvoted for you and put it in my favorites. – Sebastiano Dec 10 '19 at 23:34
  • 1
    @Sebastiano It is better if we have a page list all correct answers. How can I do it? – minhthien_2016 Dec 11 '19 at 01:11
  • @minhthien_2016 You're right, but I should go the short way due to my continuous commitments. Thank you for your comment. – Sebastiano Dec 11 '19 at 20:22

2 Answers2

4

You can use expl3 facilities. Storing the answers in a sequence allows to shuffle it.

I also defined a test environment that makes as many copies of the test as requested.

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

enter image description here

egreg
  • 1,121,712
  • I'm amazed every time I see how "easy" stuff looks in expl3. Which is kind of disconcerting, since every time I try to understand it I feel like I'm too dumb for it... :-( – campa Dec 10 '19 at 19:33
2

I propose here a possible way:

  • First I define a macro \definequestion which takes 6 arguments: the first one is some "label" to identify the question; the second is the question text; the third to sixth ones are the possible answers. The question is put in a t aligned \parbox with a fixed width \questionwidth, which may be adjusted depending on the page and font size.
  • The macro \usequestion{label} printes the corresponding question.
  • The macro \printrandomquestions uses the randomlist package to print the questions in a pseudo-random order. The optional argument is the seed, the mandatory argument must be a comma-separated list of question labels.

For a version with reshuffled answers see below.

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

Output (in landscape with 3 columns for clarity)

enter image description here

EDIT With the reshuffling of the answers.

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

enter image description here

campa
  • 31,130