Skip to content

Implement formula image → native Word object pipeline with Tkinter GUI#1

Open
renderlex with Copilot wants to merge 2 commits into
mainfrom
copilot/add-formula-recognition-to-word
Open

Implement formula image → native Word object pipeline with Tkinter GUI#1
renderlex with Copilot wants to merge 2 commits into
mainfrom
copilot/add-formula-recognition-to-word

Conversation

Copilot AI commented Apr 10, 2026

Copy link
Copy Markdown

Bootstraps the project from an empty repo into a fully functional desktop app that OCR-recognizes math formulas from images and inserts them as native OMML objects (not pictures) into .docx files.

Pipeline

Image → LaTeX (pix2tex OCR) → MathML (latex2mathml) → OMML (MML2OMML.XSL + lxml XSLT) → Word (python-docx)

New files

  • formula_to_word.py — Tkinter GUI + all conversion logic

    • latex_to_omml(latex, xsl_path) — chains latex2mathml → lxml XSLT transform
    • insert_formula_into_doc(doc, latex, xsl_path) — appends OMML element directly to paragraph._element
    • GUI: Open Image, Recognize Formula (threaded, lazy model load), editable LaTeX field, matplotlib preview, Save to Word
    • Batch mode: Add to List → Save List to Word (all formulas in one doc)
    • Auto-detects MML2OMML.XSL across Office 15/16 install paths; falls back to manual picker
  • requirements.txt — pinned minimum versions: pix2tex>=0.1.2, latex2mathml>=3.22.0, python-docx>=1.1.0, lxml>=4.9.0, Pillow>=10.0.0, matplotlib>=3.7.0

  • README.md — full setup, usage, batch mode, and XSL location guide

Original prompt

Formulas → Word

A program for recognizing mathematical formulas from images and inserting them into a Word document as native formula objects (not as pictures).

How it works

Image → LaTeX (OCR) → MathML → OMML → Word (native formula)
  1. pix2tex is a neural network that recognizes a formula from a photo and returns LaTeX code.
  2. latex2mathml converts LaTeX to MathML.
  3. MML2OMML.XSL is a Microsoft XSLT transformation that converts MathML to OMML (Office Math Markup Language).
  4. python-docx inserts an OMML element as a native Word formula.

Requirements

  • Python 3.10+
  • Microsoft Office (requires MML2OMML.XSL file, which comes with Office)
  • Internet connection for first run (OCR model ~500 MB download)

Installation

# 1. Create a virtual environment (recommended)
python -m venv venv
.\venv\Scripts\Activate.ps1

# 2. Install dependencies
pip install -r requirements.txt

# 3. Install PyTorch (if not already installed)
# For CPU:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
# Or for CUDA (GPU): see https://pytorch.org/get-started/locally/

Launch

python formula_to_word.py

Usage

  1. Click "Open Image" and select a photo with the formula.
  2. Click "Recognize Formula" — the program will recognize the LaTeX code.
  3. Check / edit the LaTeX manually in the text field (if necessary).
  4. Click "LaTeX Preview" to see how the formula looks.
  5. Click "Save to Word" — the formula will be inserted as a native Word object.

Batch mode

You can add several formulas to the list with the "Add to List" button, and then save them all together in one document.

Where to find MML2OMML.XSL

The program searches for this file automatically. Typical locations:

C:\Program Files\Microsoft Office\root\Office16\MML2OMML.XSL
C:\Program Files (x86)\Microsoft Office\root\Office16\MML2OMML.XSL

If the file is not found automatically, the program will prompt you to specify it manually.

Project structure

formulas to word/
├── formula_to_word.py # Main script (GUI + logic)
├── requirements.txt # Python dependencies
└── README.md # This file

Copilot AI changed the title [WIP] Add program for recognizing mathematical formulas in Word Implement formula image → native Word object pipeline with Tkinter GUI Apr 10, 2026
Copilot AI requested a review from renderlex April 10, 2026 13:30
@renderlex
renderlex marked this pull request as ready for review April 13, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants