Mathematics (LaTeX and KaTeX)
Next Exams typesets mathematics in your questions with KaTeX, the fast LaTeX renderer, built into the extension. You write formulas in LaTeX, the notation maths teachers already use in Moodle, Overleaf and textbooks, and learners see them as printed maths: fractions, matrices, integrals, piecewise functions, vectors and Greek letters. There is nothing extra to install. You don't need a LaTeX plugin such as JaTeX or MathJax, or any outside service.
This page explains how to write maths in Next Exams, where it is shown, the settings that control it, and how to bring maths questions in from Moodle and other systems.

Writing a formula
Put LaTeX between delimiters anywhere in question text. Next Exams reads three kinds of delimiter, plus a fourth you can switch on:
| You type | Shown as | Example |
|---|---|---|
\( … \) |
Inline maths, inside the sentence | The order of \(\mathbf{PQ}\) is \(2 \times 4\). |
\[ … \] |
Display maths, centred on its own line | \[ \det\mathbf{M} = ad - bc \] |
$$ … $$ |
Display maths, centred on its own line | $$ \int_0^{\infty} \frac{1}{1+x^2}\,\mathrm{d}x = \frac{\pi}{2} $$ |
$ … $ |
Inline maths, only when the setting Read $…$ as inline maths is on | $x^2 + 1$ |
Some formulas that work as written:
\(\mathbf{A}^{-1} = \frac{1}{5}\begin{pmatrix}3 & -1\\ -2 & 1\end{pmatrix}\)
\[ \mathrm{f}(x) = \begin{cases} x^2 & x \geq 0 \\ -2x & x < 0 \end{cases} \]
\(|z + 1| \leqslant 2\), \(\arg(z - 2\mathrm{i}) = \frac{3\pi}{4}\)
\(\sum_{r=1}^{n} r^2 = \tfrac{1}{6}n(n+1)(2n+1)\)
\(\lim_{n \to \infty}\left(1 + \frac{1}{n}\right)^n = \mathrm{e}\)
KaTeX covers the maths of school and university courses: fractions and roots, matrices (pmatrix, bmatrix, vmatrix), cases, aligned, sums, integrals and limits, vectors and arrows, set notation, \mathbb, \mathrm, \text, Greek letters and accents. The full list is in KaTeX's own supported functions reference. KaTeX typesets maths, not whole LaTeX documents: packages (\usepackage), TikZ drawings and text tables are not supported. Use a picture for a diagram, see Images in questions.
The Insert math button
Every rich-text editor in Next Exams has an Insert math button (in the editor's toolbar, or under its ⋯ menu when the toolbar is narrow). Type the LaTeX without delimiters and check the live preview underneath. Insert puts the formula into the text wrapped in \( … \).

You can also type or paste delimiters straight into the editor. That is often quicker when you are copying formulas from an existing worksheet.
< and > inside a formula
Write the less-than and greater-than signs as you would anywhere else: \(x < 0\), \(a > b\), or x < 0 inside a cases block. Next Exams keeps them as written when the question is saved, from the editor, an import or the REST API. A < in ordinary text, such as "if x < 3", is kept too. \lt, \gt, \leq and \geq also work.
Before 6.4.0 a < was read as the start of an HTML tag and the rest of the text was cut off. If an older question lost its ending, edit it once or import it again.
Where maths is shown
Formulas are typeset wherever a learner or a marker reads question content:
- On the site: the exam page and its introduction, every question stem and answer option in the exam runner, reading passages, the feedback shown after Check answer in practice mode, the explanation, and the result page's answer review.
- In the administrator: the Exam Studio's question cards, and the question and explanation in the attempt view a marker grades from.
The question editor shows the LaTeX source, so it stays easy to change. To see a whole exam as learners will, press Preview in the Exam Studio.
Certificates (PDF) and emails do not typeset maths. Keep formulas out of exam titles and email subjects, and put them in the question text instead.
Feedback for each answer, with maths
Every option of a choice question can carry its own feedback, and that feedback may contain maths. In a practice exam that reveals answers per question, the learner picks an answer and presses Check answer. They see whether it is right, the feedback written for the option they chose, your explanation, and the correct answer when theirs was wrong. All of it is typeset.

This makes a practice quiz work like a worked revision sheet: a learner who picks a common wrong answer is told why it is wrong at the moment they make the mistake. The same feedback appears on the result page when the exam shows answers. See Practice mode.
Settings
Three switches control maths. The first is in the App Manager, the other two in Configuration → Settings → Taking modes.
| Switch | Default | What it does |
|---|---|---|
| Math Rendering (App Manager) | On | Typesets LaTeX everywhere listed above, and adds the Insert math button to the editors. Off: formulas show as their LaTeX source. Nothing is deleted. |
| Read $…$ as inline maths | Off | Also reads single dollar signs as inline maths, as Moodle and many LaTeX sources write it. Leave it off if your questions mention prices: with it on, "$5 and $10" would be typeset as a formula. \( \), \[ \] and $$ $$ work either way. |
| Run Joomla content plugins on question text | Off | Passes question text through your site's content plugins, as article text is. Not needed for maths: Next Exams typesets it itself. Leave it off unless you need a particular plugin inside questions. |

Use the built-in maths rather than a LaTeX content plugin such as JaTeX. With both, a formula would be processed twice, and the plugin's output is not what the learner's answer, the feedback and the result page are built from.
Importing maths questions
LaTeX in imported questions is kept as written and typeset like any other.
- Moodle XML is the best format for maths. Stems, answers, each answer's feedback and the general feedback are imported with their formulas. If your files use single dollars, switch on Read $…$ as inline maths.
- QTI 2.1 files exported from Next Exams import back unchanged.
- CSV and Aiken keep the text of each field as written.
- GIFT uses
{,},=,~and#as its own markers, and the Next Exams GIFT import reads them wherever they appear, including inside a formula. A question with\frac{1}{2}in its stem, or\(x = 2\)in an answer, does not import correctly from GIFT. Use Moodle XML for maths questions.
Tick Create a quiz for each category on the import preview to turn a file's categories into draft quizzes as well. A maths course exported from Moodle with one category per topic becomes one quiz per topic, or one per chapter with Parent category. See Import and export.
Speed, privacy and accessibility
- Loaded only when needed. KaTeX is most of the weight of the site's exam script, so it is downloaded only by pages that contain a formula. The exam catalogue and exams without maths never load it.
- Served from your own site. KaTeX and its fonts ship inside the extension, so no request goes to a CDN or any outside service. Only the WOFF2 fonts are included, the format every supported browser uses.
- Readable by screen readers. KaTeX writes each formula twice: once as the visual layout and once as MathML, which screen readers read aloud.
- Highlighting. In exams with parts, learners can highlight passages and question text. Highlights cover the words around a formula, never the formula itself.
Tips for writing maths questions
- Use
\(\)for maths inside a sentence and\[\]or$$for a formula on its own line. Keep one formula per pair of delimiters. - Write answer options as maths when the answer is maths:
\(2 \times 4\)reads better than "2 x 4", and learners see the same notation as in the stem. - Put the reasoning in the per-option feedback, aimed at the mistake that leads to that option: "That is the order of (\mathbf{Q}^{\mathrm{T}}\mathbf{P}^{\mathrm{T}}), not (\mathbf{PQ})."
- Use the explanation for the full worked solution. It is shown for every answer.
- To show LaTeX source as text, for example in a question about LaTeX itself, put it in a code block: text inside
<code>or<pre>is never typeset.
Troubleshooting
A formula shows as its source, such as \frac{1}{2}.
Check that Math Rendering is on in the App Manager and that the formula has both delimiters. Single dollars are read only with Read $…$ as inline maths switched on. After changing a setting, reload the exam page.
Part of a formula is shown in red.
KaTeX could not read that formula, usually because of a missing } or an unsupported command. The rest of the page still works. Correct the LaTeX, or check the command in KaTeX's supported functions.
Text after a < disappeared.
The question was saved before 6.4.0. Update Next Exams, then edit and save the question, or import it again.
Prices are typeset as maths.
Read $…$ as inline maths is on, and a question mentions two amounts in dollars. Switch it off and use \( \) for maths, or rephrase the prices.
Maths from a LaTeX plugin looks doubled or broken. Switch Run Joomla content plugins on question text off, or remove the plugin's tags from the question. Next Exams typesets maths itself.
Try it
The Next Exams demo has a practice quiz on matrices with display maths, a piecewise function and feedback on every wrong answer: Maths revision: matrices (practice).
See also
- Question bank, which covers question types, rich text and media
- Exam runner, including practice mode
- Import and export
- Settings
- App Manager