https://github.com/swhl/latextoimage
Use LaTeX compilation tools to convert formulas in LaTeX format into corresponding images.
https://github.com/swhl/latextoimage
convert latex latex-ocr
Last synced: about 1 month ago
JSON representation
Use LaTeX compilation tools to convert formulas in LaTeX format into corresponding images.
- Host: GitHub
- URL: https://github.com/swhl/latextoimage
- Owner: SWHL
- License: mit
- Created: 2023-12-20T01:29:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-22T07:32:09.000Z (over 2 years ago)
- Last Synced: 2025-01-25T05:41:27.993Z (over 1 year ago)
- Topics: convert, latex, latex-ocr
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Introduction
This tool is used to convert LaTeX formulas into corresponding images with the help of LaTeX tools.
### Install LaTeX compile environment
Ubuntu:
```bash
sudo apt-get install texlive-full
# verify whether the installation is successful.
$ xelatex --help
# Usage: pdftex [OPTION]... [TEXNAME[.tex]] [COMMANDS]
# or: pdftex [OPTION]... \FIRST-LINE
# or: pdftex [OPTION]... &FMT ARGS
# Run pdfTeX on TEXNAME, usually creating TEXNAME.pdf.
```
MacOS
Recommend to install [MacTex](https://tug.org/mactex/mactex-download.html)
```bash
# verify whether the installation is successful.
$ xelatex --help
# Usage: xetex [OPTION]... [TEXNAME[.tex]] [COMMANDS]
# or: xetex [OPTION]... \FIRST-LINE
# or: xetex [OPTION]... &FMT ARGS
# Run XeTeX on TEXNAME, usually creating TEXNAME.pdf.
```
### Installation
```bash
pip install latex_to_image
```
### CLI
```bash
$ latex_to_image "x^2+y^2=1" res.png
```
### Python
```python
import cv2
from latex_to_image import LaTeXToImg
render = LaTeXToImg()
formula = "x^2 + y ^2 = 1"
img = render(formula)
cv2.imwrite("res.png", img)
```
### Result
### Reference
- [LaTeX-OCR](https://github.com/lukas-blecher/LaTeX-OCR/blob/main/pix2tex/dataset/latex2png.py)