Tutorial · 7 min read

How to Write Equations in Markdown: Inline and Display Math

How to write math equations in Markdown using inline and display syntax, which renderers typeset LaTeX, and how Fylune renders KaTeX formulas in local files.

Orion Wells

Written by

Founder of Aurcue

Founder of Aurcue, writing about AI products, personal style systems, and the decisions behind useful photo-based guidance.

How to Write Equations in Markdown: Inline and Display Math

Markdown has no equation syntax of its own. You write a formula in LaTeX notation, wrap it in dollar signs, and a math renderer such as KaTeX or MathJax typesets it. The two forms you need:

  • Inline math: $E = mc^2$ sits inside a sentence.
  • Display math: $$...$$ on its own lines becomes a centered block.

The catch is that the same dollars render on some platforms and stay as literal text on others. This guide covers the syntax, the LaTeX fragments you type most, why formulas fail to render, and which tools typeset math today, including how Fylune renders KaTeX formulas in local Markdown files.

1023ab1f c2e0 4b3c a6c3 45b073a1f6a9
Editorial illustration of plain text lines transforming into typeset mathematical notation on a document page

Inline math: single dollar signs

Write the formula between two dollar signs, tight against the content, on one line:

The identity $\sin^2\theta + \cos^2\theta = 1$ holds for every angle $\theta$.

A renderer turns that into typeset math inside the sentence. Rules that matter:

  • The opening and closing dollars must be on the same line, in the same paragraph.
  • Do not put a space immediately after the opening dollar or before the closing one; some renderers treat that spacing as literal text.
  • If no math renderer is present, the dollars print as characters. That is the most common failure, and it is not a typo in your formula.

Display equations: double dollar signs

Put $$ on its own line, the equation on the next line, and closing $$ on a line after:

$$
\frac{d}{dx}\left(e^x\right) = e^x
$$

For multi-line derivations, use aligned inside the block:

$$
\begin{aligned}
(a+b)^2 &= a^2 + 2ab + b^2 \
(a-b)^2 &= a^2 - 2ab + b^2
\end{aligned}
$$

Reserve display math for formulas a reader should notice, multi-line derivations, and anything with fractions or sums tall enough to break line spacing when used inline.

The LaTeX fragments you will type most

GoalWriteRenders as
Fraction\frac{a}{b}a stacked over b
Subscriptx_i, a_{i,j}x with i below the line
Superscriptx^2, e^{i\pi}x raised to a power
Summation\sum_{i=1}^{n} x_isigma with bounds
Square root\sqrt{b^2-4ac}radical over the expression
Greek letters\alpha \beta \thetaalpha, beta, theta
Multiplicationa \times btimes sign
Inequalities\leq \geq \neqless or equal, greater or equal, not equal

Everything inside the dollars is LaTeX math mode, not Markdown. Asterisks, underscores, and backticks have no meaning there, so you do not escape them.

Why your formula shows as raw text

Four causes, in order of frequency:

  1. No renderer. The CommonMark specification has no math support. GitHub maintainers state the pattern plainly: "Markdown does not support equation on its own. For equation to be displayed, a third party is required," with GitHub using MathJax to render equations. If the surface you paste into has no math pipeline, the dollars stay literal no matter how correct the syntax is.
  2. Escaped dollars. A backslash, as in \$, prints a literal dollar sign and never starts math. If your content passed through a converter, check for backslashes before the dollars.
  3. Dollar collisions. Two prices on one line, like $5 and $10, look exactly like inline math with 5 and ` as the formula body. Some syntax highlighters and renderers interpret them that way; the VS Code team tracks a case of dollar amounts being highlighted as math in Markdown files. Fix it by escaping the first dollar (`\$5) or by moving amounts to separate lines.
  4. Stray spacing. A space right after the opening dollar, or a wrapped line inside the pair, can stop the renderer. Keep the pair tight and on one line.

Quick diagnostic: if the dollars appear in the output, the problem is the renderer; if the dollars disappear but the formula looks garbled, the problem is LaTeX syntax inside the pair.

Which tools typeset math today

ToolSyntax supportEngineNotes
GitHub (README, issues, comments)$...$ and $$...$$MathJaxTypesets in most Markdown surfaces on github.com
VS Code built-in preview$...$ and $$...$$KaTeXThe editor also highlights dollar-sign edge cases
Obsidian$...$ and $$...$$MathJaxReading view typesets the formulas
Fylune$...$ and $$...$$KaTeXRenders inside the document experience on local files
Plain CommonMark renderersnonenoneDollars stay literal

One caveat: support can differ per surface on the same tool. GitHub renders math in Markdown files and comments, but a plain .md viewer elsewhere will not. Check the exact surface you publish to, not just the brand name.

Fylune: equations in local Markdown files

Fylune is a local-first document workspace for ordinary Markdown and MDX files, and KaTeX formula rendering is part of its rich Markdown support:

  1. Open a Markdown file inside your project folder.
  2. Type inline math with $...$, or a display block with $$...$$.
  3. The preview typesets the formulas with KaTeX inside the document experience.
  4. Save. The file is still plain Markdown: Git, other editors, and AI agents that share the folder read the same dollar signs.

Core local editing, including opening, editing, and searching these files, is free and needs no account. If you want to test this workflow on your own files, download the app at fylune.com/download.

Quick reference card

TaskWrite this
Inline math$a^2 + b^2 = c^2$
Display math$$ ... $$ on its own lines
Aligned multi-line derivation\begin{aligned} ... \end{aligned} inside $$
Literal dollar sign\$
Fraction\frac{p}{q}
Summation with bounds\sum_{i=1}^{n}

FAQ

How do you write equations in Markdown?

Wrap LaTeX in dollar signs: single $...$ for inline math, double $$...$$ on their own lines for display math, then view the file in a renderer such as KaTeX or MathJax.

Does Markdown support math natively?

No. The CommonMark specification has no math syntax. Math rendering always comes from a renderer add-on.

Why do prices like "5and5 and 10" break my document?

A dollar pair can be read as inline math. Escape one dollar as \$, or keep the amounts on separate lines.

Related reading

Sources

  • Markdown Math Rendering Across Platforms: wrapping a formula in dollar signs typesets on some platforms and stays literal on others.
  • Quarto discussion: Markdown does not support equations on its own; a renderer such as MathJax is required, and GitHub uses MathJax.
  • Stack Overflow: community answer on showing math equations in GitHub Markdown.
  • VS Code issue 136535: dollar amount incorrectly highlighted as a math equation in Markdown.
  • Fylune product overview (docs/product-overview.md): KaTeX formulas render inside the document experience; core local editing is free and requires no account.