Skip to content

KaTeX math rendering ($...$ and $$...$$) #2

@SyNeto

Description

@SyNeto

Goal

Render inline (`$...$`) and display (`$$...$$`) math expressions using KaTeX, fully offline, no CDN.

Why

Math notation in technical/academic Markdown is unreadable as raw `$` delimiters. KaTeX is the de-facto offline math renderer — fast, no MathJax-style DOM cost.

Proposed approach

  • `npm install --save-dev katex` and bundle `katex.min.js` with esbuild into `vendor/`.
  • Vendor the KaTeX CSS and fonts (`KaTeX_*.woff2`) into `vendor/katex/`.
  • Declare the font files in `web_accessible_resources` of `manifest.json` so the CSS can resolve them via `chrome-extension://...` URLs.
  • Either rewrite KaTeX CSS `url(...)` references at build time, or inject a runtime `<style>` block with URLs from `chrome.runtime.getURL()`. Decide based on which keeps the build simpler.
  • Integrate as a marked extension that scans for `$` and `$$` delimiters and replaces matches with KaTeX-rendered HTML.

Constraints

  • No CDN. Everything bundled locally. Fonts must NOT load from `cdnjs`, `unpkg`, or any external host.

Acceptance criteria

  • `$E = mc^2$` renders inline math
  • `$$\int_a^b f(x)dx$$` renders display math
  • No network requests issued by KaTeX (verify in DevTools Network tab)
  • Works on `file:///` pages
  • No regression on docs without math

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions