Skip to main content

math-svg: A Plugin for Pelican

Build Status PyPI Version License pre-commit.ci status

Render math expressions to svg and embed them.

Installation

This plugin can be installed via:

python -m pip install pelican-math-svg

Afterwards, add the plugin to the PLUGINS list in your pelicanconf.py file, e.g.:

PLUGINS = [
    "math_svg",
]

Multi-Core Rendering

To use multi-core rendering of equations (highly recommended, especially when many equations have to be rendered) change the html target in the Makefile of your pelican site to a three step process:

html:
    PELICAN_MATH_SVG_DRY=True "$(PELICAN)" "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
    pelican-math-svg render -j $(shell nproc)
    "$(PELICAN)" "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)

The first commands will execute math-svg in dry-mode and only populate the equation database without actually rendering anything. The second command will render all missing equations in parallel. The number of threads is specified by the -j flag, in this example all CPU cores are used. Replace $(shell nproc) with a number to use a fixed number of cores. The last command is the usual pelican command and produces the output files again, know including the rendered equations.

Requirements

  • required LaTeX tools (all included in TeX Live and possibly other LaTeX distributions):
    • lualatex (or another LaTeX compiler if changed in the settings, see below)
    • pdfcrop
    • dvisvgm
  • scour (optional)
  • svgo (optional)

Usage

In Markdown you can use $x$ for inline math and

$$
  \int x^2
$$

for display math.

It is required to set the stroke color using the strokeonly class (this class name can be changed, see configuration options below), otherwise lines would be rendered white:

svg path.strokeonly {
    color: #000;
}

To change the fill color for equations as well, thus essential changing the default color for math, specify the following additionally:

span.math svg path,
div.math svg path {
    fill: #000;
}

Configuration

In your pelicanconf.py you can use the following options to tweak the behavior of the plugin:

Setting Description Default Value
`MATH_SVG["titles"] Whether to generate <title> tags containing the raw LaTeX code (recommended for accessibility). True
MATH_SVG["scale_inline"] scaling factor for inline math 1.0
MATH_SVG["scale_display"] scaling factor for display math 1.0
MATH_SVG["strokeonly_class] CSS class for SVG paths that have no filling and a black stroke color, useful when changing the color of rendered equations strokeonly
MATH_SVG["latex"]["args"] CLI arguments of the invoked LaTeX compiler "--interaction=errorstopmode", "--halt-on-error"
MATH_SVG["latex"]["preamble"] preamble of the generated LaTeX document [r"\documentclass[preview,border={2pt 0pt}]{standalone}",r"\usepackage{amsmath}",r"\usepackage{amssymb}",]
MATH_SVG["latex"]["program"] LaTeX compiler to use lualatex
MATH_SVG["pdfcrop"]["args"] CLI arguments for pdfcrop --hires
MATH_SVG["dvisvgm"]["args"] CLI arguments for dvisvgm ["--pdf", "--optimize=all", "--no-fonts", "--exact-bbox"]
MATH_SVG["scour"]["args"] CLI arguments for scour ["--strip-xml-prolog", "--remove-descriptions", "--remove-metadata", "--enable-comment-stripping", "--strip-xml-space", "--enable-id-stripping",]
MATH_SVG["scour"]["enabled"] whether to use scour to optimize SVG output True if scour is in $PATH, False otherwise
MATH_SVG["svgo"]["args"] CLI arguments for svgo ["--multipass", "--precision", "5"]
MATH_SVG["svgo"]["enabled"] whether to use svgo to optimize SVG output True if svgo is in $PATH, False otherwise

Contributing

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.

To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.

License

This project is licensed under the GPLv3 license.

Metadata

Release files for pelican-math-svg 0.10.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pelican-math-svg 0.10.3
File Size Uploaded Provenance Actions
pelican-math-svg-0.10.3.tar.gz 22.8 kB Without provenance Details for pelican-math-svg-0.10.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pelican-math-svg 0.10.3
File Interpreter ABI Platform Actions
pelican_math_svg-0.10.3-py3-none-any.whl Python 3 none any Details for pelican_math_svg-0.10.3-py3-none-any.whl

Total release size: 45.7 kB

Release files / pelican-math-svg-0.10.3.tar.gz

Download URL pelican-math-svg-0.10.3.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f0ea97ce63c634912e10d6d20ad609d51b0428fbacd7f38d94f87564fd093f80
BLAKE2b-256 checksum
How to use checksums
e17db7f1bf04797246491793ab4839e75048e61e5573f23878bd4ea633a81dc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.10.7 Linux/5.15.0-1020-azure

Release files / pelican_math_svg-0.10.3-py3-none-any.whl

Download URL pelican_math_svg-0.10.3-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc627a051013135fe5e57b7bb77d272f6b51976a71a2080371c18560c8fb30f2
BLAKE2b-256 checksum
How to use checksums
7ce6ae26db6f5e0bb824ac92d3782809bf87bf0fef7da021c43a5d7a50807a93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.10.7 Linux/5.15.0-1020-azure

Security for pelican-math-svg 0.10.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page