# Pelican MathJax Issue

I updated pelican recently because I had upgraded to python 3.x. When I tried to execute pelican content command, it threw an error saying no valid contents were found. After some searching, I found out that I hadn't re-installed markdown (the earlier version was completely undetectable).

After installing markdown by pip install markdown, I re-ran the earlier command but this time I got this warning -

\$ pelican content
Traceback (most recent call last):
File "C:\Users\CHANDAN\Techblog\pelican-plugins\render_math\math.py", line 272, in mathjax_for_markdown
pelicanobj.settings['MD_EXTENSIONS'].append(PelicanMathJaxExtension(config))
KeyError: 'MD_EXTENSIONS'

Error - the pelican mathjax markdown extension failed to configure. MathJax is non-functional.


Apparantly, my MathJax plugin wasn't working properly. I searched for this error on Google which led me to this Github issue #815. On further reading, I found out this issue was merged with an earlier one #787. On this link, I found a commit made to math.py file. Here's the change at line 271.

Instead of this -

    try:
pelicanobj.settings['MD_EXTENSIONS'].append(PelicanMathJaxExtension(config))
except:
sys.excepthook(*sys.exc_info())
sys.stderr.write("\nError - the pelican mathjax markdown extension failed to configure. MathJax is non-functional.\n")
sys.stderr.flush()


Write this -

    try:
if isinstance(pelicanobj.settings.get('MD_EXTENSIONS'), list): # pelican 3.6.3 and earlier
pelicanobj.settings['MD_EXTENSIONS'].append(PelicanMathJaxExtension(config))
else:
pelicanobj.settings['MARKDOWN'].setdefault('extensions', []).append(PelicanMathJaxExtension(config))
except:
sys.excepthook(*sys.exc_info())
sys.stderr.write("\nError - the pelican mathjax markdown extension failed to configure. MathJax is non-functional.\n")
sys.stderr.flush()


And it worked like a charm. Now you know what to do when you encounter this error.

Example -

$$\frac{Q_{1}Q_{2}}{4\pi\epsilon r^{2}}$$

$$d = \sqrt{(x_{2} - x_{1})^2 + (y_{2} - y_{1})^2}$$

See you in the next post :)