Markdown has no universal math syntax in its original core specification, yet technical documents routinely contain formulas. Most modern math-aware viewers recognize LaTeX-style expressions and render them with KaTeX or MathJax. The source remains plain text while the preview displays readable notation.
The difficult part is not writing x + y. It is choosing delimiters the target renderer understands and checking that Markdown punctuation does not interfere with the formula.
Inline math belongs inside a sentence. Many renderers use single dollar signs:
The average latency is $\bar{x} = \frac{1}{n}\sum_{i=1}^{n}x_i$ milliseconds.
The rendered formula should flow with the surrounding paragraph. Keep inline expressions short. A matrix, multi-step derivation, or long fraction is easier to read as a display block.
Double dollar signs commonly create a centered block:
The compound growth model is:
```math-display
[Formula]
Put the opening and closing delimiters on their own lines for portability. Blank lines around the block also prevent adjacent prose or lists from being parsed unexpectedly.
## Useful Formula Patterns
Fractions and roots:
```markdown
```math-display
[Formula]
Sums and limits:
```markdown
```math-display
[Formula]
Matrices:
```markdown
```math-display
[Formula]
Aligned equations may work when the renderer supports the corresponding KaTeX environment:
```markdown
```math-display
[Formula]
Always preview environments in the actual publishing target. LaTeX is a large ecosystem, while browser renderers intentionally support subsets of its commands and packages.
## KaTeX vs LaTeX in Markdown
LaTeX and KaTeX are related, but they are not interchangeable products:
| Term | Role in a Markdown document |
| --- | --- |
| LaTeX | The notation and command style authors usually write, such as `\frac`, `\sum`, and `\sqrt` |
| KaTeX | A browser-focused renderer that turns a supported subset of LaTeX-style input into formatted math |
A Markdown file commonly contains LaTeX-style expressions while the website uses KaTeX to display them. That is why a formula can compile in a full LaTeX document but fail in a browser preview: full LaTeX supports packages, document commands, and extensibility that KaTeX intentionally does not reproduce.
KaTeX is designed for fast browser rendering. It supports the notation used in many technical documents, including fractions, roots, sums, matrices, superscripts, subscripts, and common aligned expressions. Package-specific macros, document layout commands, and less common environments require checking against the installed KaTeX version.
When portability matters:
1. Prefer standard math commands over package-specific macros.
2. Avoid LaTeX document wrappers such as `\documentclass` and `\begin{document}`.
3. Define unfamiliar commands in prose or replace them with supported notation.
4. Test the same Markdown in the renderer used by the final reader.
## Why Math Appears as Plain Text
If `$E = mc^2
LaTeX Markdown Viewer: Preview Math With KaTeX | mdview.io
remains visible with dollar signs, the viewer may not enable math rendering. A standard Markdown parser can treat the delimiters as ordinary text. Moving the same file to a math-aware renderer may fix it without changing the source.
Other common causes include:
- Using delimiters unsupported by the target platform.
- Omitting a closing dollar sign.
- Placing display delimiters inside a code fence.
- Copying Unicode lookalikes instead of normal backslashes or dollar signs.
- Using a LaTeX command not supported by the installed KaTeX version.
- Letting a shell or template engine consume backslashes before Markdown sees them.
Code fences intentionally prevent math rendering. Use them when teaching the syntax, but remove the outer fence when you want the formula itself to render.
## Dollar Signs That Are Not Math
Currency creates ambiguity. A sentence such as “The plans cost $5 and $10” may be interpreted differently across renderers. Escape literal dollar signs when necessary:
```markdown
The plans cost \$5 and \$10.
Do not assume every Markdown platform follows identical delimiter rules. GitHub, documentation generators, notebooks, and chat tools may make different choices.
A formula should not carry unexplained meaning. Define variables in prose, include units, and state the conclusion after a complex expression. For example, follow a capacity formula with “where r is requests per second and t is the time window in seconds.” This helps every reader, including people using assistive technology or a renderer that falls back to source.
Before sharing a Markdown document with math:
mdview.io renders Markdown and LaTeX-style math together with tables, code, and Mermaid diagrams. Previewing the complete document matters: a formula can be syntactically correct while still being too wide, poorly explained, or unsupported by the renderer used by the final reader.
No. Authors write LaTeX-style math commands, while KaTeX is one renderer that supports a large, browser-friendly subset of those commands.
The local document may load a package or macro unavailable to the Markdown site's math renderer. Markdown platforms also choose their own delimiters and KaTeX or MathJax versions.
No. Put only the mathematical expression between the delimiters supported by the destination. Document preambles, packages, and page-layout commands belong to a .tex workflow, not an ordinary Markdown math block.
Start with one inline expression, $E = mc^2$, and one display expression on its own lines:
```math-display
[Formula]
Paste the sample into [mdview.io](https://mdview.io) without the outer `markdown` code fence when you want it to render. Confirm that math rendering is enabled in Reader settings. If the simple expression works but your formula does not, add commands back one at a time and check whether they are supported by [KaTeX](https://katex.org/docs/supported.html).
A Markdown document containing formulas is not a complete LaTeX project. Keep preambles, package installation, and document compilation in a LaTeX workflow; this page covers formulas embedded in Markdown.