Adding template pages to Pelican

I was having a lot of trouble just getting my site to generate an authors file, even though I’m the only author here. The pelican documentation says you can add something like

AUTHORS_URL = 'blog/authors.html'
AUTHORS_SAVE_AS = 'blog/authors.html'

To generate the authors.html file.

It wasn’t working for me. Well, after going through the source code and finding the relevant section in generators.py I found that you have to set DIRECT_TEMPLATES like so:

DIRECT_TEMPLATES = ('index', 'tags', 'categories', 'archives', 'authors')
AUTHORS_URL = 'blog/authors.html'
AUTHORS_SAVE_AS = 'blog/authors.html'

Now it works! And looking back at the documentation, it actually sort of hints at this. D’oh!

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!

Testing out Pelican

Hi there!

I’m trying out Pelican.

I moved to Pelican from Octopress, mostly because I heard good things about Pelican being written in Python, and honestly I hadn’t really done anything in Octopress so there wasn’t any loss at that point.

Pelican, like Octopress, is a static site generator. This means you don’t have to fiddle around with setting up a SQL database and have PHP scripts dynamically generating your content. This can be nice if you don’t want to have to deal with potential security problems with running SQL and PHP on your server. Also, if you don’t have the ability to run those (e.g. you don’t have root privileges to install things on a server), then using a static site generator is a great solution.

Because your blog posts are stored as reStructuredText or Markdown files in the filesystem, you can also use something like git to handle revision control of your website.