docx
A Word document hand-formatted paragraph by paragraph drifts into the default-Calibri wall, with inconsistent headings over ad-hoc spacing and a layout no one can restyle in one move. A beautiful document keeps its design in a reference template of named styles. Every run reuses that one template, so the whole file shares a single type scale and spacing rhythm under one palette, and an editor restyles the document by changing the template alone.
Generation is deterministic and split in two. The model writes only the content as Markdown, and a shell script renders that Markdown to .docx with pandoc, applying an optional reference-doc template for the brand. The model never hand-writes document-builder code, so the same Markdown yields the same document every run. The design system the template should encode (the type scale, the two-face ceiling, the spacing rhythm, AA contrast, and the document archetypes) lives in references/beautiful-docx.md, grounded in the foundation determinism doctrine.
Steps
-
Name the archetype and its sections. State which document this is (report, proposal, contract, or memo) and list the sections drawn from the archetype table in the reference. Done when the section list and the archetype are written down before any content is drafted.
-
Write the document body as Markdown. Compose the content in GitHub-Flavored Markdown, mapping structure to Markdown:
#/##headings for the section outline,-/1.lists, and pipe tables for tabular data, with no manual font or spacing instructions in the prose. Done when the Markdown covers every named section from step 1 and carries a heading outline with no skipped level. -
Apply the brand through a reference template. Produce a baseline template by running
pandoc -o reference.docx --print-default-data-file reference.docx, then restyle that file in Word to match the design system in the reference and save the result as the reference doc. Done when the reference.docxcarries the type scale, the paired typefaces, and the spacing and color choices from the design system. -
Render deterministically with the script. Run
scripts/render.sh <content.md> <out.docx> [reference.docx], passing the reference template as the third argument so the brand applies during conversion. Done when the script printswrote <out.docx>and exits zero. -
Verify the artifact by opening it. Inspect the rendered file with
unzip -l <out.docx>and confirm the listing containsword/document.xml. Done when the listing reportsword/document.xmland the reopened document shows the expected heading hierarchy.
Scripts
scripts/render.sh <content.md> <out.docx> [reference.docx]: renders Markdown to.docxviapandoc --from gfm --to docx, adding--reference-doconly when a template path is given AND the file exists. A missing content file exits 2; an absentpandocexits 3; a successful render printswrote <out.docx>. Runscripts/render.sh --selftestto render a fixture and assert the output is a valid docx (the gatetools/run_selftests.pydiscovers this check).