Importing Quizzes to CANVAS using text2qti

David W. Agler
7 min readDec 17, 2022

--

Take your text files and convert them into Canvas quizzes.

Graphic that shows a text file with an arrow pointing to a square with the word “CANVAS” inside.
(img) Created by the author

I have a bunch of quizzes that I don’t want to rewrite in the learning management software (LMS) my university uses (CANVAS). Fortunately, there is a tool that allows you to take quizzes written in plain text, transform them into QTI files, and then import them into CANVAS. This is text2qti.

Step 1: Write Your Quiz

The quiz should be written in plain text (.txt file). Questions need to be formatted in a specific way. The documentation of text2qti provides a plethora of examples. Nevertheless, let’s consider some examples here. First, let’s consider a quiz consisting of two multiple-choice questions:

1. Is it possible for an argument to be invalid but have all true premises?
*a) Possible
b) Not possible

2. Is the following combination of PL symbols a PL wff: $(A\wedge B)$
... For an overview of the language of PL, see https://youtu.be/LeCwNLwoMkA?t=174
*a) Yes
b) No

Each question is numbered, answer choices used letters followed by a right parenthesis, and the correct answer is marked with an asterisk. The asterisk needs to come before the letter (I can’t tell you how many times I’ve put it in the wrong spot). We can add question-level feedback by using an ellipsis followed by the written feedback. Finally, LaTeX users will rejoice as mathematical expressions can be formatted in the typical way using the dollar sign $.

Second, there are some additional features that you can add to your quiz. For example, you can title the quiz Quiz title , give it a description Quiz description , give questions titles Title (although this only appears on the instructor side), specify the points of individual questions Points, give specific feedback if the question is right vs. wrong, and provide question-level feedback. Let’s illustrate all of these with the following example that uses a multi-select (multiple-answer) question. For this style of question, [] is used with an asterisk inside the square brackets [*]to indicate the correct answer.

Quiz title: A BIG QUIZ
Quiz description: You have 3 minutes to complete this quiz.

Title: An Easy Question
Points: 5
1. Does P=NP?
... Question level feedback.
+ Correct answer feedback
- Incorrect answer feedback.
[ ] Yes. It is obvious.
... Feedback for this answer.
[ ] No. It is obvious.
... Feedback for this answer.
[*] If I knew this, I'd be rich.
... Feedback for this answer.
[*] If you knew this, you wouldn't be a teacher.
... Feedback for this answer.

Here is how the feedback will look to a student who only selected the third but not the fourth answer.

(img) Created by the author

Third, text2qti allows for short-answer questions where students need to supply an answer. Accepted answers are marked with an asterisk.

Points: 3
1. Does God exist? Answer YES or NO.
* Yes
* YES
* yes

Finally, let’s consider one more quiz that consists of three questions: (1) a numerical question, (2) an essay question, and (3) a file-upload question.

Quiz title: A Three Question Quiz
Quiz description: You have 3 minutes to complete this quiz.

1. What is 100-99?
= 1

2. Please explain the entirety of Kant's <i>Critique of Pure Reason</i>.
... Feedback for all students.
____

3. Please upload your essay on Kant's <i>Critique of Pure Reason</i>.
... Feedback for all students here.
^^^^

Here is how the quiz questions will look when it is uploaded later (I typed in some dummy answers):

(img) Created by the author

Step 2: Install Python and text2qti

Next, we will need to convert our plain text quiz into a QTI zip file. Later, we import this QTI zip file into CANVAS. First, we need Python. If this is your first time installing Python, it may be helpful to watch a tutorial. Here are two tutorials:

  1. How to Install Python — The Right Way by Python Programmer.
  2. Python Tutorial for Beginners 1: install and Setup for Mac and Windows by from Corey Shafer

Second, we will need to install text2qti. To do this, I will use pip. To install, go to the search bar of the Windows tool bar, type cmd and hit Enter. Next, we need setuptools, although this may already be installed on your machine. You can check by typing pip list. If you do not see setuptools , then type the following:

pip install setuptools

This installs setuptools. Next, we will install text2qti :

pip install text2qti

With text2qti installed, we will look at a few different ways of creating a QTI zip file that will be imported to CANVAS. Let’s start with the simplest way.

Step 3.1: Simplest Case, Using the GUI

text2qti has a built-in GUI. To access it, again, type cmdor type “command prompt” to open up the command prompt. Once you are in the command prompt, type:

text2qti_tk

This will bring up the GUI:

(Screenshot) Created by the author

From here, we can upload our plain .txt quiz file, click RUN and a QTI zip file will be created. If your quiz uses LaTeX, you will need to enter the “LaTeX math rendering URL”. To find this, you will log into your institution’s CANVAS and find a link that looks something like this:

