Skip to content
D-CSIL™

AI Guide · 2026-11-30 · 1:04 PM CT

Markdown in, document out: Pandoc in six steps

Paul Derrington, Jr.

By Paul Derrington, Jr.

CEO | Chief Engineer | Research Engineer | Editor, D-CSIL

4 min read

Follow @PaulDerrington on X

Key Takeaways

Pandoc is a free command-line tool that turns Markdown into standalone HTML with a table of contents or a Word document with reusable styles. This guide walks through both conversions.

Steps 1-2 — Install Pandoc, then write one plain-text file

Step 1: install Pandoc from the official installer for your platform. On a Mac, Homebrew works too: brew install pandoc. On Windows, the installing page also lists winget install --source winget --exact --id JohnMacFarlane.Pandoc. On Linux, check your package manager's version first — Pandoc's own installing page warns it may be outdated, and offers a current binary package instead. Whatever route you take, prove it worked: pandoc --version should print a version number. Pandoc has no window or buttons; every step below is one line in a terminal.

Step 2: write your document in a text editor, not a word processor, and save it as notes.md. Start the file with a metadata block: a line of three dashes, then title, author, and date lines, then a closing line of three dots or dashes. The User's Guide is specific about the format: putting the block at the very beginning works across Pandoc’s Markdown variants. Do not leave a blank line immediately after the opening dashes. Below it, write normally — one # for the main headings, ## for subheadings, dashes for lists. That structure is what Pandoc turns into the finished document's headings, title, and contents list.

Step 3 — Make a standalone web page with a contents list

Run: pandoc notes.md -s --toc --number-sections -o notes.html. Each part does one job. The -s flag makes a complete HTML document instead of an HTML fragment. --toc inserts a table of contents built from your headings. --number-sections numbers those sections. The -o flag names the output file, and Pandoc guesses the output format from the .html extension, so no format flags are needed.

Open notes.html in a browser and check three things: the title from your metadata block appears, the contents list links to your headings, and the sections are numbered. In our test run for this guide — Pandoc 3.9, a two-section sample file — all three were present in the output. If the contents list is missing, the usual cause is headings written as bold text instead of real # headings; Pandoc builds the list from headings only.

Steps 4-5 — Make a Word file, styled your way

Step 4: a plain conversion already works — pandoc notes.md -o notes.docx produces a Word document with your headings and lists intact. Step 5 is what makes it look like your document instead of a default one. First, extract Pandoc's default style file: pandoc -o custom-reference.docx --print-default-data-file reference.docx. Open custom-reference.docx in Word or LibreOffice and change the styles — Title, Heading 1, Heading 2, Normal, and the rest of the named styles Pandoc uses. Change styles only: the User's Guide says the reference file's contents are ignored, while its styles, margins, page size, header, and footer are carried into your document.

Then rebuild with your styles: pandoc notes.md --reference-doc=custom-reference.docx -o notes.docx. Keep the custom reference file next to your notes; every future draft can reuse it, so a report series looks the same each time without anyone reformatting by hand. We ran both commands for this guide: the reference file was created, the styled conversion completed, and the resulting .docx contained the document's title and headings.

Step 6 — Check the output, and know the PDF trap before it bites

Open both outputs before you send either one. Check the title page information, one heading, one list, and one link in each file. Pandoc's User's Guide is plain about the limit: it preserves a document's structure, not every formatting detail, and elements such as complex tables may not survive every conversion. A two-minute check catches that; a recipient should not be the one to find it.

The trap: PDF is not one more extension swap. Asking for notes.pdf makes Pandoc call a separate PDF engine — LaTeX by default — and if none is installed, the command fails with an error naming the missing engine. Our test machine produced exactly that error: pdflatex not found. The fix is to install a LaTeX distribution (the getting-started guide names MacTeX on a Mac, MiKTeX on Windows, and TeX Live on Linux) or pick another engine with --pdf-engine. Until then, send the HTML or the Word file — both are finished documents, not drafts.

Disclaimer: Derrington Collaborative AI is my personal business, operated independently of and outside my official U.S. Government position and duties. The views and opinions expressed on this site and on any and all of my social media accounts are my own. They do not reflect the official policy or position of the Department of the Army, the Department of Defense, or the U.S. Government. Mention of any company, product, or service does not constitute an official endorsement.