Skip to content

Repository files navigation

LaTeXConverter (LaTeX-OCR)

MIT License Repo Size Last Commit Python

LatexCon

A custom extension that:

  • Preprocesses the image before extraction for a higher rate of accuracy.
  • Converts math images to LaTeX.
  • Renders LaTeX into styled PNG images and PDF format as well.
  • Adds custom scripts for rendering, automation,and formatting.

Tool Objective:

Convert math question images into usable, editable LaTeX code and render the result into an image for reuse in:

  • Educational content
  • Scientific papers
  • Digital documentation
  • Exam generation

Input

  • Any math image file ('.png', '.jpg', etc.)
  • Provided as a command-line argument or in code

Workflow Overview

The following diagram outlines the full process from raw math image to rendered LaTeX output. Untitled diagram _ Mermaid Chart-2025-08-05-152628


Example Run

This example demonstrates how a math image is converted into LaTeX and then rendered back as a polished output image.


Input Image

This is the raw image of a math question passed into the tool.

Example:

mathdoubt

Extracted LaTeX

The LaTeX code extracted using the 'pix2tex' model is printed below:

\frac{11 + x}{x^3}

Alternatively the following LaTeX can also be the input for the latex_to_image.py file if the '\f' in '\frac' is assumed as an escape sequence by the Python interpreter:

\[\frac{11+x}{x^{3}}\]

Folder Structure

All custom code ('extract.py', 'render_latex.py') lives inside the 'LaTeX-OCR/' folder for import compatibility.

LaTeXConverter/
├── LaTeX-OCR/
│   ├── extract.py
│   ├── render_latex.py
│   └── ...
├── assets/
│   ├── mathdoubt.png
│   ├── rendered_latex.png
├── README.md
├── LICENSE
├── requirements.txt

Usage

python LaTeX-OCR/extract.py --input assets/mathdoubt.png

Acknowledgement:

Code Modified From: Lukas Blecher

Contact

Devapragadeesh B
🔗 GitHub

About

Extracts LaTeX code from a math question image and renders it back into a high quality image using LaTeX typesetting.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages