This site is built with Pelican, a static site generator. While it's nice that the site runs lean without the need of a database, when it comes to support I'm at the behest of a fairly small community (as opposed to Wordpress.

I've been reading more papers in data science and want to publish my notes on this site. When I was in grad school I did the same thing and found it a good way to keep notes (and create content). These papers have plenty of mathematical equations, which pelican doesn't natively support.

Fortunately, Pelican has plugins and one of those plugins is render_math (guess what it does).

In case you're out there rolling your own too, here's a quick guide on how install the render_math plugin on Pelican:

1. Clone the plugins repo somewhere on your machine

Pretty straightforward. This can be anywhere you deem fit. For clarity's sake, let's assume your file structure is as follows (this is taken from the Pelican doc):

/
├── Users/
│   └── yourname/
|      └── yourproject/
|          ├── content
|          │   └── (pages)
|          ├── output
|          ├── develop_server.sh
|          ├── fabfile.py
|          ├── Makefile
|          ├── pelicanconf.py       # Main settings file
|          └── publishconf.py       # Settings to use when ready to publish

We're going to clone the repo under '/Users/yourname/'. Again, you can install it anywhere but you're going to need to tell your Pelican settings file (later) where it is. So first off, 'cd' into that directory and clone the repo:

git clone https://github.com/getpelican/pelican-plugins.git

2. Modify your Pelican settings

Inside pelicanconf, you're going to add two lines. The first will tell Pelican where your plugins file resides, the second will tell Pelican what plugin to user.

# Inside pelicanconf.py
PLUGIN_PATHS = ["Users/yourname/pelican-plugins"]
PLUGINS = ["render_math"]

The settings file also supports relative paths, so you could have easily done the following:

# Inside pelicanconf.py
PLUGIN_PATHS = ["../pelican-plugins"]
PLUGINS = ["render_math"]

3. Install dependent packages

render_math requires Typogrify and BeautifulSoup4 to work correctly. Maybe you use pip to install packages, like I do. Or maybe you use easy_install. Or maybe you do something else. In any case, make sure you install those.

4. Start writing some math

That's it! Now you can write \(x=x_0+vt\) like the best of them. I can also write equations like

\begin{equation} \label{generror} PE \leqslant \rho \frac{(1-s^2)}{s^2} \end{equation}

and refer to them as Eq.\(\ref{generror}\).

Nice!



Comments

comments powered by Disqus