markdown-to-word
Convert Markdown files with LaTeX math, tables, and images to professionally formatted Word (.docx) documents. This skill should be used when users need to convert markdown academic papers to Word format, especially those following Zhejiang University Master of Engineering Management thesis body-format requirements such as FangSong body text, 1.5 line spacing, justified paragraphs, and three-line tables.
Markdown to Word Conversion
Overview
Convert Markdown (.md) files to Word (.docx) documents using the bundled Node.js converter. The current default style profile is aimed at the common body-format requirements of the Zhejiang University Master of Engineering Management thesis, especially for 正文、标题、段落和表格。
Core Tool
All scripts are bundled inside this skill directory:
skills/markdown-to-word/
├── convert_md_to_docx.sh # Main entry point
├── md2docx.mjs # Markdown → docx main converter
├── latex2math.mjs # LaTeX math → docx math objects
├── SKILL.md
└── AGENTS.md
Usage:
skills/markdown-to-word/convert_md_to_docx.sh [-o output.docx] input.md
- If
-ois omitted, output defaults toinput.docx - The script calls the bundled Node.js converter directly
- After generation, the resulting
.docxis opened automatically for preview on the local machine
Default Formatting Profile
- 正文:小四号、仿宋、首行缩进 2 字符
- 段落:1.5 倍行距、两端对齐
- 一级标题:小三号、仿宋、加黑
- 二级标题:四号、仿宋、加黑
- 三级标题:小四号、仿宋
- 表格:三线表
- 英文与数字:
Times New Roman
These defaults are intended to match the common body-text conventions of the Zhejiang University Master of Engineering Management thesis format. Cover pages, declarations, headers/footers, page numbers, TOC, and some school-specific front/back matter may still need manual finishing in Word.
Pipeline Architecture
input.md
↓ preprocessTabTables # 制表符表格 → Markdown 表格
↓ ensureParagraphBreaks # 补全段落断行
↓ fixChinesePunctuation # 中文语境标点规范化
↓ markdown-it parse # 解析标题、段落、列表、表格、公式、图片
↓ docx build # 应用正文/标题/表格样式
↓ output.docx
Key Behaviors
1. Paragraph Normalization
- Converts tab-separated pseudo-tables to standard Markdown tables
- Inserts missing paragraph breaks for Chinese academic drafts where lines are separated but blank lines are omitted
- Normalizes Chinese-context punctuation outside code and math spans
2. Typography Rules
- Body text uses 仿宋 for East Asian text and
Times New Romanfor Latin text - Normal paragraphs use 2-character first-line indent
- Body paragraphs use justified alignment and 1.5 line spacing
- Heading 1 is centered; heading 2 and heading 3 are left aligned
3. Table Rendering
- Markdown tables are converted to three-line tables
- Vertical borders are removed by default
- Header row and bottom rule are emphasized to fit thesis-style tables
4. Formula Rendering
- Supports inline math
$...$ - Supports display math
$$...$$ - Converts LaTeX expressions into docx math objects through
latex2math.mjs
5. Image Rendering
- Supports local PNG and JPEG images
- Auto-detects image size from file headers
- Scales down oversized images to fit the page width
Preview Workflow
When the user asks for conversion preview images:
- Update the target Markdown documentation page first.
- Run
skills/markdown-to-word/convert_md_to_docx.shon that Markdown file. - Open both the Markdown source and the generated Word document side by side.
- Let the user capture “before / after” screenshots from the local machine.
File Structure
All bundled in skills/markdown-to-word/ (see Core Tool section above).
Dependencies
- Node.js: required for
md2docx.mjs