My question
How do I handle the extraction of the .tex
file (as described below) to a flat .csv
with format below ?
Posted here originally
Context
I created all my MCQ with the exam
package. However, exams are now 100% online… (sigh)
My LaTeX file has the basic following format
I need now to provide a csv where the questions of the MCQ above would be displayed like (Incorrect
,Correct
, just to be clear 😃 )
question,answer1,Cor/Inc,answer2,Cor/Inc,answer3,Cor/Inc ,answer4,Cor/Inc,answer5,Cor/Inc
And it would render like
What is the answer ?,70,Inc,75,Inc,80,Inc,85,Cor,None of the above,Inc
Each line would obviously be a new question.
What could correspond so far
I found something interesting in python, but I am more open to a solution than a type of programming.
I see the principle for environment between \begin and \end thanks to https://stackoverflow.com/questions/11054008/extract-figures-from-latex-file
Where I am stuck The recurisivity to test first \begin{questions}
then \question
then \begin{oneparchoices}
then \choice
or \CorrectChoice
This code’s very messy, and only parses TeX in the very specific format you’ve provided, and won’t always give you errors if the input document is “malformed”, but it should work:
If you have pip
, and can install the TexSoup
package (pick one):
xxxxxxxxxx
> py -3 -m pip install TexSoup
$ python3 -m pip install TexSoup
$ python -m pip install TexSoup
then this would probably be more resilient to TeX formatting changes, but needs to load the entire file into memory so wouldn’t work for as large quizzes.