Introduction

The package RndTexExams builds random tests using R and latex. The R code will take as input a latex file and randomly define, for all of the multiple choice questions, the order of the questions, the order of the answers, and the correct answers. The user can also change the content of the questions in each version.

The main target audience of this code is composed of teachers and instructors that are considering minimizing cheating in their exams. Based on this package and a database of questions, one can build an unique test and answer sheet for each student in the class, therefore making it nearly impossible to cheat by looking around.

The code is built around the stable framework of examdesign. Users that are not familiar with LaTeX or examdesign, I strongly advice to read the manual before using RndTexExams.

How to use RndTexExams

Before you start to use

In order to use RndTexExams you will need the install latex. You have two choices, miktex and texlive.

Both are good choices and should work well with RndTexExams.

How to write questions with examdesign and RndTexExams

In examdesign, the multiple answer part of the test will be encapsulated by commands \begin{multiplechoice} and \end{multiplechoice}. Within this environment, all questions will begin with \begin{question} and end with \end{question}. The multiple answers of the questions are marked as \choice{}.

Next I show an example of a question in examdesign:

% Example of a multiple choice question in examdesign (only one version)
% The preamble and the rest of the document are ommited for simplification. 
% Be aware that this simple code as it is will NOT compile in pdflatex as it needs other parts

\begin{multiplechoice}[resetcounter=no,  examcolumns=1]

\begin{question}
    
    Given the next five options, which on is the correct answer?
    
    \choice{Choice 1}
    \choice{Choice 2}
    \choice{Choice 3}
    \choice{Choice 4}
    \choice[!]{Choice 5 - The CORRECT answer!}
    
\end{question} 

\end{multiplechoice}

Notice from this simple example that each question has a main text and choices. The right answer of the question is marked with the symbol [!] as in \choice[!]{text of answer here}. The right answer for each question can be later used to build a version of the test with the correct answers for all questions. The option for printing the answer sheet is very useful for grading. You can easilly switch it in the latex file by using the command \NoKey.

Changing the text between versions

The package RndTexExams uses switches with specific symbols in order to define parts of the questions that can change in between versions. Any change in the text, whether it is in the main text of the question or text of the answers, is marked with symbol @{text in ver 1}|{text in ver 2}{text in ver 3}@.

Making it clear, each version of the test will show the text according to its position. So, in version one it will show the text text in ver 1, in version two it will show the text text in ver 1 and so on. The version of the content changes every time that R and LaTeX compiles a new test.

Since we are changing the text of the questions and answers, it is also necessary to change the correct answers in each version. To do this, simply add the symbol [x] in the text of the answers, where x is the version in which the alternative is correct.

As an example, we can make different versions of the previous example question by using the following latex code with RndTexExams:

% Example of multiple choice question in examdesign, with 2 versions
\begin{multiplechoice}[resetcounter=no,  examcolumns=1]

\begin{question}
    
    Given the next five options, which is the correct answer in @{version 1}|{version 2}@?
    
    \choice{Choice 1}
    \choice{[2] Choice 2 - @{incorrect in version 1}|{correct in versin 2}@ }
    \choice{Choice 3}
    \choice{Choice 4}
    \choice{[1] Choice 5 - @{correct in version 1}|{incorrect in version 2}@ }
    
\end{question} 

\end{multiplechoice}

And thats it! Once you have your questions with the proper syntax for using with RndTexExams, all you need to do is to pass the tex file to function rte.analize.tex.file. In the next example we are going to use an example latex file from the package:

library(RndTexExams)


# Get latex file from package
f.in <- system.file("extdata", "MyRandomTest.tex", package = "RndTexExams")

# Breakdown latex file into a a list 
list.out <- rte.analize.tex.file(f.in,
                                 latex.dir.out = 'latexOut',
                                 pdf.dir.out = 'PdfOut') 
## 
## rte: Changing LaTeX file into dataframe... Done
# Options for build.rdn.test
list.in <- list.out       # output from rte.analize.tex.file
f.out <- 'MyRandomTest_'  # pattern for names of pdf
n.test <- 10              # number of random tests 
n.question <- 3           # number of questions in each test
pdf.dir.out <- 'PdfOut'   # directory for output

# Builds pdfs
out <- rte.build.rdn.test(list.in = list.in,
                          f.out = f.out,
                          n.test = n.test,
                          n.question = n.question,
                          pdf.dir.out = pdf.dir.out) 
## 
## rte: Checking for error in inputs... Done
## rte: pdflatex flavor: texlive
## rte: Type of OS: Linux
## rte: Building Test #1...Done
## rte: Building Test #2...Done
## rte: Building Test #3...Done
## rte: Building Test #4...Done
## rte: Building Test #5...Done
## rte: Building Test #6...Done
## rte: Building Test #7...Done
## rte: Building Test #8...Done
## rte: Building Test #9...Done
## rte: Building Test #10...Done
## rte: FINISHED - Check folder PdfOut for pdf files

The function rte.analize.tex.file will analyze the tex file and produce a R list with all of the details of the latex code. I encourage the user to open the resulting list to see how all of the code is broken down into pieces.

The function rte.build.rdn.test will use the list to produce the pdf files by calling pdflatex.exe in order to compile the resulting latex files.

Getting started on your own test

The easiest way to get started on your own test is to use my example tex file and change it to your needs. Do notice that some parts of the tex file are essential to RndTexExams. You can check these lines in the the comments of the example LaTeX file.

Copy and paste the contents of the link into a new tex file, which we will assume is called MyRandomTest.tex. You can also download the gist file in R using:

setwd('Your path goes here')
download.file(url = 'https://gist.github.com/msperlin/ef1b93a8eb9026ba5e9a/raw/MyRandomTest.tex', destfile = 'MyRandomTest.tex' )

Once you have the LaTeX file, run the following script to build 5 random tests, each with 3 questions:

library(RndTexExams)

my.d <- 'Your folder to the tex file here!'
setwd(my.d)

f.in <- 'MyRandomTest.tex'
f.out <- 'RandomTest-'
n.test <- 5
n.question <- 3
latex.dir.out <- 'latexOut'
pdf.dir.out <- 'PdfOut'

list.out <- rte.analize.tex.file(f.in,
                                 latex.dir.out = latex.dir.out,
                                 pdf.dir.out = pdf.dir.out)
                                 
out <- rte.build.rdn.test(list.in = list.out,
                          f.out = f.out,
                          n.test = n.test,
                          n.question = n.question,
                          latex.dir.out = latex.dir.out)                                 

The five pdf files named RandomTest-1.pdf, RandomTest-2, and so on should be now available in folder pdfOut.

Some advices