1

I am designing random excercise sheets for my students. I'm able to get random numbers without repetition using the code from Random number without repetition in an \includegraphics. Now I want to use the random numbers to create unique tables. Eg. I have 20 possible mc questions and I want to use 5 different questions for each student. Each question is outsourced in a .tex file.

Example:

  • random number 1 -> \input{1.tex}
  • random number 3 -> \input{3.tex}
  • random number 8 -> \input{8.tex}

Each X.tex file contains a table row like

a & b & c & d \\

Now my problem is the following error code if I use the tabular environment. I don't understand where the missing } is.

! Extra }, or forgotten \endgroup. <template> \unskip \hfil } \hskip \tabcolsep \endtemplate l.56 \randomincludegraphics{total}?

Here is my MWE:

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

\begin{document}

\makeatletter \def\declarenumlist#1#2#3{% @ifundefined{c@#1@listcount}{\newcounter{#1@listcount}}{}% \setcounter{#1@listcount}{1}% \begingroup \count@=#2\relax \def\x{}% \loop \edef\x{\x{\the\count@}}% \global\expandafter\let\csname#1@\number\count@ @used\endcsname\relax \ifnum\count@<#3\relax \advance\count@@ne \stepcounter{#1@listcount}% \repeat \edef\x{\endgroup \noexpand\pgfmathdeclarerandomlist{#1}{\x}% }\x \expandafter\mathchardef\csname #1@number\endcsname\value{#1@listcount}% \setcounter{#1@listcount}{0}% }

\newcommand{\pgfmathuniquerandomitem}[2]{% \pgfmathrandomitem#1{#2}% \ifnum\value{#2@listcount}=@nameuse{#2@number}% @latex@warning{List #2 exhausted}% \else @ifundefined{#2@#1@used}% {\stepcounter{#2@listcount}\global@namedef{#2@#1@used}{used}}% {\pgfmathuniquerandomitem#1{#2}}% \fi }

\makeatother

\newcommand{\randomincludegraphics}[2][]{% \begingroup \pgfmathuniquerandomitem\z{#2}% % Uncomment the following line for the production version \input{\z.tex} % and remove the following line % I want to include \texttt{\z.pdf} with options ``\texttt{#1}'' \endgroup }

%I want 2 numbers because I have 2 possible rows

\begin{tabular}{cccc} \declarenumlist{total}{1}{2}

\randomincludegraphics{total}

\randomincludegraphics{total}

\end{tabular}

%content of 1.tex % a & b & c & d \

% content of 2.tex % e & f & g & h \

\end{document}

  • 1
    Oh, well, nine years ago was a very different situation! Let me try and fix a “modern” solution. – egreg Nov 05 '22 at 14:47
  • The xsim package also offers this feature, see section 10. Printing Random Exercises from A Collection in the manual on page 26. – Marijn Nov 05 '22 at 14:49
  • Another option is esami, see section 7.2 Commands to choose from a list in the manual. – Marijn Nov 05 '22 at 14:57
  • There is also exercisebank, but that doesn't offer randomized selection so you would need to write some code yourself to get a list of 5 random distinct numbers to use in the \makeset macro of that package (see the manual on page 6). – Marijn Nov 05 '22 at 15:06
  • See also https://tex.stackexchange.com/questions/346260/display-item-list-in-sequential-and-random-without-repetition-order – John Kormylo Nov 05 '22 at 15:59

0 Answers0