返回目录
其他 插件

dsh-latex

sbVAN/dsh-latex

该仓库暂未提供项目说明。

Stars
0
Forks
0
Issues
0
更新
9 天前

PROJECT TOPICS

项目标签

INSTALL REFERENCE

安装参考

未验证
dsh plugin --profile web add github:sbVAN/dsh-latex

该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。

PROJECT README

README

dsh-latex

English | 中文

Make the DeepSeek Harness chat render formulae as formulae, and make the model write LaTeX by default instead of wrapping math in latex fences.

What it fixes

DSH's frontend already renders TeX through KaTeX (MarkdownText in @deepseek-ai/dsh-client-ui-primitives), but:

Symptom Cause What this plugin does
Formulae show up as a grey code block The model writes them in ```latex / ```tex fences, which the frontend never renders (only $...$, $$...$$, \(...\), \[...\] and ```math are supported) | The host half states the output contract in the system prompt; the browser half renders legacy latex/tex fences in place
During streaming the answer shows raw $ and \frac The frontend deliberately keeps TeX literal while streaming and swaps in KaTeX once the message settles Left alone (upstream design); renders correctly after settling
A few formulae turn into harsh red text KaTeX strict mode: align, \si{}, \ce{} are outside the supported subset Forbidden by the prompt; the browser half turns the red error into a readable badge
Wide display math overflows the bubble KaTeX display blocks do not scroll by default The browser half adds horizontal scrolling and padding

Install

From GitHub (recommended)

dsh plugin --profile desktop add github:sbVAN/dsh-latex

Restart DeepSeek Harness afterwards, then reload the page once (the browser half needs to load the new bundle).

Development: link a local checkout

# 1. register a link dependency in the profile package.json:
#    "dsh-latex": "link:Z:/文件留存/deepseek project/dsh-latex"
# 2. create the junction (the equivalent of pnpm's link:)
New-Item -ItemType Junction `
  -Path "$env:USERPROFILE\.dsh\profiles\desktop\node_modules\dsh-latex" `
  -Target "Z:\文件留存\deepseek project\dsh-latex"
# 3. append to the profile's cordis.patch.yml:
#    - insert:
#        - id: latex
#          name: dsh-latex
# 4. restart DeepSeek Harness (the host half needs the new composition)

After that the browser half can hot-reload through HMR when hmr.root covers the plugin sources.

Configuration

- insert:
    - id: latex
      name: dsh-latex
      config:
        mode: auto
        strict: true
        compact: false
        locale: zh
        extraRules:
          - Write water as $\mathrm{H_2O}$, never \ce{}.
Key Default Meaning
mode auto auto injects only after the conversation shows math (no tax on every chat); always injects in every session; off never injects
enabled true Compatibility: false is equivalent to mode: off
locale auto zh / en / auto (auto follows DSH_LOCALE, LANG, defaulting to Chinese)
strict true true forbids fenced formulae; false only recommends
compact false Shorter prompt, roughly 1/3 of the tokens
order 145 Section order inside the system prompt (tool guidance owns 100–199)
extraRules [] Extra bullet lines appended to the contract

Behaviour

Host half (lib/index.js)

With mode: always it registers a global ctx.systemPrompt.section({ name: 'dsh-latex:math-output', order, text }). With mode: auto (default) no global section is registered: it listens on agent/pre-step, and only after a user message carries a math signal (math delimiters, TeX commands, or keywords such as integral/matrix/equation) does it register a scoped section through that session's agent.ctx — the section follows that session and is disposed with it, so chats that never touch math pay nothing. The contract covers inline $...$, single-line display $$...$$ blocks (a multi-line block loses its delimiter pairing and renders as source), a ban on fenced formulae, the KaTeX-supported subset (aligned over align, pmatrix/bmatrix/cases, \mathrm{} over \si{}/\pu{}/\ce{}, no \label/\tag), CJK only inside \text{}, no whitespace just inside $...$ (a closing $ that cannot close swallows the rest of the paragraph), splitting long derivations, and \lvert ... \rvert (never | or \left|) inside table cells.

In always mode the global section is disposed with the plugin fiber; in auto mode the scoped sections live with their sessions and are withdrawn on plugin reload. The rendered contract is written to $DSH_HOME/cache/dsh-latex/prompt.txt, mount diagnostics to mounted.json.

Browser half (lib/client.js)

  • display-math scrolling and an error badge;
  • pre > code.language-latex|tex gets a preview below it, rendered with the shared MarkdownText (no bundled KaTeX), source folded by default;
  • toolbar with show/hide source and copy LaTeX;
  • copy source: a hover button on each display block copies the original TeX from KaTeX's MathML annotation (annotation[encoding="application/x-tex"]); selecting a rendered formula and pressing Ctrl+C yields that same source instead of the newline-heavy span text;
  • 300 ms debounce over a full scan, orphan cleanup, and root unmount when React replaces nodes.

Limitations

  • No math while streaming — that is the frontend's deliberate behaviour and this plugin does not fight it.
  • Only latex / tex fences are handled — math fences are already rendered upstream.
  • No mhchem — \ce{} / \pu{} still fail; the prompt routes them to \mathrm{}.
  • No conversation.chat.node takeover — replacing the assistant renderer means duplicating the whole message structure and breaks on upstream upgrades.
  • No history rewriting — the prompt constrains future output only; old sessions are covered by the browser half.
  • auto is heuristic — it keys off math syntax and keywords, so it can miss (e.g. you only paste code and ask for a fix) or fire early; use mode: always when a session must carry the contract from the first turn.
  • A bare | in a table cell breaks the formula — GFM reads it as a column separator, so $\oint_{|z|=1}$ gets split across cells and renders as raw text. The prompt now requires \vert / \lvert ... \rvert; messages already sent cannot be repaired because the table was split at parse time.
  • Parse failures no longer flood the page: when a whole paragraph ends up inside one formula and KaTeX rejects it, parse-failure blocks are neutral instead of red; long ones collapse to three lines and expand on click. Display blocks need their opening and closing $$ on their own lines — this failure is almost always a closing $$ appended to the end of a formula.

Note: the browser half anchors on .md-code-block and reads the language from the header banner, because the rendered code block carries no language-* class on pre/code. See lib/client.js for the exact DOM contract.

Rollback

Remove the junction, drop the insert line from cordis.patch.yml, restore the profile package.json, restart. No DSH file is modified.

License

MIT

CLASSIFICATION EVIDENCE

分类依据

项目类型插件
功能分类其他
规则置信度低

系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: 无有效分类标签。