Skip to content

roghpav/eqeditor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Python LaTeX Equation Editor

A command-line tool to create beautiful PDF equations from LaTeX markup. This script demonstrates file operations, subprocess management, and cross-platform compatibility in Python.

Many years ago, when I was a college student, it was difficult to get a free equation editor, so I made this script. Now it is very easy to find free equation editors, however this script remains a simple and useful example for working with LaTeX programmatically.

Features

  • Convert LaTeX equations to high-quality PDF files
  • Input validation and error handling
  • Cross-platform support (Linux, macOS, Windows)
  • Automatic cleanup of temporary files
  • Customizable equation scaling
  • Safe filename handling
  • Automatic detection of LaTeX compiler (pdflatex preferred)

Requirements

Python

  • Python 3.6 or higher
  • No external Python packages required (uses only standard library)

LaTeX Distribution

You need a LaTeX distribution installed on your system:

Linux:

sudo apt-get install texlive texlive-latex-extra  # Debian/Ubuntu
sudo dnf install texlive-scheme-full              # Fedora

macOS:

brew install --cask mactex

Windows:

The script will automatically detect and use pdflatex (preferred) or fall back to latex + dvipdfm.

Installation

No installation needed! Just download ltxeq.py and run it.

# Clone or download
git clone <repository-url>
cd eqeditor-main

# Make executable (optional, Linux/macOS)
chmod +x ltxeq.py

Usage

Basic Usage

python ltxeq.py -e "2x=\pi+c\rho" -o "equation"

This creates equation.pdf and opens it in your default PDF viewer.

Advanced Examples

Simple equation:

python ltxeq.py -e "E=mc^2" -o "einstein"

Complex integral:

python ltxeq.py -e "\int_0^\infty e^{-x^2}dx = \frac{\sqrt{\pi}}{2}" -o "gaussian"

Custom scale (larger equation):

python ltxeq.py -e "\frac{-b \pm \sqrt{b^2-4ac}}{2a}" -o "quadratic" --scale 8

Don't open PDF automatically:

python ltxeq.py -e "\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}" -o "maxwell" --no-show

Keep temporary files for debugging:

python ltxeq.py -e "\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}" -o "euler" --keep-temp

Verbose output:

python ltxeq.py -e "a^2 + b^2 = c^2" -o "pythagoras" -v

Command-Line Options

Option Description Default
-e, --equation LaTeX equation string (required) -
-o, --output Output filename (without extension) eqtem
--scale Scale factor for equation size 5
--no-show Don't open PDF after creation False
--keep-temp Keep temporary LaTeX files False
-v, --verbose Print detailed information False
-h, --help Show help message -

How It Works

  1. Validation: Checks equation syntax (balanced braces, brackets, parentheses)
  2. Template: Wraps equation in standalone LaTeX document with required packages
  3. Compilation: Compiles using pdflatex (or latex → dvipdfm)
  4. Cleanup: Removes temporary files (.aux, .log, .dvi, etc.)
  5. Display: Opens PDF in system default viewer

Error Handling

The script includes robust error handling:

  • Validates LaTeX syntax before compilation
  • Checks if LaTeX is installed
  • Verifies successful compilation
  • Sanitizes filenames to prevent injection attacks
  • Provides clear error messages with suggestions

Troubleshooting

"LaTeX is not installed"

  • Install a LaTeX distribution (see Requirements section)
  • Ensure pdflatex or latex is in your PATH

"Invalid equation syntax"

  • Check for balanced braces: {}
  • Check for balanced brackets: []
  • Check for balanced parentheses: ()

PDF doesn't open automatically

  • Use --verbose to see detailed output
  • Try --no-show and open PDF manually

Compilation timeout

  • Check equation syntax for infinite loops
  • Use --verbose to see LaTeX output

License

MIT

Free Software, Hell Yeah!

About

Python Latex equation editor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages