Pelican plugin render_math not working in markdown

78 views Asked by At

I have installed Pelican on an Ubuntu server running in VirtualBox and it is working just fine! But when I tried a math equation it did not render it at all.

I checked the Pelican version:

$ pelican --version
4.9.1

Directory structure:

webroot/
  pelicanconf.py
  content/
  output/
  ... etc ...
  plugins/
     ... plugins go here ...

pelicanconf.py:

PLUGIN_PATHS = ['plugins']
PLUGINS = ['render_math']

There doesn't seem to be any additional math related settings in pelicanconf.

Installed plugins:

git clone https://github.com/getpelican/pelican-plugins plugins
$ git log
commit 10a14332c35932b282b1ec63f0e10ae7d45aed8c (HEAD -> master, origin/master, origin/HEAD)
Merge: 50da7ed 252eb86
Author: Justin Mayer <[email protected]>
Date:   Fri Nov 10 18:46:05 2023 +0100

Note: no warnings or errors in syslog when I start the service running Pelican.

The theme I'm using is "pelican-twitchy" with a few minor CSS changes I made. It does not seem to have any additional config for implementing mathjax.

Based on various websites, I tried these in my markdown file:

$x^2$
$x + y$
$$ s(t) = \int_{-\infty}^{+\infty} {F(f) e^{j 2 \pi f t} } dt $$
\begin{equation} x^2 \end{equation}

They render as plain strings, no mathjax at all.

But then I noticed the Readme.md in render_math says:

**NOTE: This plugin has been moved to its own repository. Please file any issues/PRs there. Once all plugins have been migrated to the New Pelican Plugins organization, this monolithic repository will be archived.

Since I am running Pelican 4.9.1 I tried:

rm -rf plugins
mkdir -p plugins
git clone https://github.com/pelican-plugins/render-math.git plugins/render-math

Updated pelicanconf.py:

PLUGIN_PATHS = ['plugins']
PLUGINS = ['render-math']

And when I restarted Pelican via the service:

ERROR    Cannot register plugin `render-math`               log.py:94
         module 'render-math' has no attribute 'register'

What should I try next?

1

There are 1 answers

3
JohnA On

Went to https://github.com/pelican-plugins/render-math/issues/20 and it suggested going to: https://github.com/pelican-plugins/render-math#enabling-additional-features

And that section says:

The MathJAX JavaScript file must be added to the HTML file, either via your theme's template configuration (if supported) or by editing the relevant template file directly. The current MathJAX CDN is hosted at http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML, and the code to add it to the HTML is provided below.

As long as this script is loaded in either the head or body of the HTML output, the complex expressions are also converted.

I added this line to base.html:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

and these lines (double $$ delimiters) now work:

$$F[f] = 1/N \sum_{k=0,f=0}^{N-1} {s[k] * cos( -j k \theta f / N)  + j sin( -j k \theta f / N)}$$
$$F(f) = \int_{-\infty}^{+\infty} {s(t) e^{-j 2 \pi f t} } dt$$
$$ e^{j\theta} = cos(\theta) + j sin(\theta) $$
$$ s(t) = \int_{-\infty}^{+\infty} {F(f) e^{j 2 \pi f t} } dt $$

The single $ lines still don't work:

$x^2$
$x + y$
$x \implies y$
test $s(t) = \int_{-\infty}^{+\infty} {F(f) e^{j 2 \pi f t} } dt$ inline

These don't work, but is expected:

<math>x^2</math>
<math>$x^2$</math>