rte.analyze.tex.file: Analyze a LaTeX file and convert it into a list

Description Usage Arguments Value Examples

Description

This function will take as input a LaTeX file and break its components into a single R List. The class of the latex file should be either exam or examdesign. The code identifies the latex class automatically.

Usage

1
2
rte.analyze.tex.file(f.in, latex.dir.out = "latexOut",
  pdf.dir.out = "PdfOut")

Arguments

f.in

The latex file with the exam

latex.dir.out

The name of the folder where the files from the latex compilation should go (will create if not found)

pdf.dir.out

The name of the folder where the pdf from the latex compilation should go (will create if not found)

Value

A list that represents the tex file with preamble, questions, answers and more. This list is later used by function rte.build.rdn.text

df.questions

A data.frame with all questions

df.answers

A data.frame with all answers

my.begin.mchoice.line

text with beggining of mchoice enviroment

my.preamble

preamble of tex file, including everything before the beggining of the multiple choice enviroment

my.last.part

All of the tex code after the end of the multiple choice enviroment

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
latex.dir.out <- 'latexOut' # Name of folder where latex files are going
                            #(will create if it does not exists)

pdf.dir.out <- 'PdfOut'     # Name of folder where resulting pdf files are going

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

# Break latex file into a R list
list.out <- rte.analyze.tex.file(f.in,
                                latex.dir.out = latex.dir.out,
                                pdf.dir.out = pdf.dir.out)

print(list.out)

Example output

Loading required package: CopyDetect
Loading required package: irtoys
Loading required package: sm
Package 'sm', version 2.2-5.4: type help(sm) for summary information
Loading required package: ltm
Loading required package: MASS

Attaching package: 'MASS'

The following object is masked from 'package:sm':

    muscle

Loading required package: msm
Loading required package: polycor

rte: Changing LaTeX file into dataframe... Done$df.questions
  n.question idx.begin idx.end
1          1         3      17
2          2        19      43
3          3        46      60
4          4        63      84
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              q.text
1                                                                                                                                                                                                                                                                                                                                                                      \\begin{question}\n\n\tWhich one is the correct answer in the next five alternatives?\n\n\t\\choice{Choice 1}\n\n\t\\choice{Choice 2}\n\n\t\\choice{Choice 3}\n\n\t\\choice{Choice 4}\n\n\t\\choice[!]{Choice 5 - CORRECT}\n\n\\end{question}
2                                                                          \\begin{question}\n\n\tConsider the following statements:\n\n\t\\begin{enumerate}[I]\n\t\t\\item The color of the sky is generally @{blue}|{red}@\n\n\t\t\\item R has a @{high}|{low}@ number of packages for empirical research in Finance\n\n\t\t\\item Microsoft word is @{better}|{worse}@ than latex for creating structured documents\n\t\\end{enumerate}\n\n\tAre correct:\n\n\t\\choice{[1] I and II}\n\n\t\\choice{II and III}\n\n\t\\choice{I, II and III}\n\n\t\\choice{[2] Only III}\n\n\t\\choice{Only I}\n\n\\end{question}
3 \\begin{question}\n\n\tWhich of the next answers do you think is the correct one? (there are three versions of this question. This is version @{1}|{2}|{3}@)\n\n\t\\choice{Choice 1 - Incorrect in all versions}\n\n\t\\choice{[1] Choice 2 - @{Correct in version 1}|{Incorrect in version 2}|{Incorrect in version 3}@}\n\n\t\\choice{[3] Choice 3 - @{Incorrect in version 1}|{Incorrect in version 2}|{Correct in version 3}@}\n\n\t\\choice{Choice 4 - Incorrect in all versions}\n\n\t\\choice{[2] Choice 5 - @{Incorrect in version 1}|{Correct in version 2}|{Incorrect in version 3}@}\n\n\\end{question}
4                                                                                                          \\begin{question}\n\n\tConsider the following statements:\n\n\t\\begin{enumerate}[I]\n\t\t\\item Latex is @{good}|{bad}@ for structured documents\n\n\t\t\\item Working with R and latex is a @{good}|{bad}@ choice for writing up and marking tests\n\n\t\t\\item We @{love}|{hate}@ R\n\n\t\\end{enumerate}\n\n\tWhich statements are true?\n\n\t\\choice{I e II}\n\t\\choice{[1] I, II e III}\n\t\\choice{Only III}\n\t\\choice{I e III}\n\t\\choice{[2] None of the other options}\n\n\\end{question}
                                                                                                                                                                                                                                                                                                                                                                              main.text
