Math in Marp slides: KaTeX, MathJax and the syntax
Marp renders LaTeX math out of the box: $E = mc^2$ inline and $$ … $$ for a display equation, with math: mathjax or math: katex in the front matter choosing the engine. Marp Core has used MathJax by default since version 3.0 (November 2021); KaTeX is lighter and faster in the preview. Both export to PDF through marp-cli and to PPTX as rendered images.
This guide covers the syntax, the engine choice, multi-line equations, macros for notation you use every week, sizing, and the checks that catch a broken formula before the lecture.
The syntax
---
marp: true
math: mathjax
---
# Expected waiting time
Inline: the mean is $\mu = \frac{1}{n}\sum_{i=1}^{n} x_i$.
Display:
$$
W_q = \frac{\lambda}{\mu(\mu - \lambda)}
$$
Inline math sits in a sentence; display math gets its own line, centred. Leave a blank line before and after a $$ block so the Markdown parser does not fold it into a paragraph.
KaTeX or MathJax?
| KaTeX | MathJax | |
|---|---|---|
| Speed in the preview | faster | slower on long decks |
| Coverage | most of LaTeX math | more environments and packages |
| Default in Marp Core | up to v2 | since v3.0 (2021) |
| Set with | math: katex |
math: mathjax |
For a lecture deck either works; start with the default and switch only if a construct fails to render. math: false turns math off for a deck that uses dollar signs literally.
Aligned and multi-line equations
$$
\begin{aligned}
T_{\text{turnaround}} &= T_{\text{finish}} - T_{\text{arrival}} \\
T_{\text{waiting}} &= T_{\text{turnaround}} - T_{\text{burst}}
\end{aligned}
$$
aligned lines up on & and breaks on \\. Number equations by hand (\tag{1}) if the room will refer to them; automatic numbering is not a Marp feature.
Macros for the course's notation
Notation that appears every week (a vector style, an operator name) belongs in a macro, not retyped:
$$
\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\E}{\operatorname{E}}
$$
Both engines accept \newcommand inside a math block. Whether a definition made on slide 2 is still known on slide 30 depends on the engine and the version, so define the macros once in a block on the first slide and check the last slide that uses them in the preview.
Sizing and layout
Math inherits the slide's font size. For a slide whose point is one equation, a scoped style enlarges it:
<style scoped>
section { font-size: 32px; }
</style>
For a deck-wide change, target the engine's container in the theme or the front-matter style: block: .katex { font-size: 1.1em; } for KaTeX, mjx-container { font-size: 110%; } for MathJax. Long equations do not wrap; split them with aligned rather than shrinking the font below what the back row can read.
Before the lecture: three checks
- Every formula renders in the preview. A missing brace shows as raw dollar signs or red text; scan the slide rail rather than paging through.
- The PDF matches.
marp deck.md --pdfrenders with the same engine; check the equation slides, since a font or a package difference shows up there first. - Speaker notes carry the source. The derivation's textbook page in the note under the slide answers "where does this come from?" faster than re-deriving.
In Lecture Studio
The Marp preview in Lecture Studio renders math when the front matter has the math directive (math: mathjax is what the app's docs show), and the Check slides scan flags an overflowing equation slide. A deck the assistant writes from a paper cites the equation's source under the slide, which is the third check above done for you. PDF export is marp-cli's job, not the app's. The app runs on macOS 15 or later and needs an Oberik project key for the assistant.
FAQ
How do I write equations in Marp?
$…$ for inline math and $$…$$ on its own lines for display math, with math: mathjax or math: katex in the front matter.
Does Marp use KaTeX or MathJax?
Both are supported. Marp Core defaults to MathJax since version 3; set math: katex to use KaTeX instead.
How do I align multi-line equations in Marp?
Use \begin{aligned} … \end{aligned} inside a $$ block, with & at the alignment point and \\ between lines.
Do equations survive export to PDF and PowerPoint?
Yes. marp-cli renders them into the PDF; the default PPTX export includes them as part of the slide image. The editable PPTX mode does not keep them as equations.