Typeset plain-text formulas in DOCX files as native Word equations.
Project description
MathFmt
MathFmt turns awkward plain-text formulas in Word documents into native Word equations suitable for textbooks, exams, and technical reports. Processing stays on your computer.
中文
MathFmt 将 DOCX 文档中的普通文本公式转换为 Word 原生 OMML 公式,例如把 ds(t)/dt、
sqrt(x^2+1) 和 p1 排版为纸质教材中常见的分式、根号与上下标。
特点
- 保留原始 DOCX,始终写入新文件。
- 支持正文、表格、页眉、页脚和混合文本公式。
- 自动跳过代码、图片公式和已有 Word 原生公式。
- 提供可审核流程和保守的一键转换。
- 完全本地运行,不上传文档。
环境要求
- Windows 10/11
- Python 3.10 或更高版本
- Microsoft Word/Office,并包含
MML2OMML.XSL
MathFmt 不分发微软的 XSL 文件。它会自动检查常见 Office 安装目录,也可使用 --xsl 指定路径。
安装
pip install mathfmt
mathfmt doctor
从源码开发安装:
git clone https://github.com/gml853503962-creator/mathfmt.git
cd mathfmt
python -m pip install -e ".[dev]"
使用
# 保守的一键转换
mathfmt convert input.docx
# 审核后转换
mathfmt scan input.docx --report candidates.json
mathfmt apply input.docx --review candidates.json --output output.docx --report result.json
一键转换默认生成 input.mathfmt.docx 和 input.mathfmt.report.json,不会覆盖原文件。编辑
candidates.json 中的 selected、source 或 linear 后再执行 apply。如果 Office 安装在
非标准目录,为 apply、convert 或 doctor 添加 --xsl C:\path\to\MML2OMML.XSL。
Codex Skill
仓库中的 skills/mathfmt 可复制到 Codex 技能目录。技能依赖已安装的 mathfmt 命令。
English
MathFmt converts plain-text formulas in DOCX files into native Word OMML equations with stacked fractions, radicals, superscripts, subscripts, derivatives, and standard mathematical operators.
Highlights
- Never overwrites the source DOCX.
- Handles body text, tables, headers, footers, and formulas mixed with prose.
- Skips likely code, image formulas, and existing Word equations.
- Offers both a review-first workflow and conservative one-step conversion.
- Processes documents locally without uploading them.
Requirements and installation
MathFmt 0.1 supports Windows, Python 3.10+, and a Microsoft Office installation containing
MML2OMML.XSL. The Microsoft stylesheet is detected locally and is not distributed with MathFmt.
pip install mathfmt
mathfmt doctor
mathfmt convert input.docx
For review-first conversion, run scan, edit the generated JSON, then run apply as shown above.
Contributing
Issues and pull requests are welcome. See CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.
License
MIT License. Copyright (c) 2026 Leo.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mathfmt-0.1.0.tar.gz.
File metadata
- Download URL: mathfmt-0.1.0.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eab8ed93b846b62182f7c7e832492e2a12d74795bafee0add8b206f4e577828
|
|
| MD5 |
149ef86e99f00421f22588efcd09489f
|
|
| BLAKE2b-256 |
fb436c47d86584f0291369c20d968375e8242ff5ef2053334c574762b15c0b81
|
Provenance
The following attestation bundles were made for mathfmt-0.1.0.tar.gz:
Publisher:
publish.yml on gml853503962-creator/mathfmt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathfmt-0.1.0.tar.gz -
Subject digest:
8eab8ed93b846b62182f7c7e832492e2a12d74795bafee0add8b206f4e577828 - Sigstore transparency entry: 1889233757
- Sigstore integration time:
-
Permalink:
gml853503962-creator/mathfmt@d4dbc31fbe9b9f24dbdfeea351cc79c2ef7cb614 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gml853503962-creator
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d4dbc31fbe9b9f24dbdfeea351cc79c2ef7cb614 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mathfmt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mathfmt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c369d4dd8aed81345e398b5be60e3bfcb77d19d7c4f6850723bf0207a189365
|
|
| MD5 |
781a39e7e42267c8ea134da4e2bb0cf8
|
|
| BLAKE2b-256 |
cb2614179433f6803df5014a0110e7192febdecd29df5239014915b5c57d93a4
|
Provenance
The following attestation bundles were made for mathfmt-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on gml853503962-creator/mathfmt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathfmt-0.1.0-py3-none-any.whl -
Subject digest:
0c369d4dd8aed81345e398b5be60e3bfcb77d19d7c4f6850723bf0207a189365 - Sigstore transparency entry: 1889233869
- Sigstore integration time:
-
Permalink:
gml853503962-creator/mathfmt@d4dbc31fbe9b9f24dbdfeea351cc79c2ef7cb614 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gml853503962-creator
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d4dbc31fbe9b9f24dbdfeea351cc79c2ef7cb614 -
Trigger Event:
push
-
Statement type: