Guide
sortes makes exams from a question bank.
You write the bank and the exams in Typst and preview them in your editor.
sortes build picks each exam’s questions, shuffles them into versions whose answer letters are spread evenly, and renders the print and solution PDFs.
It remembers what it drew, so rebuilding an exam gives the same exam, and later exams avoid questions you already used.
Install
Section titled “Install”With Homebrew, which also installs Typst:
brew install wiseodd/tap/sortesOr install Typst and uv, then:
uv tool install sortessortes runs on macOS (Apple silicon) and Linux (x86, ARM). On Windows, use WSL.
Quickstart
Section titled “Quickstart”# Create a coursesortes init examscd exams
# Create a termsortes term <term>
# Write an exam, e.g. <term>/<exam>.typ, see belowsortes build <term>/<exam>.typThe command init creates the course: bank.typ with a few example questions, and typst.toml.
Typst package
Section titled “Typst package”The bank and the exams import the sortes Typst package from Typst Universe as @preview/sortes:0.1.0.
Typst downloads it the first time it compiles a file that imports it.
Writing and previewing the bank needs only the package, not the sortes command.
A TA can work on bank.typ in any Typst editor, including the Typst web app; the preview shows every question with its ID and the right answers marked.
See bank.typ for an example.
Write the bank
Section titled “Write the bank”The bank is one Typst file, bank.typ:
#import "@preview/sortes:0.1.0": *
= Supervised Learning and Regression <regression>
#q(<supervised-def>)[ What is supervised learning? - Minimizing a function given data - #correct[Approximating the function $bold(x) |-> y$ from labeled data] - Learning without labels]
#q(<outlier-fix>)[ A handful of extreme outliers dominate a least-squares fit. A principled fix is to: - Remove the bias term from the model - Increase the learning rate - #correct[Replace the Gaussian likelihood with a Laplace likelihood] #why[Absolute errors grow linearly, so outliers pull less on the fit.]]
#q(<normal-eq-shape>)[ $bold(X)$ has $N$ rows and $D$ columns. What is the shape of $bold(X)^top bold(X)$? #blank(expect: [a *shape*])[$D times D$]]
#q(<normal-eq-derive>, points: 4)[ Derive the normal equation for linear regression. #answer(height: 5cm)[Set the gradient of the squared error to zero and solve for $bold(theta)$.]]A question is #q(<id>)[...] and has one of three answer types, as on Gradescope:
- Choices: a list of 2 to 5 choices, with the right one wrapped in
#correct[...]. Several#correctchoices make a multi-select question. - One line: the
#blank[...]command holds the model answer. Students write on a single line, labeled with what to write inexpect. - A box:
#answer[...]holds the model answer. The answer box’s height can be specified.
The command #why[...] is an explanation that only shows in the solution PDFs.
A heading with a label, like = Regression <regression>, starts a section.
Exams draw questions from sections.
If a question that an exam used comes back under a new ID with exactly the same text, the build stops.
If your course has a file of math macros, import it at the top of bank.typ as usual:
#import "@preview/sortes:0.1.0": *#import "math_commands.typ": *The questions keep the bank’s macros in every exam.
Import the file in an exam, as "../math_commands.typ", only if the exam’s own text uses them.
See the reference for options.
Make an exam
Section titled “Make an exam”An exam is a Typst file in a term directory. It uses your own template. sortes only prints the questions; the page, the header and the cover are yours.
#import "@preview/sortes:0.1.0": *
#show: sortes.with( bank: include "../bank.typ", lock: json("sortes.lock"), title: "Midterm", date: "2026-11-20", versions: 2, points: 20,)
#align(center)[ #text(size: 1.6em, weight: "bold")[Midterm] \ Version #version() #if solution() [· Solutions]]
= Supervised Learning and Regression#pick(<supervised-def>)#draw(<regression>, 3)
= Maximum Likelihood and Classification#draw(<classification>, 4, min: (compute: 1))
= Written#pick(<normal-eq-derive>)Explanation:
#draw(<regression>, 3): randomly draw 3 questions from the section<regression>.min: (compute: 1): randomly draw, with at least one of them ofkind: "compute".#pick: puts specific questions in the exam, i.e., no randomness. Note that for MCQs, their choices are still shuffled.points: 20: exam’s total points.- Questions’
pointsare preserved if specified in the bank. The rest evenly share the points left.
- Questions’
date:is the day of the exam.- It is important for after the exam, see below.
version(),solution()andsummary()are useful functions to use in your own template.- If your template has a heading or cover page that shows the number of questions or points, use
summary(): your template’s own counters can’t see the questions sortes prints. - See the reference.
- If your template has a heading or cover page that shows the number of questions or points, use
To use a template you already have, apply it first, then sortes:
#import "@preview/sortes:0.1.0": *#import "../template.typ": exam
// Your own template#show: doc => exam(doc, title: [Midterm], course: [ML 101])
// sortes#show: sortes.with( bank: include "../bank.typ", lock: json("sortes.lock"), title: "Midterm", versions: 2, points: 20,)Your template can take the title and date from summary() instead of repeating them.
Suppose you have term F2026 and inside you have created a midterm. Then you build it via:
sortes build F2026/midterm.typThe first build draws the questions and writes them to F2026/sortes.lock.
For every version, it shuffles the order of the drawn questions and of their choices.
Across a version, the right answers are spread evenly over the letters, with no letter more than 3 times in a row.
The build also renders the print PDFs and the -sol PDFs into F2026/PDFs/.
The -sol PDFs are your answer key, e.g. for Gradescope.
Building again won’t change the drawn question IDs, but you can change/adjust the questions drawn in the bank. So you can fix the bank and the template and rebuild as often as you like.
The reference lists what each kind of edit does.
Commit sortes.lock with the exams.
It is the record of what each exam contains.
Each term gets its own directory in the course:
sortes term W2027Within a term, exams never draw the same question.
Questions from past terms can appear in the current term.
The option repeats: caps the expected number of repeats, 10% by default.
Only the last 2 terms count, so questions from older terms are fresh again; memory: changes how many.
The build avoids the newest past exam’s questions first, then the next newest, only as far as it needs to stay under the cap.
So the questions you used most recently are the last to come back, and once the bank is used up, the oldest come back first.
The reference explains how repeats are counted.
Once the next term starts, the earlier terms are frozen. Nothing in them changes, not even the answer key of a given exam.
After the exam
Section titled “After the exam”After the exam’s date, the exam is given.
A given exam can’t be drawn again.