Introduction¶
In the DeepSeek Harness (DSH) chat window, writing block-level LaTeX formulas using the $$\begin{aligned}…\end{aligned}$$ syntax often results in a wall of red text with a KaTeX parse error displayed below. The same content renders perfectly in editors like VSCode, Typora, and Obsidian. This is not a typo in the formula, nor is it a model output error—rather, DSH’s own markdown rendering pipeline models and parses block-level formulas differently from other tools. dsh-latex-render-fix is a client-side plugin that, upon DSH startup, injects two regex patterns into the frontend bundle to normalize the formula syntax into a form that remark can correctly parse, allowing KaTeX to render properly.
What It Is¶
- Name: dsh-latex-render-fix
- Maintainer: mizuki5101
- Category: Client-side
- Repository: https://github.com/mizuki5101/dsh-latex-render-fix
- License: MIT
It addresses the boundary issue DSH has when parsing $$…$$ block-level formulas: the content immediately following $$ (such as \begin{aligned}) is treated as a “language identifier” and discarded, and the closing fence must appear at the beginning of a line; as a result, the \begin{} in $$\begin{aligned} gets consumed, the formula body starts from &, and KaTeX throws an error; simultaneously, if the closing $$ is not at the start of a line, it cannot close, and the formula node swallows everything to the end of the file. The plugin inserts regex patterns at the rendering entry point to move the content after the opening $$ and the content before the closing $$ each onto their own independent lines, without touching the parser itself—only altering the text structure.
Core Features¶
- On startup, automatically inspects the frontend bundle inside
resources/app.asar; if it has not yet been patched, inserts two regex patterns at the markdown rendering entry point. - Regex 1: Splits the portion where a line-leading
$$is immediately followed by\begin{into two lines:
.replace(/^\$\$(?=\\begin\{)/gm, () => '$$\n')
- Regex 2: Splits a line-ending
\end{env}$$into two lines:
.replace(/\\end\{([a-z*]+)\}\$\$$/gm, (m, a) => `\\end{${a}}\n$$`)
- Both regex patterns are idempotent—re-running them on every streaming frame does not cause cumulative insertions.
- Only matches line-leading
$$+\begin{and line-ending\end{env}$$; mid-sentence$$occurrences are unaffected. - Before patching, performs a syntax check on the asar (
node --check); backs up and verifies file size before writing; any exception is only logged and does not block DSH startup.
Behavior & Boundaries¶
- Already-safe syntax (where
$$is on its own line) is unaffected. - After a DSH upgrade overwrites the asar, the next startup will automatically re-apply the patch.
- First startup after an upgrade: formulas may still appear red; second startup: renders normally.
- Reason: when cordis loads plugins, it only registers them without awaiting the plugin’s
apply, so the patch cannot complete before the window loads (rearrangement takes approximately 0.8–1.2 seconds). - Only formulas containing
\begin{…}are split into block-level (centered display); single-line$$x$$without\beginremains an inline formula.
Installation & Enablement¶
- Search and install from the plugin marketplace.
- For manual installation, three conditions must be met in the profile’s
package.json:
1. Declared independencies:
"dependencies": {
"dsh-latex-render-fix": "link:./path/to/dsh-latex-render-fix"
}
- Listed by name in
dsh.profile.bundlesin the same file:
"dsh": {
"profile": {
"bundles": ["...", "dsh-latex-render-fix"]
}
}
node_modules/dsh-latex-render-fixmust be resolvable.
- If it is only placed innode_moduleswithout being declared independencies, the package manager and upgrade process will treat it as redundant and remove it.
Logging & Debugging¶
- Log location:
~/.dsh/dsh-guard/plugin.log. - The environment variable
DSH_LATEX_GUARD_HOMEcan redirect it elsewhere. - Manual invocation:
node lib/index.js # auto-locates app.asar
node lib/index.js --asar "<path>/app.asar"
- Example log for a successful patch application:
target bundle: /dsh/node_modules/@deepseek-ai/dsh-web-frontend/dist/assets/index-xxxxxxxx.js
render entry patched (param name e)
fK non-streaming entry patched (fK/t)
Rearrangement complete: delta=+218 shift=+0 translated nodes=10104
Patch applied (backup: app.asar.bak-20261119-164225)
- Seeing anchor hits of 0/2 means the minified structure of this DSH version has changed and the anchors no longer match; the plugin will skip without corrupting the file.
Permissions & Rollback¶
- The official DSH installer uses a per-user installation (
%LOCALAPPDATA%\Programs\DeepSeek Harness), writable by the standard user, and does not require administrator privileges. - If installed in a protected directory such as
C:\Program Files, DSH must be launched once as an administrator; otherwise the plugin will log a “no write permission” message and skip. - Before patching, a backup is created under
resources/app.asarasapp.asar.bak-<timestamp>, with only the 2 most recent kept. - Rollback command:
copy /Y "<dsh>/resources/app.asar.bak-<latest>" "<dsh>/resources/app.asar"
- Full uninstall: remove
dsh-latex-render-fixfromdsh.profile.bundles, deletenode_modules/dsh-latex-render-fix, then restore the asar as described above.
Risk Disclosure¶
The plugin modifies app.asar in the DSH installation directory (+218 bytes; all other bytes are shifted in place). Safety measures taken include:
- In-place state detection: if the normalized code is already present in the bundle, it is left untouched.
- Anchors use “property name + logical structure” (this.lastText / this.lastRendered / f.current=null), not relying on minified variable names.
- Syntax check (node --check) is performed before writing; if it fails, the operation is abandoned.
- Backup before writing, size verification after writing, automatic rollback on mismatch.
- Any exception is only logged and does not block DSH startup.
It is recommended to keep your own copy of the resources directory before making changes.
Use Cases & Caveats¶
- Suitable for users who need block-level LaTeX formulas to render correctly in the DSH chat window.
- The plugin runs with the permissions of the current DSH process and modifies
app.asar; please assess the risk yourself. - It is recommended to review the repository source code and license (MIT) before installing.
- The first startup after an upgrade may still show red formulas—this is determined by the upstream mechanism and typically resolves on the second startup.