Sven Kreiss ←Articles

pelican-jsmath Plugin

The new plugin is \(\alpha\omega\epsilon s \sigma m \epsilon\), particularly in combination with KaTeX which is used here. It has good support for big equations:

$$E=mc^2$$

A vector \(\vec{a}\) looks beautiful. Writing order of magnitudes with \(\mathcal{O}(n)\) is pretty. There was a related Pelican issue for support for KaTeX.

The plugin is packaged and can be installed with pip install pelican-jsmath (with a dash) and then added to Pelican in pelicanconf.py by adding 'pelican_jsmath' (with an underscore) to your PLUGINS list. See the Readme for more details.

Packaging Pelican Plugins

It is great that Pelican supports plugins installed via pip and outside the plugins directory. It gives the plugin author and user more control over the plugin version. This is why I wanted to document the steps I took to make pelican-jsmath a Python package.

Simplest setup.py file:

from setuptools import setup


setup(
    name='pelican-jsmath',
    version='0.1.0',
    description='Pelican Plugin that passes math to JavaScript.',
    url='http://github.com/svenkreiss/pelican-jsmath',
    author='Sven Kreiss',
    author_email='me@svenkreiss.com',
    license='AGPL-3.0',
    packages=['pelican_jsmath'],
)

If you are converting a plugin from the pelican-plugins repository, move your files into a folder, here pelican_jsmath, and add a setup.py file. That’s it. You can submit it to pypi if you want, but you can also tell people to install directly from Github using pip install https://github.com/svenkreiss/pelican-jsmath/zipball/master.

With packaged plugins, you can manage your dependencies in your requirements.txt as usual.

Testing Packaged Plugins

This Pelican plugin includes a plugin for the Python Markdown parser that modifies the HTML output. It is good to test that this plugin produces valid HTML. The repository includes an example Pelican site which is regenerated on every commit and validated with html5validator.

Sample

pelican-jsmath sample

Related Posts

Go Top