https://institution.instructure.com/equation_images/

Suppose my university was Napoleon Bonaparte Univesity (npu). My rendering URL would probably look like this:

https://npu.instructure.com/equation_images/

Alternatively, you can create the file without a LaTeX math renderer but you will need Pandoc installed. Assuming you don’t have any errors, the GUI should produce a QTI zip file. You can skip to step 4.

Step 3.2: Using the Command Prompt

Let’s create a quiz using the command prompt / line. Open up the command prompt by typing cmd or “Command Prompt” in the search bar of Windows. Next, navigate to the directory containing the quiz using cd. For example, my quiz is located in “test_folder” on my desktop, so I typed:

C:\Users\MY NAME>cd desktop\test_folder
C:\Users\MY NAME\Desktop\test_folder>

Now that you are in the directory that contains your quiz, type the following:

text2qti quiz_name.txt

text2qti will take quiz_name.txt and create the QTI zip file.

If this is the first time you are using text2qti, you may be prompted for a LaTeX rendering URL. See Step 3.1 for details. If you need to change your rendering URL in the future, you’ll need to open up the .text2qti.bespon file. It is typically located in the following folder: C:\Users\<UserName>

Assuming your quiz is formatted correctly, a QTI zip file will be created in the same folder that contains your quiz.

Step 3.3: Using an IDE

My preferred method for creating the QTI file is using an IDE (e.g. Visual Studio Code). In VSCode, I open the folder where my text quizzes are located. Next, I create a .py file. Let’s name ours “simple_test_creation.py”. In our new file, write the following:

import subprocess # needed to run cmd
subprocess.run(f'text2qti sample_quiz.txt') #f string

This will create a QTI zip file in the same folder.

Using the command line or your IDE, you can also specify options. Here are some of the most useful (for me at least).

[–latex-render-url LATEX_RENDER_URL] specifies the latex render URL you want to use. If I were to use the LaTeX render at my institution, I would write the following:

text2qti --latex-render-url https://psu.instructure.com/equation_images/ sample_quiz.txt

[–pandoc-mathml] will export the QTI file without the LaTeX render URL (you’ll need Pandoc):

text2qti --pandoc-mathml sample_quiz.txt

This is particularly useful if your institution’s LaTeX renderer has problem with more exotic symbols.

[–solutions SOLUTIONS_FILE] will export a solutions file (.html or .pdf) along with the QTI file. For example:

text2qti --solutions my_solutionspy.pdf sample_quiz.txt

[–only-solutions SOLUTIONS_FILE] will export the solutions file without the QTI file. For example:

text2qti --only-solutions mysolutions.pdf sample_quiz.txt

In the above examples involving solutions, text2qti will produce a PDF titled mysolutions.pdf containing the questions and correct answers. Here is the output of our earlier example containing one multi-select question.

(img) Created by the author

[–run-code-blocks] will allow you to run code to generate quiz questions and solutions. For example, consider the following quiz question:

import textwrap
for x in [1,2,3,4]:
print(textwrap.dedent(rf"""
1. What is {x}+{x}?
*a) ${x+x}$
b) ${x+x+x}$
"""))

Setting the -run-code-blocks option will generate four questions and their respective solutions.

text2qti --run-code-blocks sample_quiz.txt

Finally, let me show you my preferred usage. I generally use text2qti to add quiz questions into CANVAS and then use these questions to build quiz banks. I will create a .txt file for each bank and then I will need to convert the .txt file into a corresponding QTI zip file using text2qti. In many cases, I am working with dozens of .txt files. To transform all of these .txt files into QTI files, I will use glob as follows:

import subprocess
import glob
files = glob.glob("*.txt") # all txt files in directory
for file in files:
subprocess.run(f'text2qti {file} --solutions {file.replace(".txt",".pdf")}', shell=True)
# creates a QTI file and solutions pdf for each .txt in the folder

Step 4: Importing Your Quiz

The final step is to import your .zip QTI file into CANVAS. To do this, you do the following:

  1. Log into CANVAS and select your course
  2. Select Settings and then Import Course Content
  3. Under Content Type, select your created QTI .zip file as Source.

Your quiz should now be imported.

Resources

  1. text2qti by Geoffrey Poore and Glenn-Horton-Smith
  2. text2qti via pypi
  3. Installing Python Packages
  4. Installing Python by Corey Shafer

--

--

David W. Agler

Assistant Teaching Professor - Philosophy. I make logic and philosophy videos at https://www.youtube.com/@LogicPhilosophy