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.
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.
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
.
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.
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
.
Always compile the source LaTeX files before using RndTexExams. This will help you to catch syntax problems. If the tex file is not compilable, R will thrown an error.
Since each test will have its own pdf, it might be best to combine them into one pdf for easier printing. You can use pdftk for that.
The package will not modify any question outside of the multiple choice enviroment of the latex file. In the future I might address this issue by also alowing for the randomization of other types of questions besides multiple choice.
By default, examdesign prints the answer sheet of each test. So, if you don’t need it, simply add \NoKey
in the preamble of the latex file (see example file for details)
Grading is also easy with RndTexExams. One of the outputs of mrt.build.rdn.text()
is the answer sheet of all tests. You can grade all tests using R by building a Google form and sending the link to the students at the day of the test (I usually write in the whiteboard so that only those that came to the test can access it). With their smartphones they can fill 1) Name and card, 2) the number of their test and 3) their answers in all questions. Once they fill in the form, I access the resulting spreadsheet in the cloud by using googlesheets, use a partial matching algorithm from the stringdist) package for comparing the name of the students in the test against the official names from the university system. After that, all you need to do is to compare the answer sheet of each student against the correct answers for the specific version of the test that he/she took. The results come out in less than a second, saving me around five hours of boring, tedious, dehumanizing grading work.