dsh-tex-block-normalizer: Fixing the Misinterpretation of Pandoc-Style `$$` Equation Blocks in DSH

Preface

When viewing model replies in DSH Web, inline math sometimes turns entirely into red plain text, and hovering reveals a KaTeX ParseError. The same Markdown renders fine in VS Code’s preview. A common cause is that models write $$ in the Pandoc style: opening delimiter and the first line of the formula on the same line, with the closing $$ at the end of the last line. DSH’s Markdown syntax mishandles these shapes, silently dropping the first line, or an unclosed $$ swallows following prose, tables, and even later formulas into a single math node, causing KaTeX to raise errors. The community plugin dsh-tex-block-normalizer (maintained by TianzeLuo; category: workflow) normalizes those variants into the “$$ on its own line” form that DSH can accept, without modifying the original text already saved in the session.

What is this

dsh-tex-block-normalizer is a plugin for the DSH Web client: before Markdown parsing, it normalizes Pandoc-style $$ display-math blocks by moving the newlines that surround $$. Only the line breaks around $$ are adjusted; the TeX content inside the block is left unchanged. Normalization happens at render time, so history messages display correctly after a refresh without needing to resend them.

Symptoms and shapes DSH accepts

Models often write inline math like this (opening $$ on the same line as the content, body spanning multiple lines, closing $$ attached to the last line):

$$\frac{\partial}{\partial y} = 1
\quad\Longrightarrow\quad
x = y$$

In DSH, you may see: the first line being silently dropped as an info string; when the $$ block is not closed, everything from the second line to the end of the message being swallowed; KaTeX receiving a whole block of non-TeX text and reporting ParseError: ... Can't use function '$' in math mode ..., shown as red plain text in the UI.

The README summarizes what DSH 0.1.7-rc.1 accepts as follows (the plugin aims to rewrite the patterns in the last three rows into the first-row form):

Writing pattern DSH 0.1.7-rc.1 behavior
$$ on its own line … $$ on its own line Works correctly
Entire formula on one line $$ … $$ Works correctly
Opens with $$content, closes with $$ on its own line First line is silently dropped
Opens with $$ on its own line, closes with content$$ Swallows the rest of the document
Opens with $$content and closes with content$$ Drops the first line and swallows the document

Core features

  1. Pre-render normalization: Unifies the problematic $$ layouts above into the form where the opening and closing $$ each occupy their own line, without altering the formula text inside the block.
  2. Works with history messages: Does not modify session data; only affects the current Web Markdown rendering path.
  3. Observable and can be disabled: Logs a single activation message to the console; you can check installation status and the number of rewrites via a global object; can be disabled before page load.
  4. Companion audit script: A repository script lets you compare any Markdown before and after normalization (uses the same syntax and KaTeX-related pipeline as DSH; see the verification section below).

For implementation details, root-cause analysis, and boundary conditions, see the repository’s docs/ (e.g., root-cause.md, how-it-works.md, limitations.md).

Installation and activation

The plugin runs with the permissions of the current dsh process; review the source and the MIT license before installing. Use the directory that contains this package in the install command; do not construct github:owner/repo forms that are not shown in the documentation.

Assuming you have obtained the plugin directory, run:

dsh plugin --profile web add <this-package-directory>

Then restart dsh web and refresh the browser page.

Verifying effectiveness

  1. After refresh, you should see one console message:
    [dsh-tex-block-normalizer] active: Pandoc-style $$ blocks are normalized before Markdown parsing
  2. In DevTools, inspect __DSH_TEX_BLOCK_NORMALIZER__; expected shape: { installed: true, reason: 'installed', stats: { calls, rewrites } }; an increasing rewrites count indicates rewrites are occurring.
  3. Open a previously erroring history message; the red plain text should disappear, and formulas should render correctly.
  4. Temporarily disable: before page load, set globalThis.__DSH_TEX_BLOCK_NORMALIZER_DISABLE__ = true.
  5. Audit local Markdown from the command line (comparison before and after normalization):
node scripts/audit-markdown.mjs <file.md>

(This requires being in the plugin repository and having installed the dev dependencies per the README.)

Typical usage and applicable scenarios

Use when: You often read model output containing inline math in DSH Web; models prefer Pandoc-style $$ line breaks; you want to restore readable rendering without changing upstream DSH.

Cases the plugin does not handle (see the “Limitations” section of the README):

  • $$ inside block quotes or list items (e.g., > $$a, - $$a) are not processed.
  • Blocks that have no closing $$ remain unchanged and may still swallow to the end of the file.
  • Relies on React internals such as the inner .type under React.memo; if it cannot be obtained, the plugin quietly becomes a no-op and does not break the UI.

The community plugin catalog (SkillHub) and DeepSeek/Hunyuan have no official affiliation; the DSH ecosystem emphasizes “everything is a plugin,” and this package is a workflow-class addition.

Development and testing (optional)

If you want to modify normalization logic or contribute patches, the repository README provides:

npm install     # devDependencies for test-only parser / katex
npm test        # 21 tests: normalization cases + bundle artifacts + DSH syntax acceptance
npm run build   # after editing lib/normalize.js, regenerates lib/client.js

Runtime requirement: Node >=22.5 (see engines in package.json).

Conclusion

dsh-tex-block-normalizer targets DSH Web’s misparsing of Pandoc-style $$, restoring KaTeX rendering with minimal changes via newline normalization. It is effective for existing session records as well. Install using the official README command dsh plugin --profile web add <this-package-directory>, and self-check via the console and __DSH_TEX_BLOCK_NORMALIZER__.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye