Why Converting Markdown + LaTeX + Mermaid Into Real Word Docs Is Harder Than It Looks
If you work with ChatGPT, Claude, or technical Markdown docs every day, you have probably hit the same wall: The draft looks clean in Markdown—nested lists, tables, integrals, matrices, and a Mermaid diagram—and then so
If you work with ChatGPT, Claude, or technical Markdown docs every day, you have probably hit the same wall:
The draft looks clean in Markdown—nested lists, tables, integrals, matrices, and a Mermaid diagram—and then someone asks for a .docx file. You copy-paste it into Microsoft Word, and half the equations turn into raw $ strings, tables lose their borders, and the Mermaid block is just plain text.
I recently spent time building a pure client-side converter to generate real .docx files directly in the browser (zero server uploads). Here are the four things that surprised me most.
1. Word Doesn't Speak LaTeX—It Speaks OMML
Most developers assume you can just drop LaTeX or MathML into a .docx archive and Word will render it. It won't.
Microsoft Word uses OMML (Office Math Markup Language) inside word/document.xml. If you want equations to remain native and editable in Word (not blurry screenshots), the pipeline has to look like this:
LaTeX string -> MathML -> XSLT / AST transform -> Word OMML
The tricky edge cases are almost always:
- Multi-line aligned equations (
\begin{aligned}) and matrices (\begin{bmatrix}) - Inline math
$x_i$vs. display math$$...$$mixed inside list items or table cells - Escaped characters and spacing inside
\text{...}blocks
Once you get true OMML working, though, clicking an integral in Word and seeing Word's native Equation Editor light up feels pretty satisfying.
2. Mermaid Diagrams Need Controlled Rasterization
Word's SVG support across desktop versions, Mac, and WPS is still inconsistent—especially with foreignObject labels that Mermaid relies on for HTML text inside nodes.
To make diagrams look crisp everywhere without a headless browser on a backend:
- Render the Mermaid definition to SVG in an off-screen container.
- Normalize fonts and bounding boxes so text isn't clipped.
- Rasterize to a high-DPI PNG on Canvas (
2xor3xscale) and embed it as a standard Word drawing relationship (word/media/imageN.png).
It's a bit of extra work in the browser, but the output opens identically on Windows, macOS, and mobile Word.
3. Markdown Tables vs. Word Table Grids
In HTML/Markdown, table column widths are fluid. In OpenXML (w:tbl), Word expects explicit w:tblGrid column widths and cell borders (w:tcBorders), or it happily squishes columns or drops borders on paste.
Handling long code tokens or URLs inside narrow table cells also requires setting proper cell margins and word-wrap rules—otherwise a single long string blows out the entire page width.
4. Doing It All Locally Without Pandoc
Pandoc is great on a local CLI or server, and I still respect it a lot. But for quick day-to-day workflows—especially when the document contains internal architecture notes, incident timelines, or client data—people often don't want to upload drafts to a random conversion server just to get a .docx.
Shipping everything as static JS in the browser solves the privacy concern completely, at the cost of having to handle fonts, XML packaging (.zip), and edge-case parsing yourself.
Curious how everyone else handles this workflow: do you just rely on Pandoc scripts, copy-paste and fix formatting manually in Word, or avoid .docx altogether?
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.