Skip to main content

Typeset plain-text formulas in DOCX files as native Word equations.

Project description

MathFmt

中文 | English

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)/dtsqrt(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.docxinput.mathfmt.report.json,不会覆盖原文件。编辑 candidates.json 中的 selectedsourcelinear 后再执行 apply。如果 Office 安装在 非标准目录,为 applyconvertdoctor 添加 --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

mathfmt-0.1.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mathfmt-0.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

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

Hashes for mathfmt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8eab8ed93b846b62182f7c7e832492e2a12d74795bafee0add8b206f4e577828
MD5 149ef86e99f00421f22588efcd09489f
BLAKE2b-256 fb436c47d86584f0291369c20d968375e8242ff5ef2053334c574762b15c0b81

See more details on using hashes here.

Provenance

The following attestation bundles were made for mathfmt-0.1.0.tar.gz:

Publisher: publish.yml on gml853503962-creator/mathfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for mathfmt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c369d4dd8aed81345e398b5be60e3bfcb77d19d7c4f6850723bf0207a189365
MD5 781a39e7e42267c8ea134da4e2bb0cf8
BLAKE2b-256 cb2614179433f6803df5014a0110e7192febdecd29df5239014915b5c57d93a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mathfmt-0.1.0-py3-none-any.whl:

Publisher: publish.yml on gml853503962-creator/mathfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page