LaTeX in Anki: MathJax, Shortcuts, Cloze and Mobile Fixes
November 11, 2026 · 10 min read
LaTeX in Anki: Write Math on Flashcards with MathJax or TeX
LaTeX in Anki works two ways. Type TeX between \( and \) for inline math, or \[ and \] for display math. Anki's built-in MathJax renders it on desktop, AnkiDroid and AnkiMobile with no setup. The [latex] tags instead call a TeX install on your computer and save each formula as an image.
MathJax or LaTeX Tags: The Two Ways Anki Renders Math
Anki ships with MathJax, a JavaScript library that typesets TeX each time a card is shown. The second mode runs real latex and dvipng on your desktop, then stores a picture of every formula in your media folder. Both read the same TeX math syntax, but they behave very differently once you sync.
| MathJax | LaTeX tags | |
|---|---|---|
| Delimiters | \(...\) inline, \[...\] display | [latex]...[/latex], [$]...[/$], [$$]...[/$$] |
| Software to install | None | A TeX distribution plus dvipng |
| Setting to turn on | None | Generate LaTeX images, in Preferences |
| What the card shows | TeX typeset when the card appears | An image file generated on the desktop |
| AnkiMobile and AnkiDroid | Renders directly (AnkiDroid 2.9+) | Shows images only after desktop generates and syncs them |
| Packages | MathJax's TeX extensions, mhchem included | Any package you install and add to the note type header |
| Restrictions | No full LaTeX packages | Commands like \input and \def are refused |
We prefer MathJax for nearly every deck. It needs nothing installed, it looks sharp at any zoom level, and it renders on your phone the moment the note syncs. Switch to LaTeX tags only when you need a package MathJax doesn't have, such as siunitx or chemfig.
How Do You Write LaTeX on Anki?
Type the TeX into a field, select it, then click the Fx button in the editor toolbar and pick MathJax inline or MathJax block. Anki wraps your selection in the right delimiters. The Anki manual's math page walks through the same steps.
The circle has the equation \(x^2 + y^2 = r^2\).
On the card, the equation sits inside the sentence at text size, with proper superscripts.
\[\int_0^1 x\,dx = \tfrac{1}{2}\]
This one renders centered on its own line, like a displayed equation in a textbook. Click Cards... in the editor to preview either one before you save.
The Fx menu has six two-step shortcuts, listed in the editor's LatexButton source on GitHub. Press the first combination, release, then press the second key.
| Windows and Linux | Mac | Inserts |
|---|---|---|
| Ctrl+M, M | Cmd+M, M | \(...\) MathJax inline |
| Ctrl+M, E | Cmd+M, E | \[...\] MathJax block |
| Ctrl+M, C | Cmd+M, C | \(\ce{...}\) MathJax chemistry |
| Ctrl+T, T | Cmd+T, T | [latex]...[/latex] |
| Ctrl+T, E | Cmd+T, E | [$]...[/$] |
| Ctrl+T, M | Cmd+T, M | [$$]...[/$$] |
Two habits save a lot of broken cards. Use Shift+Enter for a new line inside a formula, because a plain Enter stops MathJax from working correctly. If pasted text drags formatting into an equation, open the field's HTML editor with the </> button, as described in the editing docs, and clean the source.
Want a shorthand like \R for the real numbers? The manual's Customize MathJax section has an example macro script. Leave the default delimiters alone, though, because Anki's cloze handling depends on them.
Chemistry Formulas with mhchem
Anki includes the mhchem extension, so chemical formulas work inside MathJax without extra setup. Wrap the formula in \ce, or press Ctrl+M, C and Anki adds both the delimiters and the command for you.
Water is \(\ce{H2O}\). Hydrogen burns as \(\ce{2H2 + O2 -> 2H2O}\).
The card shows H₂O with a proper subscript and a reaction arrow between the two sides. The mhchem manual lists the full syntax for charges, states and equilibrium arrows. Check these in Anki's own card preview, since general math previews often skip mhchem.
Cloze Deletions Inside Equations Without Breaking the Card
A cloze ends at }}, and TeX produces }} all the time. When Anki reads a field, it can take the end of a nested brace group for the end of your cloze. This field looks fine but splits the formula:
{{c1::\(\frac{1}{\sqrt{2}}\)}}
The }} right after the 2 closes \sqrt{2} and the fraction, not the cloze. Current releases cut the deletion there and leave a stray fragment on the card. The fix is a space between the two closing braces. MathJax ignores spaces in math, so the formula looks identical:
{{c1::\(\frac{1}{\sqrt{2} }\)}}
You can also hide just part of an equation. Anki strips the cloze markup inside the formula, so the front shows [...] typeset in place of the hidden term:
\(E = {{c1::mc^2}}\)
A fix merged into Anki's source in September 2026 stops a }} inside MathJax from closing a cloze opened outside it. As of early November 2026, no stable release includes it yet.
The fix also doesn't cover a cloze that opens inside the formula, as in \(x = {{c1::\frac{1}{2} }}\), which still needs its space. We'd keep the space as a habit, since it works in every version. If a space would change the text, the manual shows an HTML comment trick instead.
How Do You Enable LaTeX Tags in Anki?
The tag mode isn't turn-key. The manual assumes you already know LaTeX and have it installed.
- Install TeX. On Windows, use MiKTeX and set "Install missing packages on the fly" to Always in its settings. On macOS, use MacTeX or BasicTeX. On Linux, use your distro's packages.
- Make sure dvipng is installed. BasicTeX needs it added with
sudo tlmgr update --self; sudo tlmgr install dvipng. - Open Preferences and turn on Generate LaTeX images (security risk). Recent versions ship with it off, because TeX code from a shared deck could read or write files on your computer.
- Type the tags into a field, never into a card template.
Does [$]\sum_{k=1}^{\infty} \frac{1}{k}[/$] converge?
[$$]\int_0^{\pi} \sin x \, dx = 2[/$$]
The first line places a small image of the series inside the question. The second renders as a separate, centered image. [$] wraps its content in a math environment and [$$] in displaymath. Plain [latex] adds no environment, so use it for text-mode LaTeX or when you write the environment yourself.
Add Packages to the LaTeX Header
Each note type keeps its own LaTeX header and footer. Open Tools > Manage Note Types, select the note type, and click Options. Add your \usepackage lines to the header shown there:
\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage{amssymb,amsmath}
\usepackage{siunitx}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}
With that header, a field like [latex]\qty{9.81}{\metre\per\second\squared}[/latex] renders the value with correctly spaced units. Install the package in your TeX distribution first, and test it from the command line if it fails. The same dialog offers a Create scalable images with dvisvgm option for SVG output instead of PNG.
Anki refuses certain commands, including \input and \def, anywhere on cards, templates or headers. That includes comments, so check those too if you hit the error. If you truly need such a command, put it in your own package installed on the system and load it with \usepackage.
Why Is LaTeX in Anki Not Rendering on Desktop or Mobile?
Most failures trace back to one of these causes. Match what you see on the card:
- Dollar signs show up as text. Anki's MathJax only treats the backslash delimiters as math, so
$x^2$stays literal. It's an easy habit to bring over from Markdown or a Jupyter notebook. Retype it as\(x^2\). Our MathJax LaTeX guide explains why single dollar signs are off by default. - A formula breaks after you add a line. You pressed Enter inside it. Delete the break and use Shift+Enter.
- Anki reports that LaTeX image generation is disabled in the preferences. Turn on the Generate LaTeX images setting, then review the card again.
- LaTeX works on desktop but not on your phone. Mobile and web clients can't create the images. Run Tools > Check Media on desktop, click Render LaTeX if it lists missing LaTeX images, then sync.
- A cloze shows half a formula. A
}}closed it early. Add a space between the braces. - MathJax shows raw TeX or red text instead of a formula. There's a typo, or the command isn't one MathJax supports. Fix the TeX, or move that formula to LaTeX tags.
Draft and Check Card Math Before You Paste It
Our editor previews math with KaTeX, which reads $...$ and $$...$$. It doesn't support Anki's \(...\) or \[...\] delimiters, so draft only the inner TeX between dollar signs. Once it renders correctly, copy the inner part into Anki and wrap it with Ctrl+M, M or Ctrl+M, E.
There's a limit to this check. KaTeX and Anki's MathJax don't support exactly the same commands, and \ce won't render in our preview, so give each card a last look in Anki's preview. For the dollar-sign syntax itself, see our guide to writing an equation in Markdown. Our KaTeX vs LaTeX comparison lists which commands KaTeX supports.
If you'd rather build a formula from symbols than type it, the LaTeX equation editor has a symbol palette and renders with KaTeX. Copy its Markdown math snippet, then swap the dollar signs for Anki's delimiters the same way.
Anki Math Questions, Answered
Once you know which mode you're in, LaTeX in Anki comes down to the right delimiters, a space between closing braces in clozes, and generating images before you sync. Draft tricky formulas in our free Markdown editor to catch typos in the TeX, then wrap them for Anki and check the card preview. MathJax covers most decks, and the tag setup is there when you need a real LaTeX package.