tonyfu97 / latex-image-generator

Simple command-line script to convert LaTeX expressions into formula images in the current directory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LaTeX Image Generator

Motivation

I often found myself manually taking screenshots of LaTeX formulas on Overleaf's "scratch paper" to quickly visualize a given equation. This manual process became cumbersome and inspired the creation of this simple script to automatically generate images of LaTeX formulas right from the terminal.

Installation

  1. Clone the repository:

    git clone git@github.com:tonyfu97/latex-image-generator.git
    cd latex-image-generator
  2. Install the required libraries:

    pip install matplotlib
  3. Make the script executable:

    chmod +x latex_img.py
  4. Optionally, create a symlink to use the script from anywhere:

    sudo ln -s "$(pwd)/latex_img.py" /usr/local/bin/latex_img

Usage

After following the installation steps, you can use the script as follows:

latex_img "e^{i\pi} + 1 = 0" "Euler-Id"

Euler's Identity

This will create an image Euler-Id.png in the current directory, containing the given formula. If we did not specify the second argument (the image name), the image would be named formula.png by default.

Requirements

  • Python 3
  • LaTeX installation (for rendering LaTeX formulas with matplotlib)

Other Examples

Navier-Stokes Equation

latex_img "\frac{\partial \mathbf{u}}{\partial t} + (\mathbf{u} \cdot \nabla) \mathbf{u} - \nu \nabla^2 \mathbf{u} = -\nabla p" "Navier-Stokes"

Navier-Stokes Equation

Schrödinger Equation

latex_img "i\hbar\frac{\partial}{\partial t}\Psi = -\frac{\hbar^2}{2m}\nabla^2\Psi + V\Psi" "Schrodingers"

Schrödinger Equation

Quadratic Formula

latex_img "x = \frac{{-b \pm \sqrt{{b^2 - 4ac}}}}{{2a}}" "quadratic"

Quadratic Formula

About

Simple command-line script to convert LaTeX expressions into formula images in the current directory

License:MIT License


Languages

Language:Python 100.0%