Add LaTeX math rendering support#148
Conversation
Add KaTeX math support and include KaTeX CSS in export/pdf flow
There was a problem hiding this comment.
Pull request overview
This PR adds LaTeX math rendering to the Markdown Live Preview by integrating KaTeX into the existing marked → DOMPurify → preview rendering pipeline, and extends PDF export so rendered math is styled correctly.
Changes:
- Load and register
marked-katex-extensionat runtime to render$...$(inline) and$$...$$(display) math. - Include KaTeX CSS in the live preview and inline KaTeX CSS (with rewritten font URLs) into the PDF export clone.
- Add styling for display-math blocks to improve horizontal overflow behavior.
Reviewed changes
Copilot reviewed 3 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main.js | Adds KaTeX/marked-katex-extension integration, adjusts DOMPurify call, and includes KaTeX CSS in PDF export. |
| public/css/style.css | Adds styling for KaTeX display math containers in the preview. |
| index.html | Adds KaTeX stylesheet link for live preview rendering. |
| dist/index.html | Updates built HTML to include KaTeX stylesheet and new bundle reference. |
| dist/css/style.css | Updates built CSS with KaTeX display styling. |
| dist/assets/index-DWLYmPWz.js | New built bundle containing the KaTeX integration changes. |
| dist/assets/index-BEfDAM6P.js | Removes the previous built bundle. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary of bd6e7a0I pushed follow-up changes addressing these points:
I removed the duplicated hard-coded KaTeX CSS URL/version from the PDF export logic. The PDF export now derives the KaTeX stylesheet URL from the existing KaTeX
I reverted/adjusted the DOMPurify configuration so this change does not unintentionally narrow the sanitization behavior by switching to
I changed the display-math styling approach instead of relying on I also re-tested the PDF export. The integral symbol itself is now fully visible. There is still a minor visual limitation where the limits of tall operators such as |
|
BTW, I am testing with: Math testRegular Markdown still works: Heading
bold text and italic text Inline math: Another inline example: Display math: Escaped dollar sign: $5 should stay as a dollar amount.
Inline code should not render math: Fenced code should not render math: $x^2$
$$x^2$$Invalid math should not crash the app: Math inside a blockquote:
Normal Markdown Regression Test
|

Summary
This PR adds LaTeX math rendering support to Markdown Live Preview to resolve the math rendering gap reported in issue #108. It integrates KaTeX into the Markdown preview pipeline so mathematical expressions render correctly while preserving existing Markdown behavior and safety checks.
Changes
$E = mc^2$).$$ ... $$blocks).Testing
Notes
PDF export renders math, but very tall symbols such as
\intcan be slightly clipped at the bottom.Related issue
Closes #108.