docx-typst
docx-typst is a bidirectional document conversion tool. It converts Word (.docx) documents into editable Typst projects and exports a documented Typst subset, including explicit calculated results, back to editable Word documents.
It is designed for file-based document workflows, including AI-agent and version-control workflows. A document can be read and revised as readable Typst source, compiled to PDF for review, and exported to DOCX without a live Word session. Supported text, styles, lists, tables, images, headers, footers, and page setup remain editable. Conversion reports identify content that is approximated, flattened, or unsupported.
Version 0.1.0 is an alpha release for documents within the documented subset. It does not claim to reproduce every Word or Typst feature. Review conversion_report.json and inspect important pages before delivery.
Agent skills
typst-docx-adapt: adapt an existing Typst project for editable Word export while preserving its design.typst-docx-author: author a new Typst document with DOCX-compatible constructs from the start.
Copy either skill directory into your agent's skills directory, including its references and UI metadata. In Codex, invoke $typst-docx-adapt or $typst-docx-author.
Install
Python 3.10 through 3.13 is supported.
python -m pip install docx-typst
The Python package performs conversion and installs typst (typst-py), which rasterizes docx-static content during export. Install the Typst CLI separately only to compile generated projects to PDF from the command line. SVG-to-DOCX export needs Cairo native libraries through cairosvg; install the optional extra when needed:
python -m pip install "docx-typst[svg]"
EMF/WMF rendering uses Inkscape when available, or the packaged Windows PowerShell/GDI+ path on Windows. Without a renderer the original asset is preserved and the conversion report records a warning.
Word to Typst
docx-to-typst report.docx --output report-typst
typst compile report-typst/main.typ report.pdf
The generated project contains:
report-typst/
main.typ
template.typ
asset_manifest.json
conversion_report.json
assets/media/
main.typ uses semantic constructs such as docx-heading, docx-para, docx-item, docx-image, and docx-table. Paragraph style names and effective formatting are stored in a generated docx-styles table, so the source stays readable while the reverse converter can recreate Word styles.
Useful options:
docx-to-typst report.docx --output report-typst --no-media
docx-to-typst report.docx --output report-typst --drop-empty
docx-to-typst report.docx --output report-typst --strict
Typst to Word
typst-to-docx report-typst/main.typ --output report-roundtrip.docx
The reverse converter reads the documented static subset. Unannotated arbitrary Typst programs, dynamic expressions, loops, and user-defined macros are not evaluated. Wrap supported calculated results in docx-eval to evaluate them with Typst during export. It writes conversion_report.json next to the output. Pass --reference template.docx to reuse an existing document's theme and styles, and --strict to fail when unsupported content is found.
A typical edit-and-export loop:
docx-to-typst source.docx --output working
# Edit working/main.typ or replace assets.
typst compile working/main.typ working/preview.pdf
typst-to-docx working/main.typ --output revised.docx
Calculations and source roundtrip
Keep input data, formulas, and calculation helpers in the Typst source:
#let subtotal = 3 * 100
#let total = subtotal * 1.1
#docx-eval("total", [Total: #calc.round(total, digits: 2)])
docx-eval exports supported text, grids, and tables as editable static Word
content. The DOCX embeds the original source and required local dependencies;
re-importing an unchanged export restores their original bytes, including formulas
and native drawing code. Check source_restoration: "exact" in the import report.
Word edits can require reconstruction of the edited static representation instead
of formula restoration. Word does not execute Typst calculations. Use
docx-to-typst document.docx --output project --reconstruct to bypass restoration.
Static diagrams and panels
Use docx-static for content that the static subset cannot rebuild natively, such as CeTZ diagrams, timeliney charts, Fletcher decorations, or a designed cover:
#docx-static(width: 550pt)[
#cetz.canvas(...)
]
On export, the converter copies the file's top-level imports, renders the body at 200 ppi with typst-py, trims the surrounding whitespace, writes a PNG under assets/static/, and embeds it at the requested width. Pass height: when the image must fit a fixed page area. A pre-rendered asset can be supplied with path: and is not compiled again.
For vector artwork, use format: "svg". Explicit width and height preserve a fixed frame and transparency instead of trimming it. Without a height, the converter preserves the complete intrinsic drawing frame at its native Typst size. The width argument is an export measurement hint and does not shrink a body that renders wider in Typst. Give absolutely positioned artwork an explicit width and height:
#docx-static(width: 210mm, height: 297mm, format: "svg")[
// Keep the original Typst drawing code here.
#place(top + left, dx: 44pt, dy: 151pt)[
#rect(width: 82pt, height: 5pt, fill: yellow, stroke: none)
]
]
SVG exports include native vector media and a PNG fallback for older Word versions. Nested SVG image assets are expanded into vector groups for Word compatibility. The authored .typ file is never replaced with generated image paths.
Positioned covers with editable text
Use docx-canvas for a bounded page layout and docx-position for editable text or images. Coordinates are relative to the page in Word; in Typst, positions behave like place(top + left, ...). Keep the original text and drawing styling in each body. style names an existing docx-styles paragraph style for Word export; align sets Word text alignment. Frame dimensions describe the Word text box without restyling the native Typst body.
#docx-canvas(id: "cover", width: 210mm, height: 297mm)[
#docx-static(width: 210mm, height: 297mm, format: "svg")[
// Original background and illustration calls remain native here.
]
#docx-position(dx: 44pt, dy: 191pt, width: 510pt, height: 185pt,
style: "Cover Title")[
#text(font: "League Spartan", size: 40pt, weight: "bold")[Project proposal]
]
]
Use a zero-margin page without a header or footer for a full-page cover. Source order controls layer order. Put artwork in docx-static and text in docx-position to keep the text editable in Word.
Exported documents retain native static/canvas source and local file dependencies in a related package part. Reimport restores the drawing code, including after Word opens and saves the document. Exact full-source restoration applies to unchanged exports; edits to supported Word content or layout trigger reconstruction instead of silently restoring stale source. Arbitrary shape edits remain outside the supported subset.
Use docx-panel for a shaded callout that should stay editable:
#docx-panel(fill: rgb("#FFF9E7"), inset: 12pt, radius: 6pt)[
*Billing dependency:* matching a ward stock total does not prove that the
correct patient was charged.
]
In Typst it is a native block. In Word it becomes a single-cell shaded table, so the text, emphasis, and line breaks remain editable. The rendered body uses imports and assets resolved from the source file's directory. If rendering fails, the diagnostic is recorded in conversion_report.json and the body is exported as editable fallback content instead.
Start a Typst document
docx-typst init my-document
typst compile my-document/main.typ my-document/preview.pdf
typst-to-docx my-document/main.typ --output my-document.docx
The starter includes a helper module, an authoring example, and an SVG asset. To write only the helper module:
docx-typst module --output docx-typst.typ
Shortcut commands are also available:
docx-typst to-typst document.docx --output document-typst
docx-typst to-docx document-typst/main.typ --output document.docx
Supported subset
| Word feature | Word to Typst | Typst to Word |
|---|---|---|
| Headings and paragraph styles | Semantic headings plus a generated style table | Built-in and custom paragraph styles |
| Character formatting | Bold, italic, underline, strike, caps, super/subscript, color, highlight, font, size | The same supported properties |
| Lists | Bullet and numbered levels with resolved markers | List Bullet and List Number styles |
| Tables | Grid widths, header rows, horizontal/vertical merges, cell fills, common borders | Native tables, merges, header rows, cell fills |
| Images | PNG/JPEG/SVG retained; legacy formats converted or reported | PNG/JPEG embedded; SVG with Office fallback when a renderer is available |
| Links and bookmarks | External hyperlinks and named bookmarks | External hyperlinks and internal anchors |
| Headers and footers | Default section header/footer and page fields | Section headers, footers, page-number fields |
| Page setup | Paper size, margins, columns, orientation, sections | Paper size, margins, columns, orientation, sections |
| Footnotes | Rendered as Typst footnotes with a warning | Exported as superscript note text |
| Comments, charts, SmartArt, OLE, equations | Reported as unsupported or approximated | Not reconstructed |
The reverse converter also accepts a small native Typst subset, including headings, paragraphs, bullet and numbered lists, *strong*, _emphasis_, inline code, #link, #image, #figure, #table, and #grid. Authoring helpers extend it: docx-static exports native artwork as PNG or SVG, docx-panel becomes an editable shaded table cell, and docx-eval evaluates explicitly annotated calculations at export time.
Reports and validation
Both directions write conversion_report.json with counts, status, and diagnostics. A successful command does not mean every source object was reproduced.
Compare a source DOCX with a generated Typst project:
docx-typst-validate source.docx project --out project/validation.json
The validation report compares plain text, paragraph and table counts, images, styles, page size, and margins. Differences are informational; inspect the flagged content before delivery.
Python API
from docx_typst import docx_to_typst, typst_to_docx
forward = docx_to_typst("report.docx", "report-typst")
backward = typst_to_docx("report-typst/main.typ", "report-roundtrip.docx")
Fidelity notes
- Typst normalizes whitespace, smart punctuation, and some spacing. Word's layout engine and Typst's layout engine will not produce identical line breaks.
- Fonts are referenced by name; available supported script fonts can be embedded when their embedding rights permit. Fonts are not installed automatically. Missing or substituted fonts change wrapping and alignment.
- Native tables inherit literal
set tableinset and stroke rules. Left-aligned table frames align with the text margin; uniform border colors and widths are written explicitly instead of relying on Word table styles. Table/image gaps preserve paragraph spacing and explicit vertical space, with adjacent automatic gaps collapsed. - Table paragraph show rules such as
show table: set par(justify: false)override inherited body justification. Word cell margins account for paragraph line boxes so padding is not added twice; the logical Typst inset remains available for source round trips. Fonts, font sizes, and line spacing are retained. - General floating shapes and text boxes are outside the supported subset; converter-authored
docx-canvaslayouts preserve their source and editable text. Comments, tracked-change metadata, native chart data, SmartArt, OLE objects, and complex equations are outside the supported subset. - The reverse converter does not evaluate arbitrary Typst code. Unsupported constructs are reported and, when possible, flattened into readable content.
- Content inside
docx-staticis embedded as an image and is not editable in Word. Keep the Typst source for later revisions. - Review
conversion_report.jsonand inspect important pages before using the output for delivery.
Development
python -m pip install -e ".[test]"
python -m pytest -q
python -m pip install -e ".[release]"
python -m build
python -m twine check --strict dist/*
For release validation and trusted publishing setup, see Releasing to PyPI.
Open an issue for questions or bug reports.
License
MIT. See LICENSE.
Metadata
Release files for docx-typst 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docx_typst-0.1.0.tar.gz | 141.8 kB | With provenance | Details for docx_typst-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docx_typst-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for docx_typst-0.1.0-py3-none-any.whl |
Total release size: 254.4 kB
Release files / docx_typst-0.1.0.tar.gz
| Download URL | docx_typst-0.1.0.tar.gz |
|---|---|
| Size | 141.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb29cb0725acc5b288205cb85f51dfa82fe5ea8d2ac7b662f1afcdc5029a8cdd
|
|
BLAKE2b-256 checksum How to use checksums |
fe160339db2a18e60bd053cc72bf7cc324eb700ad5c8a5d6193c0b03e1bba905
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logRelease files / docx_typst-0.1.0-py3-none-any.whl
| Download URL | docx_typst-0.1.0-py3-none-any.whl |
|---|---|
| Size | 112.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
229810804b714ab2c2ae43dbef7f41264266ca019bd0456c43d1120586e18728
|
|
BLAKE2b-256 checksum How to use checksums |
8e5315c79f164aab1f7a427fdd563f510e8952bbf444a2c9eb00f7a930188a84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logSecurity for docx-typst 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for docx_typst-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.