Randomizer options

Alejandro Gonzalez Recuenco

2024-01-23

Introduction to the engine

The examrandomizer engine, examrandomizer.engine, and the examrandomizer script that it requires can be found in the exec/ folder of this library. You first will need to copy the examrandomizer script in a folder found by your $PATH.

system.file("exec", package = "TexExamRandomizer")
## [1] "/private/var/folders/f9/gx8nkt0j6kgcwslqj681v8jw0000gp/T/Rtmp3qkaKd/Rinst10a993d21e2d0/TexExamRandomizer/exec"

As described on the Basic use vignette, the engine is a wrapper of the functions CreateRandomExams and GenerateHomework. It simply allow you to also write options directly in the document for those functions directly on the ‘LaTeX’ document by invoquing json-like options.

In essence, within the first two hundred lines it searches for tags TexExamRandomizer:

%! TexExamRandomizer = {"optionname0" : "optionvalue0", "optionname1" : "optionvalue1", ...}

Note a few things:

  1. A TexExamRandomizer tag must be just one line. However, you can have multiple lines displaying a range of options for each of them
  2. Double quotes are mandatory

As an overview of how it might look with a complete set of options. The options I usually use are:

    %! TexExamRandomizer = {"noutput":3, "nquestions": 13}
    %! TexExamRandomizer = {"table":"TestClass.csv"}
    %! TexExamRandomizer = {"randominfo": {"randomnumber":1000, "parity":["even", "odd"]}}
    %! TexExamRandomizer = {"extrainfo":{"class":"Class"}}
    %! TexExamRandomizer = {"extrainfo":{"rollnumber":"Roll Number","nickname":"Nickname"}}

In the preamble it requires the following \newcommand definitions. In each exam that it generates, it will be changed accordingly to the options given.

    \newcommand{\randomnumber}{r1--1000} % Will be replaced by a number between 1 and 1000
    \newcommand{\parity}{evenorodd} % Will be replaced by the word "even" or the word "odd"
    \newcommand{\class}{classholder}
    \newcommand{\rollnumber}{rollnumber}
    \newcommand{\nickname}{StudentNickname}
    \newcommand{\myversion}{0} % This will be replaced by the version number
    \newcommand\rseed{seed} % This will be replaced by the seed used in R to seed the randomization process

Don’t worry if you don’t understand yet how you specify these options yet, that is going to be explained below.

Specifying options

These options relate to the executables that are provided in the exec\ folder.

To describe the options, I will distinguish between options that can also be altered through the command line and those that can’t. I will write the name of the option preceded by “-” or “--” if they are command line options, while they will be in double quotes if the option can be written with a TexExamRandomizer tag within the document.

To give options through the command line interface, you must specify first the option name and then the value, for example --file filename.tex

Keep in mind that options given to the terminal have priority over options written in the document itself.

Command-line-only options

All these options are defaulted to false unless they are given.

General options

Personalizing a document

If a table is specified, either through the command line with --table or through the document with a “table” option, note that each row on the table will represent a student.

With that, I mean that the personalization will occur for every row on the table. Therefore, if the number of versions that you specified is 3, and there are 20 rows, the program will try to distribute the rows more or less evenly between the number of versions that were specified. But it will still customize each and every one of the version according to the settings given here.

How the personalization is done

We rely in using ‘LaTeX’ macros to personalize documents. We search within the preamble for newcommand tags,

 \newcommand{\commandname}{commandvalue}

And once found, we change the command value to the new personalized value. A common use would be, for example, personalizing the document with a name by writing the following macro

\newcommand\Name{TestName}

An once personalization occurs, each version will replace the \Name command value for the value required for each version.

Note that if you don’t want the engine to modify the macro you are using, you can instead of using \newcommand, you could use \newcommand* or \def . The asterisk * has a special meaning in ‘LaTeX’, but with the simple use that we are giving this commands, that can’t have options, that is irrelevant..

Reserved command names

The following commands names are reserved names, that you can overwrite, but I would recommend you not to.

Instead, simply add always the next two lines in your document

\newcommand\rseed{0}
\newcommand\myversion{0}

Document options

So, how do you add your own commands to be personalized you might ask?

There are two types of information that you might want to add to personalize each individual document.

Random information

Random information will be added in the document by adding the option "randominfo". The format in the document will be as follows

!% TexExamRandomizer = {"randominfo": {"<commandname>": <integer>, "<commandname2>" : <integer> ...}}

It will try to find commands of the type \newcommand{\commandname}{??} and replace them with \newcommand{\commandname}{randint}. Where the random integer that will be chosen will be a number between 1 and the <integer>.

If on the other hand, you want the value of the command to be chosen between a list of values, you can instead write

"<commandname>" : ["value1", "value2", "value3"]

And the program will choose randomly between one of those values.

The most useful way to use this option, in my opinion, is just to generate one numbe from which to seed the pgf/TikZ random seed, and then use native tools in ‘LaTeX’ to randomize anything you want. In that way you have much more control, however, for some people it might be more comfortable and more clear to specify it directly in the tags.

Extra information.

Extra information can be added in the document with the option "extrainfo" as follows

!% TexExamRandomizer = {"extrainfo": {"<cmdName>":"<columnName>", "<cmdName>":"<columnName>", ...}}

It works similarly to how adding random information works. However, instead of specifying the values from which to choose, we are instead specifying a column name in the table from which to gather the information. (Look at the “table” option to see how you can suggest a table to the program). For each row, it will choose the corresponding value and replace in the tex document the values of

\newcommand\cmdName{Testname}

to instead use

\newcommand\cmdName{<vale row i of column columnName>}

Naming columns with spaces and punctuation marks.

Keep in mind that we are still using R, which modifies the name of the column (It really dislike spaces and certain symbols). Therefore, to prevent having confusing behaviour, I decided to simply remove all punctuation marks and spaces. Therefore, punctuation marks and spaces will be ignored both on tags “extrainfo” and on the column names on the “table” provided.

Examples.

The following examples show some sets of options for different characteristics.

Three layers document with table info

%! TexExamRandomizer = {"noutput": 5}
%! TexExamRandomizer = {"table":"TestClass.csv"}
%! TexExamRandomizer = {"extrainfo":{"Class":"class", "Roll Number":"rollnumber","Nickname":"nickname"}}

%! TexExamRandomizer = {"layercmd":["section", "question", "(choice|CorrectChoice)"]}
%! TexExamRandomizer = {"layernames":["document", "questions", "choices"]}
%! TexExamRandomizer = {"reordersections":[true, true, false]}
%! TexExamRandomizer = {"reorderitems":[false, true, true]}

Exam class with 6 sections, choosing a few questions for each section.

%! TexExamRandomizer = {"noutput":2, "nquestions": [2,3,3,3,1,1]}
%! TexExamRandomizer = {"randominfo": {"randomnumber":100, "switchnumber":["even", "odd"]}}

Fixing position of sections and questions. Randomizing only the choices for each question.

%! TexExamRandomizer = {"noutput":2}
%! TexExamRandomizer = {"randominfo": {"randomnumber":100000000, "switchnumber":["even", "odd", "stop"]}}
%! TexExamRandomizer = {"reordersections":[false, false], "reorderitems":[false, true]}
%! TexExamRandomizer = {"table":"TestClass.csv"}
%! TexExamRandomizer = {"extrainfo":{"Class":"class", "Roll Number":"rollnumber","Nickname":"nickname"}}