Batch render LaTeX files to cropped SVG images
Project description
LaTeXclippings
Batch render LaTeX files to cropped SVG images.
Features
LaTeXclippings takes multiple LaTeX files, and an optional preamble, as input. Using your computer's LaTeX installation, it renders each input file as an SVG image or embeddable HTML <img>
tag. All relevant LaTeX features are supported, including regular text, inline and display math, and tables.
Each rendered image is cropped, allowing it to be easily embedded in other content. When generating HTML <img>
tags, additional CSS style rules are added, which adjust the SVG's scale and baseline to match the surrounding text. No more misaligned equations!
LaTeXclippings provides a simple command-line utility, as well as a Python API for integration into more complex projects (like static website generators). LaTeXclippings also converts pdflatex
errors into informative Python exceptions, helping you identify the file and line responsible for an error.
Dependencies
LaTeXclippings is written in Python, and also uses:
pdflatex
to generate PDFs from LaTeX sourceinkscape
for PDF cropping and SVG conversion
Usage
Command Line
The latexclippings
command reads LaTeX files (or standard input) and outputs SVG or embeddable HTML. (If you did not install LaTeXclippings from PyPI, you can use ./latexclippings.py
or python latexclippings.py
instead.)
Using standard input and output:
$ # Kinetic energy formula (in classical mechanics).
$ echo '$ E_k = \frac{1}{2}mv^2 $' | latexclippings > kinetic-energy.svg
Rendering multiple LaTeX files to HTML, using a custom preamble:
$ latexclippings --format html --preamble my-preamble.tex \
> apple.tex banana.tex grape.tex
$ ls
apple.html banana.html grape.html my-preamble.tex
apple.tex banana.tex grape.tex
The contents of apple.html
(note the inline CSS styles for scaling and alignment):
<img style="display: inline-block; width: 21.38669ex;
height: 2.08727ex; vertical-align: -0.45000ex;"
alt="I enjoy eating apples." title="I enjoy eating apples."
src="data:image/svg+xml;base64, PHN2ZwogICB4bWxuczp...">
Python API
For more sophisticated usage (e.g. integration into a static website generator), you can use the Python API.
from latexclippings import LatexFile
lf = LatexFile([r"This is some \LaTeX code.", r"Math: $ \sin(x) $"])
c = lf.clippings[0]
print(f"The first clipping is {c.width} by {c.height} ex, "
+ f"with {c.depth} ex below the baseline.")
with open("math.svg", "w") as f:
f.write(lf.clippings[1].svg)
License
LaTeXclippings is licensed under the MIT License.
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
Built Distribution
File details
Details for the file latexclippings-0.1.0.tar.gz
.
File metadata
- Download URL: latexclippings-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c4f74f7f891e9cf5b1274009b962ea33ac8241f13519f16cfd71bd5014f65f6 |
|
MD5 | 6a54d1bef42bc9a3484c3738766b31b9 |
|
BLAKE2b-256 | 818916a045aa23298f3bf43b307f0db7c5553c03bc84b1f474ebcb9ad4586686 |
File details
Details for the file latexclippings-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: latexclippings-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22a9f02c9f1e097ce4141fc54b5b2dee6707d2458a42c1962033da00bc4b7e4a |
|
MD5 | 035f61e997893da68f94662905d0813d |
|
BLAKE2b-256 | 4c0a12eb346426372a1ada4146d3fc8d24cba20c54ff280a81b2d5bfa3374aa5 |