dsh-formula-docx
Manifest validMarkdown to .docx with native Word equations (OMML), plus a PDF pass that verifies every formula renders.
dsh-formula-docx
Turn Markdown into a .docx whose equations are real Word equation objects
(OMML) — double-clickable and editable in Word, correct in WPS, sharp in PDF.
把 Markdown 变成公式是 Word 原生公式对象(OMML)的 .docx:在 Word 里可双击编辑,
WPS 正常打开,导出 PDF 不糊。不是公式图片,也不是上标下标拼出来的字。
https://github.com/Red-Rayux/dsh-formula-docx
安装:
dsh plugin add Red-Rayux/dsh-formula-docx
Why / 为什么
Documents with dozens of formulas are where normal Markdown-to-Word pipelines
fall apart: formulas arrive as images, or as x²-style character hacks, or as
LaTeX source that nobody can edit later.
公式密集的文档最容易在这一步翻车:公式变成图片、变成 x² 这种字符拼贴、
或者干脆留一堆 LaTeX 源码没人能改。
This plugin converts each formula through LaTeX → MathML → OMML and writes it
into the document as a native equation, then verifies the result by exporting a
PDF and looking at every page.
这个插件把每个公式走 LaTeX → MathML → OMML 转成原生公式写进文档,
再把文档导出 PDF 逐页看图校验。
Requirements / 依赖
| Need | Why |
|---|---|
| Python 3.9+ | runs the scripts |
pip install lxml latex2mathml python-docx | conversion + docx writing |
MML2OMML.XSL | ships with Microsoft Office; auto-detected, or set MML2OMML_XSL |
| Microsoft Word | only for the PDF preview pass (LibreOffice works as fallback) |
pip install pymupdf | only for the preview pass |
Without Office you can still generate the docx — you just lose the visual check.
Quick start / 快速开始
pip install lxml latex2mathml python-docx pymupdf
# 1. smoke test first -- do not skip this
python scripts/build.py /tmp/smoke.docx examples/smoke.md
python scripts/check_docx.py /tmp/smoke.docx --md examples/smoke.md
python scripts/preview.py /tmp/smoke.docx
# 2. then build your own document
python scripts/build.py out.docx ch01.md ch02.md ch03.md --cover cover.json
# 3. verify
python scripts/check_docx.py out.docx --md ch0*.md --pdf out.pdf
python scripts/preview.py out.docx --dpi 120
build.py accepts one or more markdown files (or globs), joins them in order,
optionally adds a cover page and page numbers.
What it supports / 支持的语法
# Headings (h1 auto page-breaks)
**Bold with an inline formula $E=\pi L$ inside.**
$$R=\frac{\pi\left(L-L_P\right)}{T_\phi\left(T_\theta E_0\cos\theta+E_D\right)}$$
[w:20,30,50]
| Quantity | Definition | Unit |
|---|---|---|
| Radiance | flux per projected area per solid angle | $\mathrm{W\cdot m^{-2}\cdot sr^{-1}}$ |
::: core
**Callout block** — holds paragraphs, lists, and display formulas.
:::
Full reference: references/syntax.md.
The six traps / 六个坑
Every one of these was hit in production, and each has a fix:
- A formula that appears twice renders as an empty box the second time —
the OMML node gets moved out of its first parent. Cache with
deepcopy. ns0:prefixes appear indocument.xmland WPS rejects the file — declarensmapat element creation, neversetxmlns on a live node.- Chinese characters inside
\text{}break the conversion — move the words out of the formula. - Numbered lists restart at 1 when a formula interrupts them — render the original numbers from the Markdown.
**bold with $x$ inside**prints the raw$x$— the bold branch must recurse instead of emitting one run.\xrightarrowdoes not survive the OMML mapping — split into formula + sentence + formula.
Details and code: references/pitfalls.md.
Verification is part of the job / 校验是流程的一部分
check_docx.py compares the equation count in the docx against the LaTeX in
the markdown sources. If they differ, a formula was dropped or double-rendered —
both are silent failures that only show up as a blank box or a doubled formula.
preview.py exports a PDF through Word and renders every page to PNG.
Layout bugs (squeezed table columns, an orphaned heading, a callout split across
pages) are invisible in the XML and obvious in the image.
License
MIT
Comments
Loading…
Similar plugins
by jiekesu967
Adds a markitdown tool that converts PDF, Word, Excel, PowerPoint, HTML, CSV, EPUB and URLs to Markdown, using a real Microsoft MarkItDown installation when one is reachable and a bundled dependency-f
★ 3
↓ 283/wk
MIT
TypeScript
Nov 4, 2026
dsh plugin --profile web add dsh-markitdownby jiavenzhong
DSH 插件:发送文件先转 Markdown — 让大模型直接读懂 PDF/Word/Excel/PPT/HTML/CSV/EPUB,基于 Microsoft MarkItDown
★ 0
MIT
JavaScript
Aug 18, 2026
dsh plugin --profile web add dsh-tool-markitdownby Z8906
读取 Office / PDF 前先转成 Markdown,用一行路径代替整份全文 —— 省 token 的 DSH bundle 插件。0 npm 依赖,转换全在本地,产物归你所有,卸载自动清理 Python 环境。 Convert Office/PDF to Markdown before reading in DeepSeek Harness — one path instead of the whole document.
★ 1
MIT
JavaScript
Nov 8, 2026
dsh plugin --profile web add dsh-plugin-office-markdownby zsy334
在DeepSeek harness工作区面板或 convert_document 工具中转换 Word、PDF、Markdown、HTML、TXT、Excel/CSV 与 PowerPoint 文件。
★ 0
MIT
JavaScript
Nov 3, 2026
dsh plugin --profile web add dsh-doc-convertby protoctistmoses143
Convert PDFs, Office docs, scanned images, and more to clean Markdown, JSON, or text locally with offline OCR—no servers, no API keys, fully private.
★ 0
MIT
TypeScript
Oct 13, 2026
dsh plugin --profile web add dsh-docby jiaoqsh
DeepSeek Harness plugin: read_document tool — Word, PowerPoint, Excel, OpenDocument, RTF, EPUB, CSV, and PDF as Markdown for the model
★ 6
↓ 490/wk
MIT
TypeScript
Oct 4, 2026
dsh plugin --profile web add @jiaoqsh/dsh-document