FormalDoc turns Markdown into polished Word documents.
It is built for people who draft with AI tools, write in Markdown, and still need a real .docx
deliverable with formal styles, headings, tables, spacing, and editable equations.
- Web app: formaldoc.app
- npm package:
formaldocon npm - AI skill:
skills/formaldoc/SKILL.md
AI tools are good at drafting, but Word output is still painful. Copying from ChatGPT, Claude, DeepSeek, Kimi, Qwen, Doubao, or other tools often leaves you fixing:
- broken heading levels
- inconsistent fonts and spacing
- tables copied as messy rich text
- LaTeX formulas that become plain text or screenshots
- Chinese official-document layouts that are hard to reproduce manually
FormalDoc closes that gap. Write or generate content in Markdown first, then export a .docx that
is much closer to a final document.
Paste Markdown or rich text from an AI chat window. FormalDoc normalizes it into Markdown while preserving the parts that matter:
- headings
- lists
- tables
- code blocks
- bold, italic, links, and inline structure
It is designed for the way AI-generated content is actually copied and edited.
FormalDoc has first-class LaTeX math support. Formulas are converted into native Word equations, so they remain editable in Microsoft Word instead of being flattened into images.
Choose from Chinese and English templates for official documents, reports, academic writing, business documents, and legal-style documents.
The web app generates documents in the browser. For one-off exports, you can paste, choose a template, and download without setting up a backend workflow.
FormalDoc is also a published npm package, CLI, and AI-agent building block. Use the same document engine from the browser, Node.js scripts, terminal commands, or reusable AI skills.
Formula handling is one of the strongest parts of FormalDoc.
| Input | Word output |
|---|---|
$E = mc^2$ |
Inline editable Word equation |
$$\frac{a}{b}$$ |
Centered block equation |
$\sum_{i=1}^{n} x_i$ |
Inline equation with limits |
$$\begin{cases} a & x > 0 \\ b & x \le 0 \end{cases}$$ |
Structured block equation |
Supported formula scenarios include:
- inline math inside normal paragraphs
- block math between paragraphs
- fractions, roots, sums, integrals, products, Greek letters, accents, matrices, and cases
- formulas mixed with bold or emphasized text
- AI-copied LaTeX that may contain escaped backslashes
The conversion path is LaTeX to MathML to OMML to Word equation objects. In practical terms, that
means the generated .docx uses Word's native math model instead of a screenshot-based workaround.
FormalDoc ships with 8 built-in templates.
| Template | Best for |
|---|---|
cn-gov |
Chinese government and official documents, GB/T 9704-style layout |
cn-general |
General Chinese documents |
cn-academic |
Chinese academic writing |
cn-report |
Chinese reports, work summaries, and briefings |
en-standard |
Standard English documents |
en-business |
Modern English business documents |
en-academic |
English academic papers |
en-legal |
English legal or contract-style documents |
- Open formaldoc.app
- Paste Markdown or rich text copied from an AI tool
- Choose a template
- Download the generated
.docx
npx formaldoc input.md -o output.docxnpm install formaldocnpm install -g formaldoc
formaldoc input.md -o output.docxFormalDoc supports GitHub Flavored Markdown plus LaTeX math.
| Markdown | Output |
|---|---|
# Title |
Document title |
## Heading |
Heading 1 |
### Heading |
Heading 2 |
#### Heading |
Heading 3 |
##### Heading |
Heading 4 |
| Paragraphs | Body text |
**bold** |
Bold text |
*italic* |
Italic text |
~~strike~~ |
Strikethrough |
[text](url) |
Hyperlinks |
- item / 1. item |
Lists |
> quote |
Blockquotes |
`code` |
Inline code |
| Code fences | Code blocks |
| GFM tables | Word tables |
$...$ |
Inline equations |
$$...$$ |
Block equations |
# Default template: cn-gov
formaldoc document.md
# Write to a specific file
formaldoc document.md -o output.docx
# Pick a template
formaldoc document.md -t en-standard
# Read from stdin
cat document.md | formaldoc --stdin -o output.docx
# Help
formaldoc --helpFormalDoc is ESM-first.
import { writeFile } from 'node:fs/promises';
import { convertMarkdownToDocx } from 'formaldoc';
const result = await convertMarkdownToDocx({
markdown: '# Hello\n\nGenerated by FormalDoc.',
templateName: 'en-business',
});
await writeFile('output.docx', result.buffer);
console.log(result.outputPath ?? 'output.docx');When you already have a .md file, prefer the file-based API:
import { convertMarkdownToDocxFile } from 'formaldoc';
const result = await convertMarkdownToDocxFile({
inputPath: './input.md',
outputPath: './output.docx',
templateName: 'cn-report',
});
console.log(result.outputPath);FormalDoc is especially useful in AI-assisted document workflows.
Typical flow:
- The AI writes or receives Markdown content
- The AI selects a template
- The AI installs
formaldocfrom npm - The AI runs the Node API or CLI
- The AI returns the generated
.docx
This means the AI can produce a real Word document, not just draft text.
This repo includes a reusable skill at skills/formaldoc/SKILL.md.
The skill helps an AI tool:
- choose an appropriate template
- prefer file-based conversion when a Markdown file already exists
- fall back to inline conversion when needed
- save the generated
.docxas a real output artifact
If you use Claude Projects, Claude Code style environments, Codex, or other agent systems with reusable instructions, start from:
If you use the skills installer ecosystem, install the skill directly from this GitHub repository:
npx skills add https://github.com/shrektan/formaldoc --skill formaldocExamples:
# Install globally for Claude Code
npx skills add https://github.com/shrektan/formaldoc --skill formaldoc -g -a claude-code -y
# Install globally for Codex
npx skills add https://github.com/shrektan/formaldoc --skill formaldoc -g -a codex -yNotes:
- this flow installs the skill from GitHub, not from the npm tarball
- the repository must be pushed to GitHub before others can install the latest skill version
- the skill name is
formaldoc, which matches the included frontmatter
npm run dev
npm run build
npm run lintProject layout:
src/: React app and document generation logiccli/: CLI entrypointdocs/: supporting documentationskills/: AI skill definitions included with the repo
Apache-2.0. See LICENSE.
