Skip to main content

Blogging with Emacs: Plots and Diagrams

Continuing my very-meta habit of blogging about how I'm blogging, and not much else… I give you: "Bells and Whistles," perhaps better titled, "More of the Same".

In Emacs Org Mode, there are many ways to plot and diagram, and even draw (it's terrible, don't bother). Let's see if we can get some working with my Nikola-based blogging solution.

Plotting Charts

This example is from Org Mode's official documentation, though I've changed the output path for Nikola building.

First I'll activate a Python venv with matplotlib pre-installed

import matplotlib
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(3,2))
plt.plot([1,3,2])
fig.tight_layout()

fname = '../images/myfig.png'
plt.savefig(fname)
# fname[1:] # return this to org-mode

Then make an HTML link (on Org export) into images, like this:

[[./images/myfig.png]]

Which will then display the image after Nikola builds, like this:

nil

Voila! We plotted a chart! If I change the Python code, and re-build, I'll get a different chart.

Diagramming

Diagrams are different from plots and charts. They aren't strictly mathematical. Instead, we need to look to other possible solutions.

Emacs package sources offer several options, but the one I have experience with is ditaa.

+--------+   +-------+    +-------+
|        | --+ ditaa +--> |       |
|  Text  |   +-------+    |diagram|
|Document|   |!magic!|    |       |
|     {d}|   |       |    |       |
+---+----+   +-------+    +-------+
    :                         ^
    |       Lots of work      |
    +-------------------------+

Then make an HTML link like before:

nil

Voila! We made a diagram!

Conclusion

I also tried including LaTeX equations and inline LaTeX, to no avail. Even with the default MathJax, it seems that Nikola does not do a pure Emacs Org Mode export to HTML, and I was unable to get LaTeX working.

Which brings up the point I'd like to conclude with:

Nikola + Org Mode is a workable solution that lets us use most Org Mode features out-of-the-box, like tables, executable code blocks, and the like.

However, when it comes to bells and whistles, it falls a little short of pure Org Mode HTML export.

  • Having to create a separate HTML link for an image is annoying, but Nikola makes so much else easier that I can probably overlook it. If I was doing a pure Org Mode export, Emacs would create the image link for me.
  • The ditaa integration was awkward, at best. I basically had to do an Org Mode HTML export to the ../images directory, then add an HTML link. If it was pure Org Mode export, Emacs would create the image link for me.
  • No Emacs-based LaTeX. In fact, I couldn't get LaTeX to display at all! Even after I added the mathjax tag to the post's meta file, as described in the Nikola Handbook.

For now, I'll keep using Nikola, but my next iteration of this blog might be pure Org Mode, with HTML templates.

Comments

With an account on the Fediverse or Mastodon, you can respond to this post. Since Mastodon is decentralized, you can use your existing account hosted by another Mastodon server or compatible platform if you don't have an account on this one. Known non-private replies are displayed below.