A package to export test questions into Moodle from python or latex
Project description
moodlexport
This Python module provides code which allows to easily generate families of questions (called categories in Moodle) that can be directly exported from either Python or Latex to Moodle, and use them to create a test. The main motivation behind this module is that :
- it is easier to define mathematical objects in Python than Moodle
- it is more comfortable to type maths in Latex
- generating random problems is simpler in Python and can go way beyond what Moodle proposes
- it is easier to store/manipulate locally a Latex or Python file than doing it on the Moodle interface. It also simplifies collaborating projects.
It can be installed with a pip command : pip install moodlexport
Some internal links within this documentation:
Main features of this module so far
- Creating a question. The only supported classes of questions are:
- "essay" : the student answers in a white text box.
- "multichoice" : the question comes with at least 2 possible answers.
- All the options available in Moodle are available here (defining a grade, information for the grader, feedback, etc). See more details below.
- Creating a category (family) of questions.
- Supports Unicode within python and latex : éà ê ...
- Supports Latex syntax in Moodle : correctly supports inline latex with
$e^x$, and equation with$$ f(x) = \sum_i x_i^2 $$, \begin{equation*}...\end{equation*}, \begin{cases}etc
Quick start
Simple examples from Python:
from moodlexport import Question
question = Question("essay")
question.text("What is the derivative of $f(x) = e^x + 0.5 \Vert x \Vert^2$?")
question.grade(1.5)
question.save("my first question")
Simple examples from Latex
You can produce the same result as above by defining your question directly in a Latex file.
Suppose for isntance that you have a Latex file myquestion.tex containing the following :
\documentclass{amsart}
\usepackage{latextomoodle}
\begin{document}
\begin{question}[essay]
What is the derivative of $f(x) = e^x + 0.5 \Vert x \Vert^2$?
\grade{1.5}
\end{question}
\end{document}
Then you can convert this myquestion.tex file directly into a readytoexport.xml file, by using the following Python commands:
from moodlexport import latextomoodle
latextomoodle('myquestion.tex','my first question')
Note that if you wish to compile the .tex file without errors, you will need to place the Latex package latextomoodle.sty in the same folder. This package can be found in the latex folder of this project.
Exporting many questions at once
If you want to export more than one question, you might want to gather them within a category, which will produce a single file containing all those questions. Here is how to proceed:
In Python:
from moodlexport import Question, Category
category = Category("My little catgory name")
question = Question("essay")
question.text("What is the derivative of $f(x) = e^x + 0.5 \Vert x \Vert^2$?")
question.grade(1.5)
question.addto(category)
question = Question("multichoice")
question.text("Is every symmetric matrix invertible?")
question.grade(2.0)
question.answer("Yes", False)
question.answer("No", True)
question.addto(category)
category.save()
In Latex, followed by the python command latextomoodle('file_name.tex') :
\documentclass{amsart}
\usepackage{latextomoodle}
\begin{document}
\begin{category}[My little catgory name]
\begin{question}[essay]
What is the derivative of $f(x) = e^x + 0.5 \Vert x \Vert^2$?
\grade{1.5}
\end{question}
\begin{question}[multichoice]
Is every symmetric matrix invertible?
\answer[0]{Yes}
\answer[100]{No}
\grade{2.0}
\end{question}
\end{category}
\end{document}
Documentation
Main commands
The Category Class
category = Category(string) creates an object of class Category. string here specifies the name of the category, which will appear in Moodle. It comes with a few methods:
category.save(string)creates an XML file under the XML Moodle format, ready to import within Moodle. The name of the file is the name of the category by default. If astringis given, the name of the file will bestring.xml.category.description(string)Adds a description to the category, which will appear in Moodle.
The Question Class
question = Question(type) creates an object of class Question. The type of the question can be essay (default) or multichoice. It comes with a family of methods question.OPTION(value) where OPTION describes every possible option that you can set in Moodle. The most important ones are:
question.title(string)sets the title of the questionquestion.text(string)sets the text (main body) of the questionquestion.grade(float)sets the grade of the quesitonquestion.graderinfo(string)sets the information to be given to the graderquestion.addto(category)adds the question to acategory
Methods specific to the essay type (answer via a text editor):
question.responseformat(string):editorfilepickerlets the student upload a file as an answer (default) ,editorforbids it.question.responserequired(bool):0if no response is required (default),1if a response is required.
Methods specific to the multichoice type (finite number of possible answers):
question.answer(string, value): Adds a possible answer to the question.stringis the text of the answer,valuedescribes if this answer is correct or no. It can be described in two ways:- as a boolean
TrueorFalse(default) - as a percentage (integer between 0 and 100), which represents the fraction of the grade attributed to the answer. This is typically used for questions with more than 2 answers. A unique true answer has 100, a wrong answer has 0 (default)
- as a boolean
question.single(value):trueif only one answer is possible (default),falseif more than one answer can be selected by the student.
Main commands in Latex (bêta)
It is possible to use a similar syntax within a TEX document :
\begin{category}[name] ... \end{category}defines the environment corresponding to a category. It is possible to write various categories within the same document.nameis the name of the category.\begin{question}[type] ... \end{question}defines the environment corresponding to a question. It is possible to write various question within the same category.typeis the type of the question,essayby default.- All the methods mentioned above can be used in latex. The analogue of
.OPTION(value)becomes\OPTION{value}in Latex (and must be placed within the corresponding environment). For instance :\description{string}sets the description of a category\grade{float}sets the grade of a question\answer[value]{string}adds an answer to a multichoice question
The corresponding latex package can be found in the latex folder.
Known issues/missing features
- for multichoice we never check that the sum of the fractions is equal to 100%
- for the latex package, there is issues with
newcommandandrenewcommandbecause for instance the document classamsartdefinestextbut it is not the case forarticle.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moodlexport-0.0.13.tar.gz.
File metadata
- Download URL: moodlexport-0.0.13.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b717dcab70ce216b1977b3b697b1989f303b28991ad0e748a1a595feabace91c
|
|
| MD5 |
0c0ca57bb5b18569602a514c341ac685
|
|
| BLAKE2b-256 |
4037463e3faf5de5f878db4c95118eb186eae4469ce15c35c81c866ee854497a
|
File details
Details for the file moodlexport-0.0.13-py3.7.egg.
File metadata
- Download URL: moodlexport-0.0.13-py3.7.egg
- Upload date:
- Size: 25.4 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88c0d6d5810266637b3063aad633cdfeb0c52bc47177dce4ef440a25d13d3ab8
|
|
| MD5 |
9d312be8f5f9c8abccd5721d1f352d14
|
|
| BLAKE2b-256 |
2b7c048635f39bcbf981a98edaeeb3fe7072db71ef2f5e08cd3267bab5b1ec51
|