1                                                                                                                                                                                                                                                                                             \\begin{question}\n\n\tWhich one is the correct answer in the next five alternatives?\n\n
2 \\begin{question}\n\n\tConsider the following statements:\n\n\t\\begin{enumerate}[I]\n\t\t\\item The color of the sky is generally @{blue}|{red}@\n\n\t\t\\item R has a @{high}|{low}@ number of packages for empirical research in Finance\n\n\t\t\\item Microsoft word is @{better}|{worse}@ than latex for creating structured documents\n\t\\end{enumerate}\n\n\tAre correct:\n\n
3                                                                                                                                                                                                                      \\begin{question}\n\n\tWhich of the next answers do you think is the correct one? (there are three versions of this question. This is version @{1}|{2}|{3}@)\n\n
4                                     \\begin{question}\n\n\tConsider the following statements:\n\n\t\\begin{enumerate}[I]\n\t\t\\item Latex is @{good}|{bad}@ for structured documents\n\n\t\t\\item Working with R and latex is a @{good}|{bad}@ choice for writing up and marking tests\n\n\t\t\\item We @{love}|{hate}@ R\n\n\t\\end{enumerate}\n\n\tWhich statements are true?\n\n

$df.answers
   n.question
1           1
2           1
3           1
4           1
5           1
6           2
7           2
8           2
9           2
10          2
11          3
12          3
13          3
14          3
15          3
16          4
17          4
18          4
19          4
20          4
                                                                                                                                                                                                                                                                                                                                                                                                         main.text
