pelican mathjax

pelican static website mathjax
By Pierre Feilles Published on Last update on

update (2018-12-18)

To write math with the pelican blog engine, it is now possible to simply use the render_math plugin in the official plugins repository.



Here is a simple method to write math in markdown for the pelican static website engine using this simplified latex plugin for markdown.

Credits

The original complete pelican plugin for rendering math by Barry Steyn was simplified into this plugin (by Jake Vanderplas) which I forked to use the update provided by Wittawat Jitkrittum. The mathjax extension is written by Rob Mayoff.

Installation

Install this mathjax extension for the python markdown module. (The other two we need, extra and codehilite, are officially supported)

Create a plugins directory in the pelican website repository. And then copy this latex.py file to it.

And then just add

PLUGIN_PATHS = ["plugins",]
PLUGINS = ["latex"]
MD_EXTENSIONS = ['codehilite(css_class=highlight)','extra', 'mathjax']

to your pelicanconf.py file.


The latex.py plugin is adding the following script, which is loading mathjax, to articles and pages metadata:

<script async type= "text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
   MathJax.Hub.Config({
       config: ["MMLorHTML.js"],
       jax: ["input/TeX","input/MathML","output/HTML-CSS","output/NativeMML"],
       // ....
   })
 </script>

Use

Now we can write latex directely in markdown files.

For example, latex inline \\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\\) gives : \(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)

And

$$ A_{m,n} = \begin{pmatrix}
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
\vdots  & \vdots  & \ddots & \vdots  \\
a_{m,1} & a_{m,2} & \cdots & a_{m,n}
\end{pmatrix}
$$

gives :

$$ A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix} $$

Comments

comments powered by Disqus