Notes apps

How to Write LaTeX in Markdown

By imagetolatex team · Published

Most Markdown editors that support math use the same syntax: put inline math between single dollar signs, $E = mc^2$, and display math between double dollar signs on their own lines, $$ … $$. GitHub, Jupyter, Obsidian and VS Code render it with MathJax or KaTeX; plain Markdown viewers show the dollar signs as text.

The syntax

Markdown with inline and display math
The roots of $ax^2 + bx + c = 0$ are

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
What the display block renders
x = − b ± b 2 − 4 a c 2 a
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}Open in the LaTeX editor

GitHub also accepts a fenced block with the language math, which avoids clashes with other Markdown rules.

Where it renders

ToolInlineDisplayRenderer
GitHub (README, issues, wikis)$…$$$…$$ or a math code blockMathJax
Jupyter notebooks$…$$$…$$MathJax
Obsidian$…$$$…$$MathJax
VS Code Markdown preview$…$$$…$$KaTeX

Static site generators and chat apps vary: some need a math plugin, some use \(…\) and \[…\] instead of dollars. Check the docs of the tool that renders your page.

What breaks and how to fix it

  • Underscores and asterisks inside math can be read as italics by the Markdown parser before the math renderer sees them. Put display math on its own lines, or use the math code block on GitHub.
  • Backslashes: some parsers swallow \\, so line breaks in aligned disappear. Write \\\\ if needed, or use a math code block.
  • A dollar sign as currency: escape it as \$ so it does not start math.
  • Packages and macros: Markdown math is MathJax or KaTeX, not a full LaTeX document. \usepackage and TikZ do not work; most of amsmath does.

The other way round: Markdown inside a LaTeX document

If you want to write parts of a LaTeX document in Markdown, the markdown package converts it while compiling. It needs LuaLaTeX or shell escape, which Overleaf allows. For whole documents, converters such as Pandoc translate Markdown to LaTeX and back.

Markdown inside LaTeX (markdown package)
\usepackage{markdown}
...
\begin{markdown}
# Results
The fit is *good*: $R^2 = 0.98$.
\end{markdown}

Getting Markdown with math from screenshots and PDFs

Lecture slides, textbook pages and handwritten notes can be turned into Markdown with the math already in $…$: paste a screenshot into image to Markdown and copy the result into your notes.

The image to Markdown converter in page mode with a sample lecture page turned into Markdown text with LaTeX math between dollar signs
A page of notes becomes Markdown with every formula as LaTeX math.

FAQ

How do I write LaTeX in Markdown?
Use $…$ for inline math and $$…$$ on separate lines for display math, in an editor that renders math.
Does GitHub support LaTeX in Markdown?
Yes. README files, issues and wikis render $…$, $$…$$ and math code blocks with MathJax.
Why does my formula show with dollar signs?
The viewer does not render math, or the Markdown parser changed the formula first. Try a math code block or check the tool's math settings.
Can I use Markdown in LaTeX?
Yes, with the markdown package (LuaLaTeX or shell escape), or convert files with Pandoc.

Sources

Related guides

Converting more than one equation?

When the math is in a whole page, a PDF, a Word file or handwriting, these converters do it in one go and keep every equation editable.

Single printed formulas are free: 3 a day without an account, 6 with a free account. New accounts get 30 credits to try handwriting, pages and documents; failed conversions return their credits. See plans and credit prices.