Back to Resources

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
4 linescompact
flowchart LR
    Delim["Delimiters: $ (inline) or $$ (block)"] --> LaTeX["LaTeX Mathematical Expression"]
    LaTeX --> Engine["MathJax / KaTeX Engine"]
    Engine --> MathML["Rendered Math Symbols in Discussion/PR"]
Rendered from Mermaid source with the native ZeroLabs diagram container.

Inline expressions

Two delimiter styles work inline with prose:

markdown
This sentence uses `$` delimiters to show math inline: $\sqrt{3x-1}+(1+x)^2$
markdown
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 $$:

markdown
**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:

markdown
**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)```
StyleDelimitersBest for
Inline $…$single dollarsShort formulas in a sentence
Inline $`…`$dollar-backtickFormulas that fight Markdown parsing
Block $$…$$double dollarsDisplay equations on their own lines
Fence ```mathlanguage tag mathSame as block, without $$

Dollar signs next to math

  • Inside a math expression, escape a literal dollar with \$:
markdown
This expression uses `\$` to display a dollar sign: $`\sqrt{\$4}`$
  • Outside math but on the same line, wrap the character in span tags:
markdown
To split <span>$</span>100 in half, we calculate $100/2$

Further reading

Share