How to write mathematical expressions on GitHub
Post GitHub MathJax inline and display delimiters via gh --body-file, then prove stored math source with gh issue view --json.
What this covers
Writing mathematical expressions documents how to show math in Markdown on GitHub. Rendering uses MathJax (including accessibility extensions). Background on LaTeX math: LaTeX/Mathematics (Wikibooks). Surfaces: issues, discussions, pull requests, wikis, and Markdown files.
flowchart LR
Delim["Delimiters: $ (inline) or $$ (block)"] --> LaTeX["LaTeX Mathematical Expression"]
LaTeX --> Engine["MathJax / KaTeX Engine"]
Engine --> MathML["Rendered Math Symbols in Discussion/PR"]Inline expressions
Two delimiter styles work inline with prose:
This sentence uses `$` delimiters to show math inline: $\sqrt{3x-1}+(1+x)^2$This sentence uses $` and `$ delimiters to show math inline: $`\sqrt{3x-1}+(1+x)^2`$Use the $`…`$ form when the expression contains characters that collide with Markdown. See Basic writing and formatting syntax.
Block expressions
Start a new line and wrap the expression with $$:
**The Cauchy-Schwarz Inequality**\$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$Or use a math fence (no $$ required). This renders the same inequality:
**The Cauchy-Schwarz Inequality**```math\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)```| Style | Delimiters | Best for |
|---|---|---|
Inline $…$ | single dollars | Short formulas in a sentence |
Inline $`…`$ | dollar-backtick | Formulas that fight Markdown parsing |
Block $$…$$ | double dollars | Display equations on their own lines |
Fence ```math | language tag math | Same as block, without $$ |
Dollar signs next to math
- Inside a math expression, escape a literal dollar with
\$:
This expression uses `\$` to display a dollar sign: $`\sqrt{\$4}`$- Outside math but on the same line, wrap the character in span tags:
To split <span>$</span>100 in half, we calculate $100/2$