Table of Contents
If you are using the latest official version of Emacs and the latest version of org-mode, which is not the same thing as the version of org-mode that is shipped with Emacs, then here is some way to publish a blog post to wordpress with math equations in it, using org-mode.
1. some preliminary
In an org-mode buffer, one uses dollar signs (the same way as in LaTeX documents) to surround mathematical expressions, but without extra spaces. That means:
$a^2 + b^2$ is good but $ a^2 + b^2 $ is not good.
When you run the command
org-export-dispatch on an org-mode buffer, you can choose to export the contents to HTML. When you do that, something like
$a^2 + b^2$
is exported to something like
\(a^2 + b^2\)
When you paste the exported HTML text into the textbox of the WordPress post editor and press Preview, you will see that the generated preview does not have math equation images.
2. search and replace
The WordPress manual mentions that writing something like
$.latex a^2 + b^2$
(without the dot) is the way to have WordPress generate equations images.
So you just have to search for all occurrences of something like
\(a^2 + b^2\)
in the exported HTML text, and then replace them appropriately before pasting the contents to the WordPress post editor.
Emacs certainly has “search and replace” feature and you can even save such a task as a keyboard macro, but let me give you a command for the task:
(defun my-parens-to-wordpress-math () "Replace \\(...\\) with in current buffer." (interactive) (save-excursion (save-match-data (goto-char (point-min)) (let ((case-fold-search nil) (re (rx "\\(" (group (+? not-newline)) "\\)"))) (while (re-search-forward re nil t) (replace-match (concat "$" "latex \\1$") t))))))
Wrote that command to publish my first math-heavy article on this blog: article on information entropy
3. some idea on how to write a math blog post using org-mode, AUCTeX, latex-preview
My workflow for now is like this:
- Write an outline (looking like a TOC) for a blog post in an org-mode buffer
- Instead of continuing in an org-mode buffer, I switch to an AUCTeX mode buffer, and write one section there (with the visual help of preview-latex), and then paste it back into a section in the original org-mode buffer.
- Go on with the next section.
- and so on
AUCTeX does have an outline feature and org-mode does have LaTeX preview feature, but I am more at home with the outline feature of org-mode and the preview feature of AUCTeX for now.