1                                                                                                                                                                                                                                                                                                                  \n\\begin{question}\n\n\n\n\tWhich one is the correct answer in the next five alternatives?\n\n
2                                                                                                                                                                                                                                                                                                                  \n\\begin{question}\n\n\n\n\tWhich one is the correct answer in the next five alternatives?\n\n
3                                                                                                                                                                                                                                                                                                                  \n\\begin{question}\n\n\n\n\tWhich one is the correct answer in the next five alternatives?\n\n
4                                                                                                                                                                                                                                                                                                                  \n\\begin{question}\n\n\n\n\tWhich one is the correct answer in the next five alternatives?\n\n
5                                                                                                                                                                                                                                                                                                                  \n\\begin{question}\n\n\n\n\tWhich one is the correct answer in the next five alternatives?\n\n
6  \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item The color of the sky is generally @{blue}|{red}@\n\n\n\n\t\t\\item R has a @{high}|{low}@ number of packages for empirical research in Finance\n\n\n\n\t\t\\item Microsoft word is @{better}|{worse}@ than latex for creating structured documents\n\n\t\\end{enumerate}\n\n\n\n\tAre correct:\n\n
7  \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item The color of the sky is generally @{blue}|{red}@\n\n\n\n\t\t\\item R has a @{high}|{low}@ number of packages for empirical research in Finance\n\n\n\n\t\t\\item Microsoft word is @{better}|{worse}@ than latex for creating structured documents\n\n\t\\end{enumerate}\n\n\n\n\tAre correct:\n\n
8  \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item The color of the sky is generally @{blue}|{red}@\n\n\n\n\t\t\\item R has a @{high}|{low}@ number of packages for empirical research in Finance\n\n\n\n\t\t\\item Microsoft word is @{better}|{worse}@ than latex for creating structured documents\n\n\t\\end{enumerate}\n\n\n\n\tAre correct:\n\n
9  \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item The color of the sky is generally @{blue}|{red}@\n\n\n\n\t\t\\item R has a @{high}|{low}@ number of packages for empirical research in Finance\n\n\n\n\t\t\\item Microsoft word is @{better}|{worse}@ than latex for creating structured documents\n\n\t\\end{enumerate}\n\n\n\n\tAre correct:\n\n
10 \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item The color of the sky is generally @{blue}|{red}@\n\n\n\n\t\t\\item R has a @{high}|{low}@ number of packages for empirical research in Finance\n\n\n\n\t\t\\item Microsoft word is @{better}|{worse}@ than latex for creating structured documents\n\n\t\\end{enumerate}\n\n\n\n\tAre correct:\n\n
11                                                                                                                                                                                                                                          \n\\begin{question}\n\n\n\n\tWhich of the next answers do you think is the correct one? (there are three versions of this question. This is version @{1}|{2}|{3}@)\n\n
12                                                                                                                                                                                                                                          \n\\begin{question}\n\n\n\n\tWhich of the next answers do you think is the correct one? (there are three versions of this question. This is version @{1}|{2}|{3}@)\n\n
13                                                                                                                                                                                                                                          \n\\begin{question}\n\n\n\n\tWhich of the next answers do you think is the correct one? (there are three versions of this question. This is version @{1}|{2}|{3}@)\n\n
14                                                                                                                                                                                                                                          \n\\begin{question}\n\n\n\n\tWhich of the next answers do you think is the correct one? (there are three versions of this question. This is version @{1}|{2}|{3}@)\n\n
15                                                                                                                                                                                                                                          \n\\begin{question}\n\n\n\n\tWhich of the next answers do you think is the correct one? (there are three versions of this question. This is version @{1}|{2}|{3}@)\n\n
16                                   \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item Latex is @{good}|{bad}@ for structured documents\n\n\n\n\t\t\\item Working with R and latex is a @{good}|{bad}@ choice for writing up and marking tests\n\n\n\n\t\t\\item We @{love}|{hate}@ R\n\n\n\n\t\\end{enumerate}\n\n\n\n\tWhich statements are true?\n\n
17                                   \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item Latex is @{good}|{bad}@ for structured documents\n\n\n\n\t\t\\item Working with R and latex is a @{good}|{bad}@ choice for writing up and marking tests\n\n\n\n\t\t\\item We @{love}|{hate}@ R\n\n\n\n\t\\end{enumerate}\n\n\n\n\tWhich statements are true?\n\n
18                                   \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item Latex is @{good}|{bad}@ for structured documents\n\n\n\n\t\t\\item Working with R and latex is a @{good}|{bad}@ choice for writing up and marking tests\n\n\n\n\t\t\\item We @{love}|{hate}@ R\n\n\n\n\t\\end{enumerate}\n\n\n\n\tWhich statements are true?\n\n
19                                   \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item Latex is @{good}|{bad}@ for structured documents\n\n\n\n\t\t\\item Working with R and latex is a @{good}|{bad}@ choice for writing up and marking tests\n\n\n\n\t\t\\item We @{love}|{hate}@ R\n\n\n\n\t\\end{enumerate}\n\n\n\n\tWhich statements are true?\n\n
20                                   \n\\begin{question}\n\n\n\n\tConsider the following statements:\n\n\n\n\t\\begin{enumerate}[I]\n\n\t\t\\item Latex is @{good}|{bad}@ for structured documents\n\n\n\n\t\t\\item Working with R and latex is a @{good}|{bad}@ choice for writing up and marking tests\n\n\n\n\t\t\\item We @{love}|{hate}@ R\n\n\n\n\t\\end{enumerate}\n\n\n\n\tWhich statements are true?\n\n
                                                                                             text.answer
1                                                                                   \t\\choice{Choice 1}
2                                                                                   \t\\choice{Choice 2}
3                                                                                   \t\\choice{Choice 3}
4                                                                                   \t\\choice{Choice 4}
5                                                                      \t\\choice[!]{Choice 5 - CORRECT}
6                                                                               \t\\choice{[1] I and II}
7                                                                                 \t\\choice{II and III}
8                                                                              \t\\choice{I, II and III}
9                                                                               \t\\choice{[2] Only III}
10                                                                                    \t\\choice{Only I}
11                                                      \t\\choice{Choice 1 - Incorrect in all versions}
12 \t\\choice{[1] Choice 2 - @{Correct in version 1}|{Incorrect in version 2}|{Incorrect in version 3}@}
13 \t\\choice{[3] Choice 3 - @{Incorrect in version 1}|{Incorrect in version 2}|{Correct in version 3}@}
14                                                      \t\\choice{Choice 4 - Incorrect in all versions}
15 \t\\choice{[2] Choice 5 - @{Incorrect in version 1}|{Correct in version 2}|{Incorrect in version 3}@}
16                                                                                    \t\\choice{I e II}
17                                                                           \t\\choice{[1] I, II e III}
18                                                                                  \t\\choice{Only III}
19                                                                                   \t\\choice{I e III}
20                                                             \t\\choice{[2] None of the other options}

