A tool to convert Typst project to Microsoft Word format.
Project description
typ2docx: Converting Typst Project to Microsoft Word Format
typ2docx is a command line tool that converts a Typst project to Microsoft
Word .docx format, with tables, cross-references, most of the styles, and most
importantly the math markups preserved.
You're encouraged to read this document thoroughly before using it, as I employed many non-trivial hacks for this non-trivial problem! (It involves 6 different programming languages!)
If this tool enhanced your workflow, especially if it helped with your academic publication, please consider crediting this project or sponsoring me :heart:.
Installation
[!NOTE]
Currently this tool supports macOS only, and it requires several dependencies. The package installation is expected to take some time, since it requires compiling a Rust library. Read along to know why.
To compile the Rust extension used in this tool, you will need Rust toolchain,
which can be installed via rustup.
This tool is distributed via PyPI. Installation via
uv is recommended.
To install typ2docx, execute the following command:
uv tool install typ2docx
If you want to tinker with this program:
git clone git@github.com:sghng/typ2docx.git
cd typ2docx
# do your modifications...
uv tool install .
For more details, read
UV's guide on using tools. You may
also use pipx or other similar tools to install and run this program.
The following runtime dependencies are also required:
- Pandoc, a universal document converter.
- Saxon, a processor for XSLT 3.0. The free home edition would suffice.
- Adobe Acrobat desktop app for converting PDF to
.docx. Either the freeAcrobat Readeror the paidAcrobat Proworks.
For macOS users, it is recommended to install these dependencies via Homebrew with the following command:
brew install pandoc saxon adobe-acrobat-reader
Usage
Once the tool is installed, invoke it with the path to the entry point of your
Typst project to convert it into Microsoft Word .docx format.
typ2docx main.typ
Run typ2docx --help to see the help info on how to use this tool.
What It Does and Does Not
There are some known issues -- which may or may not be a real issue depending on your use cases. Read the Motivation section to understand why I built this tool.
- Text in SVG/PDF images are distorted.
- Some spaces between inline equations and regular text are missing.
- Not all stylings are preserved. (This is expected, just like for any file format conversion.)
Similar Tools
- Adobe Acrobat does a great job in converting PDF
to
.docx, but the math equations are completely messed up. - Microsoft Word can also
convert a PDF to
.docxformat. In my experience, it doesn't work as well as Adobe Acrobat. pdf2docxPython library doesn't work for most of my PDF files.- Pandoc provides superb support for math markup when
converting
.typfile to.docx, but its support for Typst is very limited. For example, it doesn't recognize basic functions like#stroke. It also doesn't support latest features in Typst, such as embedding PDF as image. typliteis a tool developed by the author oftinymist. Its support for conversion to.docxis limited, as it relies on HTML as an intermediary. Styles and cross-references are lost, and math are rendered as images.
Motivation
This tool is developed so that a .docx export that meets the basic requirement
of academic paper submission can be produced. These requirements are very loose,
since the press has their own process for making a manuscript publication ready.
- Cross-referencing is NOT required.
- Figures are NOT required. They can be included as standalone attachments, as long as the names are matched.
- NO typesetting required.
With these said, the only true requirement is the quality of math equations, which must be retained effectively. And in Microsoft Word, it should be in Office Math Markup Language (OMML).
This tool is developed primarily to address the equation output problem.
Solution
The idea is to export with both Adobe Acrobat and Pandoc, and merge the best part in the two exports together.
- Branch 1
- A preamble is injected to the Typst project entry point, so that all math are rendered as markers.
- Typst compiles the project into PDF file.
- Adobe Acrobat converts this PDF into
.docxformat. This process is automated with an AppleScript.
- Branch 2
- A Rust lib extracts all math source code in a Typst project.
- The source code are put into a new Typst source file, in order of their appearance in original document.
- This source file is converted to
.docxwith Pandoc, they are cleanly formatted with MathML.
- The two Microsoft Word files are unpacked. A XLST script merges the
document.xmlfiles by examining the markers. The result is finally repacked into a.docxfile as output.
The math source code can not be extracted with purely static analysis or regex
matching, since the location where a content is defined can be different from
where it shows up in document, and multiple source files can be involved via
#include and #import. This necessitates the use of typst and typst-eval
Rust crates for parsing as well as evaluating the Typst project.
Contribution
You are more than welcome to contribute by raising issues or opening pull requests!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file typ2docx-0.1.0.tar.gz.
File metadata
- Download URL: typ2docx-0.1.0.tar.gz
- Upload date:
- Size: 32.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
363c663250a77f7afe01a8f749371791c4676bbdda6bd6649878dd19bad6f90c
|
|
| MD5 |
5309b395e6ee28695502f00fffa502a6
|
|
| BLAKE2b-256 |
0c098a208c4aae7b1e1b2bf3250a00cf12d28cf16c915e6c58f5519a0ee39d51
|
Provenance
The following attestation bundles were made for typ2docx-0.1.0.tar.gz:
Publisher:
pypi.yml on sghng/typ2docx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typ2docx-0.1.0.tar.gz -
Subject digest:
363c663250a77f7afe01a8f749371791c4676bbdda6bd6649878dd19bad6f90c - Sigstore transparency entry: 685563341
- Sigstore integration time:
-
Permalink:
sghng/typ2docx@02d283089cc70c99a997ee70fba64edef68dec2d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sghng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@02d283089cc70c99a997ee70fba64edef68dec2d -
Trigger Event:
release
-
Statement type: