If you are writing technical documentation, academic papers, or machine learning research on GitHub, you inevitably need to present mathematical equations. Standard Markdown was designed purely for text formatting and has zero native understanding of LaTeX.
To bridge this gap, modern documentation systems and platforms like GitHub rely on JavaScript rendering engines such as MathJax or KaTeX. As detailed in GitHub Docs: writing mathematical expressions, you can natively embed mathematical expressions.
This guide explains the standard syntax for embedding LaTeX in GitHub Markdown, how to handle dollar signs, and where mathematical syntax is supported.
Inline Math
To render an equation within a standard paragraph on GitHub, you can use two syntaxes.
The most common method is wrapping the LaTeX expression in single dollar signs:
The mass-energy equivalence formula is $E = mc^2$.
Alternatively, GitHub supports a dollar-backtick syntax, which avoids conflicts with standard Markdown formatting:
The mass-energy equivalence formula is $`E = mc^2`$.
Block (Display) Math
To render a standalone, centered equation on its own line, you also have two options.
You can wrap the expression in double dollar signs:
The integral of a function is defined as:
$$
\int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
$$
GitHub also supports wrapping block math in a specialized fenced code block using the math language identifier:
The integral of a function is defined as:
```math
\int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
```
Dollar Signs & Escaping
A common issue when writing math in Markdown is the accidental rendering of literal dollar signs.
In our test, the sentence It costs $5 and $10 today. rendered as plain text, not math. Outside math, escape a literal dollar sign as \$ — for example Price \$5 and \$10. renders as plain text. Inside math, escape the dollar with a backslash and use the dollar-backtick form, as in GitHub’s documented example:
This expression uses `\$` to display a dollar sign: $`\sqrt{\$4}`$
Where Math Does and Doesn’t Render
It is important to remember that LaTeX math support is not universal across all Markdown renderers:
- GitHub: Natively supports math rendering in Markdown files, Issues, Pull Requests, Discussions, and wikis using MathJax.
- Other Platforms: Static site generators like Hugo or Astro often require specific plugins (such as
remark-mathandrehype-katex) or configuration to render equations correctly.
Always check your specific platform’s documentation before relying on math formatting.
Tip: Inline math with underscores and asterisks such as $x_i * y_i$ rendered correctly on GitHub in our tests; if a renderer mangles them, the $...$ form protects the expression from Markdown emphasis parsing.
Previewing Math Locally
When testing complex LaTeX formatting, you can use the Markdown Math Previewer to verify your equations.
This tool uses KaTeX loaded directly into your browser’s memory, giving you instant visual feedback while keeping your data strictly private. It treats any pair of dollar signs on one line as math, so it is slightly stricter than GitHub about stray dollar signs. If you encounter rendering issues while previewing, ensure you escape or avoid lone dollar signs.
