Blogging with weblogger – with images and math!

Back to weblogger.el

I just realised the power of these amazing programmable editors, like emacs. Today evening, I decided to work a bit on productivity. I decided that there are a lot of things I should be blogging about, without wasting a lot of time on trying to sign into the javascript-heavy wordpress interface.

Lot of the things I would like to blog about have images and math content. I thought it might be worth spending some time rigging up ELISP functions to automate some tasks – for instance posting formulae. Here’s some (dirty) code I wrote:

Weblogger Helper Functions

With these functions, I can quickly upload files to my “file” server (to which I have access via ssh) and link them into my blog. This way, I can quickly insert images, links to files on blog posts without bothering about having to upload them.

Inserting links:


M-x weblogger-insert-file
[Type the filename in the minibuffer]
[Wait till it gets uploaded...]

The file is then uploaded and a link to it is inserted into the post.

Inserting images:


M-x weblogger-insert-image
[Type the filename in the minibuffer]
[Wait...]

The file is uploaded and an <img…&rt; tag is inserted which pulls in the image.

Inserting math

With texdrive.el from here, and a few “wrapper” functions in my elisp file, it’s really easy to insert LaTeX formulae into my blogposts. All I need to do is M-x weblogger-insert-formula and enter my TeX formula and a title for it, and the function inserts an <img…&rt; tag into my post. As an example:

M-x weblogger-insert-formula

and then, in the minibuffer:

Formula (TeX): T^{\mu \nu} = (p + \rho) u^{\mu} u^{\nu} - \eta^{\mu \nu}
Title: Stress-Energy Tensor

and the result is:

<img src="http://members.bas.org.in/kstar/blog_files/stress-energy-tensor.png" title="Stress-Energy Tensor" class="texdrive-formula" alt="T^{\mu \nu} = (p + \rho) u^{\mu} u^{\nu} - p \eta^{\mu \nu}" border="0">


Next, I do a M-x weblogger-upload-tex-images and the TeX formulae are automatically picked up from the buffer (by texdrive.el) and put through LaTeX and ImageMagick to produce a png, which my code then uploads to the server. So here’s the result:

T^{\mu \nu} = (p + \rho) u^{\mu} u^{\nu} - p \eta^{\mu \nu}

I’d be glad if somebody would like to improve the code. It’s licensed under the GPL.

[Thanks to SG for pointing out that I had missed a ‘p’ factor in front of the Minkowski metric]

HTH 🙂

Advertisements