Skip to main content

Convert LaTeX mathematical expressions to images for web and email

Project description

MathRender

Convert LaTeX mathematical expressions to images for web and email.

Features

  • Convert LaTeX expressions to HTML with embedded images
  • Automatic browser preview for easy copying to Gmail
  • High-quality PNG rendering of mathematical expressions
  • Simple command-line interface
  • Support for both inline ($...$) and display ($$...$$) math

Installation

Prerequisites

You need a LaTeX distribution and dvipng installed on your system:

Ubuntu/Debian:

sudo apt update
sudo apt install texlive-latex-base texlive-latex-extra dvipng

macOS:

# Install MacTeX or BasicTeX
brew install --cask mactex
# OR for a smaller installation:
brew install --cask basictex
sudo tlmgr update --self
sudo tlmgr install dvipng preview

Windows: Install MiKTeX which includes dvipng.

Install mathrender

pip install mathrender

Or install from source:

git clone https://github.com/yourusername/mathrender.git
cd mathrender
pip install -e .

Quick Start

Basic Usage

Convert LaTeX expressions and preview in browser:

mathrender 'The integral $$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$ is beautiful.'

This automatically:

  1. Converts LaTeX expressions to images
  2. Creates an HTML file with embedded images
  3. Opens it in your browser
  4. You can then copy and paste into Gmail

More Examples

From a file:

mathrender -f document.txt

Save as PNG:

mathrender 'Einstein showed that $E = mc^2$ revolutionized physics.' --png output.png

From stdin:

echo 'The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$.' | mathrender

Generate MIME for email systems:

mathrender -f document.txt --mime

Command Reference

Basic Usage

mathrender [OPTIONS] [INPUT]

Options:

  • -f, --file PATH: Read input from file
  • -o, --output PATH: Save output to file (MIME format)
  • -p, --png PATH: Save as PNG image file
  • --mime: Output MIME content instead of opening HTML
  • --dpi INTEGER: Image resolution (default: 300)
  • --subject TEXT: Email subject line (for MIME output)
  • --from TEXT: From email address (for MIME output)
  • --to TEXT: To email address (for MIME output)
  • --raw: Output raw MIME without base64 encoding

Check Dependencies

Verify all dependencies are installed:

mathrender --check

How It Works

  1. LaTeX Detection: The tool finds LaTeX expressions in your text using common delimiters:

    • Inline math: $...$ or \(...\)
    • Display math: $$...$$ or \[...\]
  2. Image Generation: Each expression is:

    • Compiled with LaTeX
    • Converted to PNG with dvipng
    • Optimized for email display
  3. HTML Output:

    • Creates HTML with embedded base64 images
    • Opens in your default browser
    • Ready to copy and paste

Tips for Gmail

  1. The HTML preview opens automatically in your browser
  2. Select all content (Ctrl+A or Cmd+A)
  3. Copy (Ctrl+C or Cmd+C)
  4. Paste into Gmail compose window
  5. After pasting, you can resize images by clicking and dragging
  6. The images are embedded, so recipients don't need to "load images"
  7. Works with Gmail's confidential mode

Troubleshooting

"LaTeX compilation failed"

Make sure you have the required LaTeX packages:

sudo apt install texlive-latex-extra texlive-fonts-recommended

"dvipng: command not found"

Install dvipng:

sudo apt install dvipng

Images appear too large/small

Adjust the DPI setting:

mathrender "your text" --dpi 150

Browser doesn't open automatically

The HTML file is saved to a temporary location. Look for the path in the output:

✓ HTML opened in browser: /tmp/tmpXXXXXX.html

You can manually open this file in your browser.

Development

Setup

git clone https://github.com/yourusername/mathrender.git
cd mathrender
pip install -e .

Running Tests

pytest

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mathrender-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mathrender-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file mathrender-0.1.0.tar.gz.

File metadata

  • Download URL: mathrender-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.11.0-26-generic

File hashes

Hashes for mathrender-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8dbb559df3ce3781ab0205151d24f670da1ecea3457796a214acf05a5958b76a
MD5 f4443edf4df14d08e835801eacd00076
BLAKE2b-256 a5a41bd6c317e7ff3eaae64545a95c0a8faa225ed4da87619bf885298e6c511a

See more details on using hashes here.

File details

Details for the file mathrender-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mathrender-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.11.0-26-generic

File hashes

Hashes for mathrender-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70312185594518c753a952ca3d378aa2718e9d4461934c4f4871e1f5ba156d39
MD5 d7eddaadf685f05dfb072d9916cc0b82
BLAKE2b-256 0a6df11abb5a2e137e26c6dfe78d219dbe3fd40f3162a468c3ecc7ff182db150

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page