# Getting LaTeX Math to work in Pelican

Basically, you can follow this post verbatim.

I’ll just explain how I got to work on my personal setup. First of all, in order to do this you’ll need to edit your template. I have a copy of the “notmyidea” template in my blog directory, so I can make changes to it. You can copy /usr/share/pyshared/pelican/themes/notmyidea to your blog directory, for example if my pelican files live in ~/blog/ I’d copy notmyidea to ~/blog/themes/notmyidea. Now you’ll need to tell Pelican where to look for your theme, you can do this by editing your pelicanconf.py to include:

THEME = "themes/notmyidea"
THEME_STATIC_DIR = "theme"
THEME_STATIC_PATHS = ['static']
CSS_FILE = "main.css"

Now, in blog/themes/notmyidea/templates/base.html you’ll need to add

<!-- Using MathJax, with the delimiters $--> <!-- Conflict with pygments for the .mo and .mi --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { styles: { ".MathJax .mo, .MathJax .mi": {color: "black ! important"}} }, tex2jax: {inlineMath: [['$','$'], ['\\\$','\\\$']],processEscapes: true} }); </script> <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> in the <head> section. Now that you have this done, you should be able to start using inline equations using \$a^{\\beta}\$to get$a^{\\beta}$(note the double backslash). I was having problems, however, getting the math directive to work with MathJax. What was happening was that instead of creating a <div class="math"> for the mathblock, RST was parsing the$\LaTeX\$ as HTML. In order to fix this, you need to edit your docutils settings, as documented here. I did this by having a docutils.conf in my ~/blog folder with the following contents:

[html4css1 writer]
math_output: MathJax

Now

.. math::

\frac{1}{\sqrt{2\pi\sigma^2}}\operatorname{exp}\left\{-\frac{\left(x-\mu\right)^2}{2\sigma^2}\right\}

Outputs to:

$\frac{1}{\sqrt{2\pi\sigma^2}}\operatorname{exp}\left\{-\frac{\left(x-\mu\right)^2}{2\sigma^2}\right\}$

Yay!