A high-performance, beautiful LaTeX to image conversion tool and library powered by Puppeteer and KaTeX.
LaTeX2Img-CLI allows you to transform text containing LaTeX equations into crisp, high-resolution PNG images. Perfect for documentation, sharing equations on social media, or generating assets for web projects.
- 🚀 Lightning Fast: Powered by KaTeX for near-instant math typesetting.
- 🎨 Premium Aesthetics: Uses the Inter font for a modern, clean look.
- 📱 High Resolution: Captures at 2x DPI for ultra-sharp text and symbols.
- 🛠 Flexible: Supports mixed content (text + math), multiple delimiters (
$,$$,\(,\[), and custom styling. - 💻 CLI & Library: Use it directly from your terminal or integrate it into your Node.js apps.
# Clone the repository
git clone https://github.com/prajdabre/latex2img-cli.git
cd latex2img-cli
# Install dependencies
npm install
# Link for global CLI usage
npm linkAfter linking, you can use the latex2img command:
latex2img 'The mass-energy equivalence: $E = mc^2$' -o output.png -s 32 -w 600-o, --output <path>: Output image path (default:output.png)-s, --font-size <number>: Font size in pixels (default:24)-p, --padding <number>: Padding in pixels (default:20)-w, --width <number>: Fixed width for text wrapping-b, --background <color>: Custom background color (CSS value)-t, --theme <name>: Theme choice (modern,handwritten,chalkboard)-g, --grounded [level]: Extract boxes to.json(charorequation)-d, --debug [level]: Render boxes on image (charorequation)-n, --noise <0-1>: Apply artifact synthesis (blur, jitter, ink bleed)
This tool is designed for generating high-quality grounded synthetic training data for STEM OCR models.
- JSON Metadata: Using
--groundedproduces a JSON file mapping every symbol to its precise[x, y, w, h]coordinates. - Debug View: Using
--debugrenders those boxes (red for characters, blue for equations) directly on the image for verification. - Artifact Synthesis: Using
--noiseapplies randomized jitter, skew, and ink-bleed effects to simulate messy handwriting or poor scanning conditions, perfect for testing model robustness.
| Theme | Description | Preview |
|---|---|---|
modern (default) |
Clean, professional Inter font on white/transparent background. | View |
handwritten |
Organic "Architects Daughter" font with a slight tilt and ink-blue color. | View |
chalkboard |
Classroom aesthetic with "Patrick Hand" font and slate-board background. | View |
const latexToImage = require('./index');
async function convert() {
await latexToImage(
"Quadratic formula: $$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$",
'quadratic.png',
{
fontSize: 28,
padding: 40,
backgroundColor: '#f8f9fa'
}
);
}
convert();| Description | Rendered Result | Input Text |
|---|---|---|
| Basic Math (Inline + Block) | ![]() |
Link |
| Calculus (Integrals) | ![]() |
Link |
| Linear Algebra (Matrices) | ![]() |
Link |
| Physics (Standard Model) | ![]() |
Link |
| Chemistry (Reactions) | ![]() |
Link |
| Stress Test (Overflow/Wide) | ![]() |
Link |
| Multi-line (Lists/Notes) | ![]() |
Link |
| Theorem (Mixed Content) | ![]() |
Link |
| Quadratic (Large Block) | ![]() |
Link |
| Einstein (Inline) | ![]() |
Link |
| Grounded (Metadata) | ![]() |
JSON |
| Synthetic (Noisy) | ![]() |
JSON |
This project is licensed under the MIT License - see the LICENSE file for details.
Created by Raj Dabre












