/LaTeXToImage

Use LaTeX compilation tools to convert formulas in LaTeX format into corresponding images.

Primary LanguagePythonMIT LicenseMIT

LaTeX To Image

PyPI SemVer2.0 GitHub

简体中文 | English

Introduction

This tool is used to convert LaTeX formulas into corresponding images with the help of LaTeX tools.

Install LaTeX compile environment

Ubuntu:

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

# 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

pip install latex_to_image

CLI

$ latex_to_image "x^2+y^2=1" res.png

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