1

I'm writting a large exam using exam class. I want to create many versions (at least two) of the exam by permuting the questions. I think I had seen something like that in the user manual, but now I can't find it.

Originally I want to do that with a problem sheet with 100 questions. But an example could be the following:

\documentclass{exam}

\usepackage[utf8]{inputenc}
\usepackage[spanish,shorthands=off]{babel}
\usepackage{cmbright}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{calc, cd}

\newcommand{\n}[1]{\boldsymbol{#1}}

\theoremstyle{definition}
\newtheorem{ej}{Ejercicio}

\newcommand{\tq}{\;|\;}

\title{Conjuntos Abstractos}
\author{}
\date{}


\begin{document}

\maketitle

\begin{questions}
\question Demuestra que iso implica biyectiva.

\question Demuestra que la categoría $1/\mathcal{S}$ tiene todos los límites finitos. Los objetos de $1/\mathcal{S}$ son parejas $(A,a:1\to A)$, donde $A$ es un conjunto abstracto; y las flechas $f:(A,a:1\to A)\to(B,b:1\to B)$ son flechas entre conjuntos abstractos $f:A\to B$ que hacen conmutar al siguiente diagrama
\begin{center}
    \begin{tikzcd}
        & 1 \arrow[ld, "a"swap] \arrow[rd, "b"] \\
        A \arrow[rr, "f"swap] && B
    \end{tikzcd}
\end{center}

\question Demuestra que si una categoría $\n{C}$ tiene coproductos y coigualadores entonces tiene todos los colímites.

\question Demuestra que todo igualador es mono.

\question Sean \tikzcd[cramped, sep=small] U \arrow[r, rightarrowtail, "i"] & A \endtikzcd{} e \tikzcd[cramped, sep=small] V \arrow[r, rightarrowtail, "j"] & A \endtikzcd{} subobjetos de $A$. Diremos que $i$ es equivalente ($i\sim j$) a $j$ si $i\subseteq j$ y $j\subseteq i$. Demuestra que la relación $\sim$ es de equivalencia.

\question Sean $A$ un conjuntos abstractos y considera los conjuntos
\begin{gather*}
Sub(A)=\{\tikzcd[cramped, sep=small, ampersand replacement=\&] U \arrow[r, rightarrowtail, "i"] \& A \endtikzcd{}
         \tq \text{$i$ es mono}\}/\sim \\
\mathcal{S}(A,B)=\{f:A\to B\tq\text{$f$ es una flecha en $\mathcal{S}$}\}
\end{gather*}
Demuestra que hay una biyección $Sub(A)\cong\mathcal{S}(A,2)$.
\end{questions}

\end{document}

For the structure and the kind of text, it can be compiled using PDFLaTeX, PDFTeX, XeTeX,... If there is a good solution using a specific compilation method I can use it with no much trouble.

Does anyone knows how to do something like that?

Thanks in advance

4
  • Maybe this can help: tex.stackexchange.com/questions/379881/…
    – Skillmon
    Mar 18, 2018 at 19:14
  • Not sure if this is what I want. If I understand well probsoln can only help me if I want to make different problem sheets changing the set of questions, even selecting a subset randomly (this is nice). But what I want is to have the same questions in different order, so I think probsoln is not the solution I want, or maybe I'm missing some features of probsoln package? Mar 20, 2018 at 0:38
  • Can you please create a minimal working example (basically just a list of questions and stuff, I can play with). Please include all packages necessary to reproduce your code (most likely just the exam class). Perhaps I can hack me into something and provide what you need. Important question: Are you using XeTeX (or XeLaTeX) or another engine?
    – Skillmon
    Mar 20, 2018 at 7:31
  • I already edit the original question with an example (only 6 questions). Thanks for taking time @Skillmon Mar 20, 2018 at 16:34

1 Answer 1

2

The following does work. Note however that since the whole content of randomizedquestions is read by a macro, catcode changes which appear inside of the environment don't take effect. Because of that, e.g. tikzcd doesn't work without ampersand replacement.

The environment takes an optional argument which specifies how many questions you actually want to use. This way you can for example define 10 questions but use only 5. If the optional argument is greater than the actually defined questions all questions are used without any warning or error.

I hope this is of use for you (and sorry that you have to change all tikzcd code to use ampersand replacement if it doesn't already).

\documentclass{exam}

\usepackage[utf8]{inputenc}
\usepackage[spanish,shorthands=off]{babel}
\usepackage{cmbright}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usepackage{expl3}
\usepackage{environ}
\usetikzlibrary{calc, cd}

\newcommand{\n}[1]{\boldsymbol{#1}}

\theoremstyle{definition}
\newtheorem{ej}{Ejercicio}

\newcommand{\tq}{\;|\;}

\ExplSyntaxOn
\seq_new:N \l_luisturcio_questions_seq
\seq_new:N \l_luisturcio_indices_seq
\int_new:N \l_luisturcio_index_int
\int_new:N \l_luisturcio_questions_int
\tl_new:N \l_luisturcio_questions_tl
\tl_new:N \l_luisturcio_index_tl
\bool_new:N \l_luisturcio_loop_bool
\NewEnviron { randomizedquestions } [1][]
  {
    \luisturcio_sequence_questions:V \BODY
    \luisturcio_shuffle_questions:n { #1 }
    \luisturcio_create_questions_tl:
    \exp_args:Nno \begin{questions} \l_luisturcio_questions_tl \end{questions}
  }
\cs_new:Nn \luisturcio_sequence_questions:n
  {
    \seq_set_split:Nnn \l_luisturcio_questions_seq { \question } { #1 }
    \seq_remove_all:Nn \l_luisturcio_questions_seq {}
  }
\cs_generate_variant:Nn \luisturcio_sequence_questions:n { V }
\cs_new:Nn \luisturcio_shuffle_questions:n
  {
    \int_set:Nn \l_luisturcio_questions_int
      { \seq_count:N \l_luisturcio_questions_seq }
    \tl_if_empty:nTF { #1 }
      {
        \int_step_inline:nnnn
          { \l_luisturcio_questions_int } { -\c_one } { \c_one }
      }
      {
        \int_compare:nNnTF { \l_luisturcio_questions_int } > { #1 }
          {
            \int_step_inline:nnnn
              { \l_luisturcio_questions_int } { -\c_one }
              { \l_luisturcio_questions_int - #1 + \c_one }
          }
          {
            \int_step_inline:nnnn
              { \l_luisturcio_questions_int } { -\c_one } { \c_one }
          }
      }
      {
        \int_set:Nn \l_luisturcio_index_int { \int_rand:nn { \c_one } { ##1 } }
        \luisturcio_add_to_indices:
      }
  }
\cs_new:Nn \luisturcio_add_to_indices:
  {
    \bool_set_true:N \l_luisturcio_loop_bool
    \bool_do_while:Nn \l_luisturcio_loop_bool
      {
        \seq_if_in:NxTF \l_luisturcio_indices_seq
          { \int_use:N \l_luisturcio_index_int }
          {
            \int_incr:N \l_luisturcio_index_int
          }
          {
            \seq_put_right:Nx \l_luisturcio_indices_seq
              { \int_use:N \l_luisturcio_index_int }
            \bool_set_false:N \l_luisturcio_loop_bool
          }
      }
  }
\cs_new:Nn \luisturcio_create_questions_tl:
  {
    \tl_clear:N \l_luisturcio_questions_tl
    \bool_while_do:nn { ! \seq_if_empty_p:N \l_luisturcio_indices_seq }
      {
        \tl_put_right:Nn \l_luisturcio_questions_tl { \question }
        \seq_pop_right:NN \l_luisturcio_indices_seq \l_luisturcio_index_tl
        \tl_put_right:Nx \l_luisturcio_questions_tl
          {
            \seq_item:Nn \l_luisturcio_questions_seq { \l_luisturcio_index_tl }
          }
      }
  }
\ExplSyntaxOff

\title{Conjuntos Abstractos}
\author{}
\date{}


\begin{document}

\maketitle

\begin{randomizedquestions}
\question Demuestra que iso implica biyectiva.

\question Demuestra que la categoría $1/\mathcal{S}$ tiene todos los límites finitos. Los objetos de $1/\mathcal{S}$ son parejas $(A,a:1\to A)$, donde $A$ es un conjunto abstracto; y las flechas $f:(A,a:1\to A)\to(B,b:1\to B)$ son flechas entre conjuntos abstractos $f:A\to B$ que hacen conmutar al siguiente diagrama
\begin{center}
    \begin{tikzcd}[ampersand replacement=\&]
        \& 1 \arrow[ld, "a"swap] \arrow[rd, "b"] \\
        A \arrow[rr, "f"swap] \&\& B
    \end{tikzcd}
\end{center}

\question Demuestra que si una categoría $\n{C}$ tiene coproductos y coigualadores entonces tiene todos los colímites.

\question Demuestra que todo igualador es mono.

\question Sean \tikzcd[cramped, sep=small,ampersand replacement=\&] U \arrow[r, rightarrowtail, "i"] \& A \endtikzcd{} e \tikzcd[cramped, sep=small,ampersand replacement=\&] V \arrow[r, rightarrowtail, "j"] \& A \endtikzcd{} subobjetos de $A$. Diremos que $i$ es equivalente ($i\sim j$) a $j$ si $i\subseteq j$ y $j\subseteq i$. Demuestra que la relación $\sim$ es de equivalencia.

\question Sean $A$ un conjuntos abstractos y considera los conjuntos
\begin{gather*}
Sub(A)=\{\tikzcd[cramped, sep=small, ampersand replacement=\&] U \arrow[r, rightarrowtail, "i"] \& A \endtikzcd{}
         \tq \text{$i$ es mono}\}/\sim \\
\mathcal{S}(A,B)=\{f:A\to B\tq\text{$f$ es una flecha en $\mathcal{S}$}\}
\end{gather*}
Demuestra que hay una biyección $Sub(A)\cong\mathcal{S}(A,2)$.
\end{randomizedquestions}

\end{document}
4
  • This answer is very good! I have tried to understand all the code but I'm not smart enough to achieve that. Now I have another problem (not sure if I have to write it as a different question or edit this one), for some reason this randomizequestions doesn't work if the set of questions is greater than 70. That's why I try to understand the code, I wanted (with no luck) to see if some part of the code have this restriction. May 3, 2018 at 15:18
  • @LuisTurcio I have 154 questions and it's still working (though every questions beyond those you provided is \question foobar), what is your error message? Now I used copies of your questions. It still works with 384 questions, though compilation time is significantly longer.
    – Skillmon
    May 3, 2018 at 15:39
  • I'm so sorry is just as you said, if I use copies of my questions is still working with a large number of questions. So the problem is something I should be able to correct. Thank you for taking the time, and again I'm still impressed with the solution you provide. May 3, 2018 at 16:30
  • @LuisTurcio to debug you could at first create your questions' bodies outside of randomizedquestions, this way the error messages TeX shows should become more readable.
    – Skillmon
    May 3, 2018 at 17:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .