Pandoc Markdown to Word: The Complete Guide

Master Pandoc, the most powerful command-line tool for converting Markdown to Word (DOCX). This comprehensive tutorial covers installation, basic commands, advanced options, custom templates, and troubleshooting to help you produce professional Word documents from Markdown sources.

Updated: March 2026 10 min read

What is Pandoc?

Pandoc is a free, open-source universal document converter created by John MacFarlane, a philosophy professor at the University of California, Berkeley. Often described as the "Swiss Army knife" of document conversion, Pandoc can convert files between dozens of markup formats, including Markdown, HTML, LaTeX, Microsoft Word (DOCX), EPUB, PDF, and many more.

What makes Pandoc the most powerful tool for converting Markdown to Word? Unlike simple online converters that only handle basic formatting, Pandoc provides granular control over every aspect of the output. You can apply custom Word templates (reference documents), generate tables of contents, handle citations with BibTeX, render mathematical equations, apply syntax-highlighted code blocks, and much more — all from the command line.

Pandoc is written in Haskell and runs on Windows, macOS, and Linux. It is actively maintained and has a vibrant community with hundreds of contributors. Whether you are a developer writing technical documentation, an academic preparing research papers, or a writer drafting a book manuscript, Pandoc gives you the control and flexibility that no GUI tool can match.

40+
Supported Formats
10M+
Downloads
100%
Free & Open Source

Installation

Pandoc is available on all major operating systems. Choose your platform below for step-by-step installation instructions.

Installing Pandoc on Windows

  1. Option 1: MSI Installer (Recommended)

    Download the latest .msi installer from the Pandoc releases page. Run the installer and follow the prompts. Pandoc will be added to your PATH automatically.

  2. Option 2: Chocolatey
    choco install pandoc
  3. Option 3: Winget
    winget install --id JohnMacFarlane.Pandoc

Verify the installation by opening a terminal and running:

pandoc --version

Installing Pandoc on macOS

  1. Option 1: Homebrew (Recommended)
    brew install pandoc
  2. Option 2: PKG Installer

    Download the .pkg file from the Pandoc releases page and double-click to install.

Verify installation:

pandoc --version

Installing Pandoc on Linux

  1. Ubuntu / Debian
    sudo apt-get install pandoc
  2. Fedora
    sudo dnf install pandoc
  3. Arch Linux
    sudo pacman -S pandoc
  4. Latest Version (All Distros)

    For the latest version, download the .deb or .tar.gz package from the GitHub releases page.

Verify installation:

pandoc --version

Basic Usage

The simplest way to convert a Markdown file to Word with Pandoc is a single command. Pandoc automatically detects the input and output formats based on file extensions.

The Essential Command

pandoc input.md -o output.docx

pandoc — Calls the Pandoc executable.

input.md — The source Markdown file. Pandoc reads this and parses it into an internal AST (Abstract Syntax Tree).

-o output.docx — The -o flag specifies the output file. The .docx extension tells Pandoc to generate a Microsoft Word document.

Specifying Formats Explicitly

You can also specify input and output formats explicitly using -f (from) and -t (to) flags:

pandoc -f markdown -t docx -o output.docx input.md

This is useful when your files don't have standard extensions or when you want to use a specific Markdown variant such as markdown_strict, gfm (GitHub Flavored Markdown), or commonmark.

Converting Multiple Files

Pandoc can accept multiple input files and combine them into a single output document:

pandoc chapter1.md chapter2.md chapter3.md -o book.docx

The files are concatenated in the order provided, making this ideal for assembling multi-chapter documents or reports from separate Markdown files.

Advanced Options

Pandoc's real power lies in its extensive command-line options. Here are the most important flags for producing professional Word documents.

--toc — Table of Contents

Automatically generates a table of contents at the beginning of the document based on your heading structure. You can control the depth with --toc-depth.

pandoc input.md -o output.docx --toc --toc-depth=3

This generates a TOC that includes headings up to level 3 (H1, H2, H3). The default depth is 3 if --toc-depth is omitted.

--reference-doc — Custom Word Template

Apply a custom Word template to control fonts, colors, spacing, and styles in the output document. This is the most powerful way to brand your documents.

pandoc input.md -o output.docx --reference-doc=custom-template.docx

To create a reference template, first generate a default one with pandoc -o custom-reference.docx --print-default-data-file reference.docx, then open it in Word and modify the styles (Heading 1, Heading 2, Body Text, etc.) to match your branding.

--filter — Custom Filters

Filters transform the document's AST (Abstract Syntax Tree) between parsing and writing, enabling powerful customizations such as cross-references, diagram rendering, and more.

# Using pandoc-crossref for figure/table numbering
pandoc input.md -o output.docx --filter pandoc-crossref

# Using a Lua filter (no external dependency needed)
pandoc input.md -o output.docx --lua-filter my-filter.lua

Lua filters are recommended for most use cases as they ship with Pandoc and don't require installing additional software. Popular filters include pandoc-crossref and pandoc-citeproc.

--metadata — Document Metadata

Set document metadata such as title, author, and date from the command line. These values populate the Word document's built-in properties and can appear on a title page.

pandoc input.md -o output.docx \
  --metadata title="My Report" \
  --metadata author="Jane Smith" \
  --metadata date="2026-03-18"

You can also define metadata in a YAML front-matter block at the top of your Markdown file, which is often more convenient for documents with rich metadata.

--number-sections — Numbered Headings

Automatically numbers your sections (1, 1.1, 1.1.1, etc.), which is essential for technical and academic documents.

pandoc input.md -o output.docx --number-sections

Combine with --toc for a fully navigable, professionally numbered document. You can also use --shift-heading-level-by=-1 to adjust heading levels.

Common Use Cases

Here are five practical, real-world command combinations that you can copy and use immediately.

1. Professional Report with TOC and Numbered Sections

Perfect for business reports, project documentation, and white papers.

pandoc report.md -o report.docx \
  --toc --toc-depth=3 \
  --number-sections \
  --reference-doc=company-template.docx \
  --metadata title="Q1 2026 Report"

2. Branded Document with Custom Template

Apply your company's fonts, colors, and layout to every document you generate.

# First, generate a default reference doc to customize:
pandoc -o custom-reference.docx --print-default-data-file reference.docx

# Then use it for all future conversions:
pandoc input.md -o output.docx --reference-doc=custom-reference.docx

3. Academic Paper with Citations

Handle bibliography and citations in APA, IEEE, Chicago, or any CSL style.

pandoc paper.md -o paper.docx \
  --citeproc \
  --bibliography=references.bib \
  --csl=apa.csl \
  --number-sections \
  --metadata link-citations=true

4. Document with Math Equations

Convert LaTeX math notation into native Word equation objects (OMML).

pandoc math-doc.md -o math-doc.docx

Pandoc automatically converts LaTeX math ($E = mc^2$ and $$\int_0^1 f(x)\,dx$$) into Word's native OMML format, which renders beautifully in Microsoft Word without any additional plugins.

5. Syntax-Highlighted Code Documentation

Generate developer documentation with properly highlighted code blocks.

pandoc api-docs.md -o api-docs.docx \
  --highlight-style=tango \
  --toc \
  --metadata title="API Documentation v2.0"

Available highlight styles include pygments, tango, espresso, zenburn, kate, monochrome, breezeDark, and haddock. List all available styles with pandoc --list-highlight-styles.

Troubleshooting Common Issues

Running into problems? Here are the five most common issues and their solutions.

Problem: "pandoc: command not found"

Cause: Pandoc is not installed or not added to your system's PATH.

Solution: Reinstall Pandoc using the official installer (which adds it to PATH automatically). On Windows, restart your terminal after installation. On macOS/Linux, ensure /usr/local/bin is in your PATH. Verify with pandoc --version.

Problem: Images Not Appearing in Output DOCX

Cause: Image paths in your Markdown are relative, and Pandoc cannot find them from the current working directory.

Solution: Use the --resource-path flag to specify where images are located, or use absolute paths. Example: pandoc input.md -o output.docx --resource-path=./images. For remote images, Pandoc will fetch them automatically if you have network access.

Problem: Formatting Looks Wrong or Missing

Cause: The default Word template may not match your expectations, or your Markdown syntax may have issues (e.g., missing blank lines before lists).

Solution: Create a custom reference document with --reference-doc to define exactly how each style should look. Also ensure your Markdown follows proper syntax — Pandoc requires a blank line before and after lists, block quotes, and code blocks for correct parsing.

Problem: UTF-8 / Encoding Errors

Cause: Your Markdown file is not saved in UTF-8 encoding, or it contains BOM (Byte Order Mark) characters.

Solution: Save your Markdown file as UTF-8 without BOM. In VS Code, click the encoding indicator in the status bar and select "Save with Encoding" → "UTF-8". On the command line, you can convert encoding with iconv -f WINDOWS-1252 -t UTF-8 input.md -o input-utf8.md.

Problem: Tables Not Rendering Properly

Cause: Pandoc's default Markdown table syntax is strict. Pipe tables require proper alignment and separator rows.

Solution: Ensure your tables use the correct pipe table syntax with a separator row of dashes. Use -f gfm for GitHub Flavored Markdown table support. Example of a correct table:

| Header 1 | Header 2 |
|----------|----------|
| Cell 1   | Cell 2   |

Pandoc vs Online Tools

Pandoc is an incredibly powerful tool, but it is not always the best choice. Here is a quick comparison to help you decide when to use Pandoc and when an online tool may be more appropriate.

Feature Pandoc (CLI) Online Tools
Setup Required Yes (install) No
Customization Extensive Limited
Batch Processing Excellent Usually not supported
Custom Templates Full support Varies
Citations / Bibliography Full support Not supported
Ease of Use Learning curve Paste and click
Privacy 100% local Depends on service
Cost Free Free to paid

Use Pandoc When:

  • - You need maximum control over output formatting
  • - You are converting documents in batch or as part of a CI/CD pipeline
  • - Your documents include citations, math, or cross-references
  • - Privacy is critical and data must stay on your machine
  • - You need reproducible builds with version-controlled templates

Use Online Tools When:

  • - You need a quick, one-off conversion
  • - You don't want to install any software
  • - Your document uses basic Markdown formatting
  • - You are on a device where you can't install programs
  • - You want a visual preview before downloading
Try our free online converter →

Frequently Asked Questions

Is Pandoc free to use?

Yes, Pandoc is completely free and open-source software, released under the GPL license. You can use it for personal, commercial, and academic purposes without any cost. The source code is available on GitHub, and the project is actively maintained by its creator and a community of contributors.

Can Pandoc handle images embedded in Markdown?

Yes, Pandoc embeds images directly into the DOCX file. It supports both local images (relative or absolute paths) and remote images (URLs). For local images, make sure the paths are correct relative to where you run the pandoc command, or use the --resource-path flag to specify image directories. Remote images are downloaded automatically during conversion.

How do I use a custom font in my Word output?

Pandoc uses a reference document (--reference-doc) to define styles. To change fonts, generate a default reference document, open it in Word, modify the styles (Heading 1, Normal, etc.) to use your desired fonts, save the file, and then use it as your reference document for all future conversions. The fonts must be installed on the machine where the DOCX is opened.

Can I convert Word (DOCX) back to Markdown with Pandoc?

Absolutely. Pandoc works in both directions. Simply reverse the command: pandoc input.docx -o output.md. Note that some complex Word formatting (e.g., text boxes, advanced tables, SmartArt) may not convert perfectly, as Markdown has a simpler formatting model. For best results, use clean, well-structured Word documents.

How do I automate Pandoc conversions in a build pipeline?

Pandoc integrates easily into CI/CD pipelines. You can install it in a Docker container, GitHub Actions workflow, or any build system. Use a Makefile or shell script to define your conversion commands with all options, and run them as part of your build process. For example, in GitHub Actions you can use pandoc/core Docker image or install via apt-get install pandoc in your workflow YAML.

Prefer a Faster, No-Install Solution?

Try our free online Markdown to Word converter. Paste your Markdown, click convert, and download your DOCX instantly — no command line required.

Convert Markdown to Word Now →

100% free • No sign-up • Privacy-first

Related Articles