Python wrapper and CLI utility to render LaTeX markup and equations as SVG using dvisvgm and svgo.

Overview

latex2svg

Python wrapper and CLI utility to render LaTeX markup and equations as SVG using dvisvgm and svgo.

Based on the original work by Tino Wagner, this version has enhanced features.

The design goals are:

  • Auto vertical alignment without any further styling.
    • by adding a style="vertical-align:" to the SVG attributes
  • Auto scaling on font size/zoom change.
    • by using em units for width, height and style
  • Unique IDs so multiple SVGs on one page won’t corrupt each other.
    • by generating random 4-character ID prefixes within the SVG
  • Minified SVG for direct inclusion.
    • by using svgo (a Node app)
  • For e-book readers and dictionaries:
    • Good legibility.
    • Direct inclusion as , not necessarily .
    • Possibility for easy CSS styling, i.e. using fill.
    • Compatibility with pyglossary and the ebook-reader-dict project.
    • Possibility of LaTeX preamble changes/additions, to correct LaTeX code in automated processes like converting a Wiktionary dump to an e-reader dictionary.

Usage

Python 3 module

from latex2svg import latex2svg
out = latex2svg(r'$\sin(x) = \sum_{n=0}^{\infty} \dots$')
print(out['valign'])  # baseline position in em
print(out['svg'])  # rendered SVG

CLI utility

$ ./latex2svg.py --help
usage: latex2svg.py [-h] [--version] [--preamble PREAMBLE]

Render LaTeX code from stdin as SVG to stdout. Writes metadata (baseline
position, width, height in em units) into the SVG attributes.

optional arguments:
  -h, --help           show this help message and exit
  --version            show program's version number and exit
  --preamble PREAMBLE  LaTeX preamble code to read from file

$ echo '$\sin(x) = \sum_{n=0}^{\infty} \dots$' | ./latex2svg.py > sample.svg

Result:

sample formula

Requirements

  • Python 3
  • A working LaTeX installation, like Tex Live or MacTeX
  • dvisvgm
  • svgo

License

This project is licensed under the MIT license. See LICENSE for details.

Copyright Β© 2022 Matthias C. Hormann

Owner
Matthias C. Hormann
Problem solver, IT specialist and creator of beautiful things. Also part-time radio presenter.
Matthias C. Hormann
πŸ‘» Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal.

πŸ‘» Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal. It c

Billy 11 Nov 10, 2021
Simple CLI for managing Postgres databases in Flask.

Overview Simple CLI that provides the following commands: flask psql create flask psql init flask psql drop flask psql setup: create β†’ init flask psql

Daniel Reeves 21 Oct 03, 2022
Rdwcli - Car list cli app with python

Rdwcli - Car list cli app with python

Arie Twigt 1 Feb 02, 2022
Faza - Faza terminal, Faza help to beginners for pen testing

Faza terminal simple tool for pen testers Use small letter only for commands Don't use space after command 'help' for more information Installation gi

Ag3ntQ 5 Feb 20, 2022
Enriches Click with option groups, constraints, command aliases, help sections for subcommands, themes for --help and other stuff.

Enriches Click with option groups, constraints, command aliases, help sections for subcommands, themes for --help and other stuff.

Gianluca Gippetto 62 Dec 22, 2022
CLI to show end-of-life dates for tools and technologies.

Python 3.9+ interface to endoflife.date to show end-of-life dates for tools and technologies.

Hugo van Kemenade 32 Jan 06, 2023
Access hacksec.in from your command-line

Access hacksec.in from your command-line

hacksec.in 3 Oct 26, 2022
Autosub - Command-line utility for auto-generating subtitles for any video file

Auto-generated subtitles for any video Autosub is a utility for automatic speech recognition and subtitle generation. It takes a video or an a

Anastasis Germanidis 3.9k Jan 05, 2023
A simple script to make the operation of AltServer-Linux more easier with cli

A simple script to make the operation of AltServer-Linux more easier with cli

powen 23 Dec 13, 2022
A terminal client for connecting to hack.chat servers

A terminal client for connecting to hack.chat servers.

V9 2 Sep 21, 2022
Navigate torrents in CLI with Mariner.

Navigate torrents in CLI with Mariner. It offers a simple interface for streamlined experience. No more annoying ads and pop-up windows.

2 Oct 20, 2021
Arithmos cipher on CLI based

Arithmos Cipher CLI This is the CLI version of Arithmos Cipher. Install pip inst

LyQuid :3 1 Jan 16, 2022
Terminal with builtin ortholinear keyboard and touch screen as a home automation interface.

OLKB-Terminal Terminal with builtin ortholinear keyboard and touch screen as a home automation interface. Features Step and STLs available for non-com

Jeff Eberl 50 Oct 07, 2022
PyWordle: A Python-made wordle manual solver

PyWordle: A Python-made wordle manual solver How to use it Start the program with python3 pywordlesolver.py. How it works The program has a simple 5-l

Federico Torrielli 5 Nov 24, 2022
Command line tool to automate transforming the effects of one color profile to another, possibly more standard one.

Finished rendering the frames of that animation, and now the colors look washed out and ugly? This terminal program will solve exactly that.

Eric Xue 1 Jan 26, 2022
🌈 Beautify your command line interfaces.

Basics Install: pip install iridi Usage: import iridi # Create gradient text # iridi.print(message, colors, options) # Ask for input with gradient

Conrad Crawford 39 Oct 20, 2022
A Python command-line utility for validating that the outputs of a given Declarative Form Azure Portal UI JSON template map to the input parameters of a given ARM Deployment Template JSON template

A Python command-line utility for validating that the outputs of a given Declarative Form Azure Portal UI JSON template map to the input parameters of a given ARM Deployment Template JSON template

Glenn Musa 1 Feb 03, 2022
🌈 Generate color palettes based on Neovim colorschemes.

Iris Iris is a Neovim plugin that generates a normalized color palette based on your colorscheme. It is named for the goddess Iris of Greek mythology,

N. G. Scheurich 45 Jul 28, 2022
A fantasy life simulator and role-playing game hybrid distributed as CLI, written in Python 3.

Life is Fantasy Epic (LIFE) A fantasy life simulator and role-playing game hybrid distributed as CLI, written in Python 3. This repository will be pro

Pawitchaya Chaloeijanya 2 Oct 24, 2021
Interactive Redis: A Terminal Client for Redis with AutoCompletion and Syntax Highlighting.

Interactive Redis: A Cli for Redis with AutoCompletion and Syntax Highlighting. IRedis is a terminal client for redis with auto-completion and syntax

2.2k Dec 29, 2022