Skip to content
ucli

docx2md

Word to Markdown

Convert Microsoft Word documents with complex mathematics to Markdown with LaTeX equations

Install docx2md

ucli build docx2md

It needs Python 3.9 or later and Pandoc, and installs with uv into ~/.local/bin.

Why docx2md?

For technical books, academic papers and scientific documents written in Word

  • Equations

    Word equations become LaTeX. Equation numbers such as #(1.2.3) become \tag{1.2.3}.

  • Images and Tables

    Pictures are extracted into one image directory and referenced; Word tables become Markdown tables.

  • Front Matter

    The dedication, copyright page and title page of the document are kept as their own sections.

  • Batch Processing

    Convert every Word document in a directory in one command.

  • Verification

    docx2md verify reads the Word file's XML and compares it with the Markdown, and names anything lost or changed.

  • Corrections with Proof

    docx2md edit makes one exact correction and copies the rest of the file byte for byte; docx2md diff lists every difference between two Word files.

Options

CommandWhat it does
docx2md convert <file.docx> [output.md]Convert one Word document to Markdown with LaTeX
docx2md batch <input-dir> <output-dir>Convert every Word document in a directory
docx2md verify <file.docx> <file.md>Compare the Markdown with the Word document; exit status 1 on a failed check
docx2md edit <in.docx> <out.docx> --replace OLD NEWMake one exact correction in a table cell or a paragraph
docx2md diff <a.docx> <b.docx>List every difference between two Word documents (--expect N, -o report.md)

Examples

Convert, then verify

docx2md convert book.docx book.md
docx2md verify book.docx book.md

Convert a directory

docx2md batch ./files/input ./files/output

Prove a correction

docx2md edit book.docx book-corrected.docx --replace "teh" "the" --paragraph "the words around teh typo"
docx2md diff book.docx book-corrected.docx --expect 1 -o change-0001.md

Read the docs View on GitHub