Skip to content
joielabPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

dsh-katex

Page-level LaTeX math rendering for DeepSeek Harness Web: a KaTeX post-processor that renders TeX math on any message text surface — user messages, tool results, and streaming text included.

The DSH conversation already renders $...$ math through MarkdownText once a message settles, but several text surfaces never reach that pipeline: user messages render through the literal MessageText, tool results and other blocks carry plain text, and the streaming arm parses without math. This plugin is a DOM-level KaTeX post-processor that covers those surfaces.


Features

  • Renders TeX math anywhere in the chat: $...$ (inline), $$...$$ (block), \(...\), \[...\].
  • Streaming-safe: in-flight messages (data-streaming) are left for settled MarkdownText; code blocks (pre/code) are never touched.
  • React-safe: the original text node is emptied but never removed, so React's fiber references stay valid; rendered spans are inserted as siblings and re-applied automatically when React rewrites the source text.
  • Zero runtime dependencies: KaTeX is inlined into the bundle at build time; the browser side needs nothing beyond the DSH shell's platform modules.
  • No changes to DSH core — installed as an ordinary plugin, survives @deepseek-ai/dsh updates.

Installation

From npm (once published)

dsh plugin --profile web add dsh-katex

From this repository

# clone, then install into your profile
dsh plugin --profile web add /path/to/dsh-katex

Then restart dsh web and refresh the page. The plugin appears in the browser roster (window.__DSH_BOOT__) and starts rendering math immediately.

Plugin-set changes take effect on restart — the client-hmr row only hot-reloads rows that already exist.


How it works

┌────────────────────────────┐   MutationObserver    ┌──────────────────────────────┐
│  DSH Web shell (React)     │ ────────────────────▶ │  KatexPostProcessor (browser)│
│  user msg / tool result /  │   text nodes appear   │  find MathRuns → katex       │
│  streaming text            │                       │  renderToString → span       │
└────────────────────────────┘                       └──────────────────────────────┘

The browser half (src/client.js, bundled to lib/client.js):

  1. Observes document.body with a MutationObserver, coalescing passes per animation frame.
  2. Walks text nodes; skips pre/code/script/style/textarea and containers marked data-streaming.
  3. Matches TeX delimiters with display-mode precedence ($$…$$/\[…\] before $…$/\(…\), \$ escapes excluded).
  4. Renders each run with KaTeX, empties the original text node (keeping it in the tree), and inserts rendered <span data-dsh-katex-part> siblings before it.
  5. Marks the parent data-dsh-katex; when React rewrites the source under a still-marked parent, the observer clears stale rendered siblings and re-applies.

The host half (src/index.js → lib/index.js) is an empty apply so the plugin row exists in the host Loader; all behavior lives in the browser.


Development

pnpm install          # dev deps: esbuild + katex (both used only at build time)
pnpm run build        # regenerates lib/client.js, lib/index.js, cordis.patch.yml

The generated artifacts are committed (like dsh-system-control / dsh-theme-palettes), so users can install from a clone without a build step. prepublishOnly rebuilds them before publishing.

Testing manually

  1. Start DSH web with the patch: pnpm dsh web --patch ./cordis.patch.yml (or install into a profile).
  2. Send a message containing $E = mc^2$, $$x^2 + y^2 = z^2$$, or \(\partial\Gamma \cong \Gamma \times (\Gamma \to \Gamma)\).
  3. The math renders as KaTeX; user messages and tool results render too.

Files

dsh-katex/
├── package.json        # dsh.bundle + dsh.client declarations
├── cordis.patch.yml    # insert row (generated by build.mjs)
├── build.mjs           # esbuild bundler: inlines KaTeX into lib/client.js
├── src/
│   ├── client.js       # browser half: KatexPostProcessor (source)
│   └── index.js        # host half: empty apply (source)
├── lib/                # committed build artifacts
│   ├── client.js       # window.__ModuleLoader__.load({id, factory}) bundle
│   └── index.js        # host half ESM
└── .github/workflows/ci.yml

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages