Markdown Math Preview: LaTeX and KaTeX Examples That Render Correctly

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

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.

Display Math

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.

## Why Math Appears as Plain Text

If `$E = mc^2

  
    
    
    
    Markdown Math Preview: LaTeX and KaTeX Examples That Render Correctly | 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.

Accessible Mathematical Documents

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.

Preview Checklist

Before sharing a Markdown document with math:

  1. Verify every inline delimiter has a closing delimiter.
  2. Put display delimiters on separate lines.
  3. Check fractions, superscripts, matrices, and aligned environments.
  4. Confirm literal currency symbols are not treated as math.
  5. Inspect the document on mobile for overflowing formulas.
  6. Export or print once if the final deliverable is a PDF.

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.