Math blocks are not rendered when delimiters are indented for list-item continuation #209233
Replies: 3 comments
AnswerThis looks like a valid GitHub Markdown rendering bug involving math blocks inside continued list items. The issue is that when a math delimiter is indented to remain part of a list item, GitHub renders it as plain text instead of mathematical notation. Expected behaviorIndented math blocks should still be recognized and rendered as math while remaining inside the list item. Current behaviorThe same math block renders correctly when moved to column 0, but loses math rendering when indented for list continuation. Suggested fixGitHub's Markdown parser should handle list-item continuation indentation before processing math delimiters, so constructs such as The minimal reproduction and comparison with VS Code in the post should make this straightforward to reproduce. If this answer was helpful, please mark it as answered. |
|
GitHub only recognises display maths when each $$ sits on its own line with a blank line before and after the block, and inside a list item every line of that construct must be indented to align with the list item's content, for example two spaces beneath a "- " marker. A fenced ```math block needs the same handling: a blank line above the opening fence plus consistent list-item indentation. In your repro the fence sits immediately under "The output is:" with no blank line between them, so the parser treats it as ordinary text rather than maths. Try restructuring the item as text, blank line, indented $$ on its own line, formula, indented $$, blank line, and the block should render while staying inside the list. |
|
Hi @MikeProjects, The root cause in your minimal reproduction comes down to two strict constraints in GitHub's Markdown parser (built on CommonMark + MathJax):
Working Fixes for Your Exact ExampleOption 1: Multi-line fenced math block (Preserves list structure) Ensure an empty line precedes the fence, and keep each delimiter on its own line indented by 2 spaces:
Perform a change of variable: let Option 2: Using indented If you prefer standard TeX display math over code fences, place both
Perform a change of variable: let Option 3: Using HTML If you have nested lists with complex multi-paragraph equations where indentation rules become brittle: Both Option 1 and Option 2 will render properly as rendered MathJax while keeping the structural hierarchy intact on GitHub. If this solution resolves the issue in your documentation, please consider marking this as the accepted answer! |
Uh oh!
There was an error while loading. Please reload this page.
🏷️ Discussion Type
Question
💬 Feature/Topic Area
Code Search and Navigation
Body
Hi, GitHub team, 👋
Thank you for the outstanding work on GitHub and for continuously improving the Markdown experience.
I found a rendering issue in GitHub Markdown when trying to keep a display math block logically inside a list item.
Problem summary
When a math delimiter is indented (to keep the block inside a bullet/list continuation), GitHub renders the math source as plain code/text instead of rendering it as math.
This happens with both:
$$ ... $$```math ... ```Why this matters
In CommonMark/GFM list writing, indentation is needed to keep follow-up content in the same logical list item.
Repro case (minimal)
Actual behavior
The
mathblock is rendered as a plain source-code block (not as KaTeX/display math). The following screenshot image is taken on GitHub.com built-in Preview of the above sample source code.Expected behavior
Indented math delimiters used as list-item continuation should still be recognized as math and rendered accordingly. The attached screenshot image is taken on VS Code with its built-in Markdown Preview.
Notes
I’m happy to help test possible fixes with additional examples.
Thanks!
All reactions