$my.begin.mchoice.line
[1] "\\begin{multiplechoice}[resetcounter=no,  examcolumns=1]"

$my.preamble
[1] "\\documentclass[10pt]{examdesign} \n \n \n\\usepackage{amsmath} \n\\usepackage{graphicx} \n\\usepackage[utf8]{inputenc} \n\\usepackage{pifont} \n\\usepackage[english]{babel} \n\\usepackage{fancyhdr} \n\\pagestyle{fancy} \n\\usepackage{totpages} \n\\usepackage[margin=0.9in]{geometry} \n\\renewcommand{\\headrulewidth}{0.0pt} \n\\usepackage{framed} \n \n\\SectionFont{\\large\\sffamily} \n\\Fullpages \n\\ContinuousNumbering \n\\DefineAnswerWrapper{}{} \n\\NumberOfVersions{1} \n \n\\NoKey\t\t\t% Print key ? \n \n\\NoRearrange \t% Random arrange with latex? (leave it UNCOMMENTED, R will do all of the dirty work) \n \n\\newcommand{\\myversion}{} % this line is very important as it locates and allows the printed test to show the number of  the test (DONT DELETE IT) \n \n \n\\newcommand{\\UniName}{Name of my University}  \n\\newcommand{\\DeptName}{My Department}  \n\\newcommand{\\ClassName}{My Class Name}  \n\\newcommand{\\MyName}{Author: My name} \n\\newcommand{\\ExamName}{Exam Name: Version \\myversion} \n\\newcommand{\\TermName}{Current Term} \n \n\\rfoot{Random test \\# \\myversion} \n \n\\begin{document} \n \n\\begin{examtop} \n \n\\begin{center} \n    \\textbf{\\Large \\UniName} \\\\ \n    \\textbf{\\Large \\DeptName} \\vspace{0.5cm}  \\\\ \n    \\textbf{\\Large \\ClassName} \\\\ \n    \\textbf{\\Large \\MyName} \\\\ \n    \\textbf{\\Large \\ExamName } \\\\ \n    \\textbf{\\Large \\TermName} \n \\end{center} \n \n\\vspace{1cm} \nName: \\rule{4in}{.4pt}  \\quad  \\noindent Card:\\enspace\\hrulefill \n \n \n\\vspace{1cm} \n \n\\small \n \n\\begin{framed} \n \nInstructions for this test: \n \n\\begin{itemize} \n \n\t\\item Make sure you finish before the end of the exam time \n \n\t\\item There is only one correct answer in all multiple choice questions \n \n\t\\item Don't cheat! \n \n\\end{itemize} \n \n\\vspace{0.5cm} \n \n{\\large \\emph{Good Luck!}} \n\\end{framed} \n \n\\begin{framed} \n\tInstructions on how to use RndTexExams (DELETE THIS IN THE FINAL VERSION) \n\t\\begin{itemize} \n \n\t\t\\item The switch statements for the text of the questions, including main text and answers are defined as @{Text for version 1}|{Text for version 2}@. For each question, fell free to define as many versions as needed. \n \n\t\t\\item You can define the right answer in each version of the test by assigning the character [!] or [ver] in the right answer for version ver. See the rest of the file for examples. \n \n \n\t\\end{itemize} \n \n\\end{framed} \n \n\\end{examtop} \n \n \n\\vspace{1cm} \n"

$my.last.part
[1] "\n\n\\end{document}"

$examclass
[1] "examdesign"

RndTexExams documentation built on May 2, 2019, 6:10 a.m.