$npx -y skills add woodfishhhh/EZ_math_model --skill docxUse when EZ_math_model needs to convert paper.md to paper.docx, read a DOCX problem statement, preserve equations and tables, or package a modeling report as a Word document.
| 1 | # docx — Word 文档读写与打包 |
| 2 | |
| 3 | ## 何时使用 |
| 4 | |
| 5 | - 把 `paper.md` 转换为 `paper.docx`。 |
| 6 | - 读取用户上传的 `.docx` 题目。 |
| 7 | - 需要参考模板、图片嵌入、公式对象或表格保真。 |
| 8 | |
| 9 | ## 优先链路 |
| 10 | |
| 11 | 1. 宿主 `docx` skill。 |
| 12 | 2. `pandoc` 直调。 |
| 13 | 3. `python-docx` 兜底。 |
| 14 | |
| 15 | ## Markdown 转 DOCX |
| 16 | |
| 17 | ```powershell |
| 18 | pandoc paper.md ` |
| 19 | --from gfm+tex_math_dollars+pipe_tables ` |
| 20 | --to docx ` |
| 21 | --output paper.docx ` |
| 22 | --resource-path . |
| 23 | ``` |
| 24 | |
| 25 | 有参考模板时追加: |
| 26 | |
| 27 | ```powershell |
| 28 | --reference-doc <template.docx> |
| 29 | ``` |
| 30 | |
| 31 | ## DOCX 转文本 |
| 32 | |
| 33 | 优先使用宿主 `docx` skill。没有宿主能力时,用 `python-docx` 提取段落和表格,再写成 Markdown 友好文本。 |
| 34 | |
| 35 | ## 产出要求 |
| 36 | |
| 37 | - 输出文件默认与 `paper.md` 同目录:`paper.docx`。 |
| 38 | - 图片必须嵌入,不保留失效本地链接。 |
| 39 | - `$...$` 与 `$$...$$` 尽量转换为 Word 可编辑公式;失败时保留原始 LaTeX 文本并写诊断。 |
| 40 | |
| 41 | ## 对象级验收 |
| 42 | |
| 43 | DOCX 不是“文件存在就合格”。转换后必须把 `.docx` 当 zip 解包检查: |
| 44 | |
| 45 | - `word/document.xml` 必须存在且可读取。 |
| 46 | - 公式验收:统计 `m:oMath` / `m:oMathPara`。若 `paper.md` 有公式但 DOCX 中 |
| 47 | 公式对象数为 0,formal 模式失败。 |
| 48 | - 图片验收:统计 `word/media/*`。Markdown 图片引用数不得超过嵌入图片数; |
| 49 | 缺图必须列出文件名。 |
| 50 | - 表格验收:统计 `w:tbl`。Markdown 表格应转换为 Word 表格对象;未转换时至少 |
| 51 | 降级为 warning,formal 视严重程度阻塞。 |
| 52 | - LaTeX fallback:统计 `word/document.xml` 中残留 `$...$`。formal 模式下残留 |
| 53 | 公式文本不得直接标为通过。 |
| 54 | |
| 55 | EZMM 内置 `scripts/runtime/audit_export.py` 会执行上述检查,生成 |
| 56 | `export_audit.json` 与 `export_audit.md`。 |
| 57 | |
| 58 | ## 失败诊断 |
| 59 | |
| 60 | | 情况 | 处理 | |
| 61 | |---|---| |
| 62 | | 宿主 skill、pandoc、python-docx 都不可用 | 保留 `paper.md`,在 `diagnostics.md` 写缺失工具 | |
| 63 | | 公式渲染异常 | formal 模式阻塞正式发布;demo 模式保留 LaTeX 文本并降级 | |
| 64 | | 图片路径错误 | 检查 Markdown 相对路径和 `--resource-path` | |