Markdown to Word with Pandoc

A practical guide to pandoc in.md -o out.docx: the flags that matter, where the output loses Mermaid, image sizes and styles, and how to fill those gaps without leaving the browser.

Free · no install

Converting with Pandoc

The one-line version:

pandoc in.md -o out.docx

With your own styles and a table of contents:

pandoc in.md -f gfm --reference-doc=styles.docx --toc -o out.docx

Pandoc handles headings, lists, tables and LaTeX math well. It does not render Mermaid, images keep their pixel size, and --toc only works if the reference doc has a TOC style.

Paste the same Markdown here to compare the result.

Converted in your browser. Your file never leaves your device.
1

Install Pandoc

brew install pandoc, choco install pandoc or apt install pandoc. No LaTeX distribution is needed for .docx output.

2

Run the command

pandoc in.md -o out.docx. Add -f gfm for GitHub tables and task lists, and --reference-doc for styles.

3

Fix what Pandoc cannot

Mermaid, image sizing and heading styles need filters or manual work. Or paste the same file above and download.

Pandoc Markdown to Word: what it does, what it drops, and how to fill the gaps

Pandoc is the reference tool for document conversion and its .docx writer is excellent. It produces real Heading styles, native tables, list numbering and, remarkably, native Word equations from LaTeX without needing a LaTeX installation, because it writes OMML directly. If you live in a terminal and convert the same kind of file every week, a Makefile with a pandoc line is hard to beat. This page explains the command, the flags that make a difference, and the specific places where the output falls short so you can decide what to do about them.

The commands

The minimal form is pandoc in.md -o out.docx. Pandoc infers the output format from the extension. Its default input dialect is Pandoc's own Markdown, which differs from GitHub's: pipe tables work, but task lists, strikethrough with tildes and autolinked URLs need -f gfm. To match the look of an existing document, run pandoc --print-default-data-file reference.docx > styles.docx, open styles.docx in Word, modify the styles Normal, Heading 1 to 6, Body Text, Source Code, Block Text, Table and Compact, save, and pass --reference-doc=styles.docx. --toc inserts a table of contents field that Word fills in when you open the file and accept the update prompt. --number-sections prefixes headings with numbers, and --resource-path tells Pandoc where to find relative images. For math, nothing extra is required; $…$ and $$…$$ convert to equations by default.

Where the output loses fidelity

Mermaid. A ```mermaid block is just a code block to Pandoc and arrives in Word as monospace text. Rendering it requires the mermaid-filter package, which pulls in Node.js and a headless Chromium, and the output is a fixed-DPI PNG. Image size. Pandoc embeds images at their pixel dimensions using 96 dpi. A 1600-pixel screenshot becomes a 42 cm picture that overflows the page until you resize it by hand or add {width=100%} attributes to every image in the source. Heading and table styles. Without a reference document the output uses Pandoc's plain defaults, and table header shading is absent because Pandoc's default table style has none. Equation numbering. Pandoc does not number display equations; that requires the pandoc-crossref filter, a separate Haskell binary that must match your Pandoc version. Column widths. Pipe tables get equal widths unless the dash counts in the separator row are made proportional to the desired widths, which nobody remembers to do. Preview. There is none; you open the .docx to find out.

How MDtoDOCX covers the gaps

MDtoDOCX uses the same style names as Pandoc, so a reference document built for Pandoc works as a Word template here with no changes. On top of that it renders Mermaid diagrams to SVG in the browser, scales images to the printable width automatically, estimates table column widths from content and shades header rows, numbers display equations with SEQ fields and resolves cross-references without a filter, and shows a live Word-style preview before you download. Nothing is installed and nothing is uploaded. The trade-off is that Pandoc scripts and runs in batch on a server, while MDtoDOCX runs interactively in a tab; Pro adds batch conversion for people who need both.

Using the two together

They are not exclusive. A common pattern is to keep Pandoc in a CI pipeline for release notes and use MDtoDOCX for anything with diagrams, screenshots or equations that needs to look right the first time. Because both produce standards-compliant .docx files, a document from either can be post-processed by the other or opened in Word, LibreOffice and Google Docs. For inline math specifics see Markdown to Word with formulas, and for the inline formatting mapping that both tools share, see Markdown to Word with formatting.

Pandoc vs MDtoDOCX vs copy-paste, feature by feature

FeaturePandocMDtoDOCXCopy into Word
Heading stylesNativeNativeBold text only
LaTeX mathNative OMML, no LaTeX installNative OMML (Pro)Raw text
Equation numberingpandoc-crossref filterBuilt in (Pro)Manual
Mermaidmermaid-filter + Node + ChromiumBuilt in, SVG (Pro)Lost
Image sizingPixel size, often overflowsFit to page widthBrowser size
Table header shading and widthsNeeds reference doc; equal widthsAutomaticInconsistent
Custom styles--reference-docUpload .docx (Pro), same style namesReapply by hand
PreviewNoneLive Word-style previewn/a
Scripting and batchExcellentBatch in ProNone
InstallBinary plus filtersNoneNone
PriceFree, open sourceFree core, Pro for math, diagrams, templatesFree

Frequently asked questions

What is the basic pandoc command for Markdown to Word?
pandoc in.md -o out.docx. Pandoc detects the output format from the .docx extension. Add -f gfm if your file uses GitHub features such as task lists or tildes for strikethrough.
Do I need LaTeX installed for pandoc to convert math to Word?
No. For .docx output Pandoc writes Word's native OMML equations directly. A LaTeX distribution is only needed for PDF output via LaTeX.
How do I apply my own styles with pandoc?
Export the default reference document, modify its styles in Word, and pass it with --reference-doc=styles.docx. The same file works as a template in MDtoDOCX.
Why are my images huge in the pandoc output?
Pandoc places images at their pixel size at 96 dpi, so large screenshots overflow the page. Add width attributes in the Markdown or resize in Word. MDtoDOCX scales images to the printable width automatically.
Can pandoc render Mermaid diagrams?
Not on its own. You need the mermaid-filter package with Node.js and a headless browser, and the result is a PNG. MDtoDOCX renders Mermaid to SVG in the browser without installing anything.
Does pandoc --toc produce a table of contents in Word?
It inserts a TOC field. Word asks to update fields when the file opens and then fills it in. If nothing appears, right-click the field and choose Update Field.
How do I number equations with pandoc?
Install pandoc-crossref matching your Pandoc version and label equations with {#eq:name}. MDtoDOCX uses the same label syntax and numbers equations without a filter.
Is MDtoDOCX a replacement for pandoc?
For interactive conversion of documents with diagrams, images and equations, yes. For scripted batch pipelines, Pandoc remains the better tool and the two produce compatible .docx files.