Tuesday, November 11, 2008

Testing, testing, testing

{Note: I completely re-wrote this post once I got the ASCIIMathML version working. If you were here earlier, you may have found the not quite working version!}

I'm sure I did this last year when I was working with the Egyptian teachers... but if I did, I didn't write up how I did it on the blog and I had to work it out again. :-(

A maths student was wanting to show formulae in his blog but it has to be said that it is not easy to get the layout right - even for something as simple as a fraction:

$\frac{1}{2} + \frac{2}{3}$

If you want something more complicated, it is even more difficult:


Last year I found jsTeXrender which is a javascript program that does the business and YourEquations.com explains how to use it. It uses a script to turn LaTeX gobbledygook into properly formatted formulae. It is fairly painful to use as you have to switch into the script view of your blog editor and type in some fairly obscure LaTeX commands. There is just about enough information in the above websites to make it possible to add formulae to your blog but it is a bit of a struggle.

However, I have now found an easier way - use ASCIIMathML. This script understands LaTeX, so you can create very complex mathematical formulae if that is what you need to do. Just surround the LaTeX with dollar signs and ASCIIMathML should do the rest.

For example, type
\$\forall x \in X, \quad \exists y \leq \epsilon\$ to get
$\forall x \in X, \quad \exists y \leq \epsilon$
(Note that mathematical packages such as Mathematica and MathType can export in LaTeX format.)

However, ASCIIMathML's real strength is you can type a more or less readable text description of what you want and it will be rendered properly for you. Best of all, you do not have to switch to the script view to enter the formulae - just bracket the formulae with the grave accent, \` (not the apostrophe). For example:

For example, t
ype \`int_0^1f(x)dx\` to get:

Type \`sin^-1(x)\` to get:

Type \`d/dxf(x)=lim_(h->0)(f(x+h)-f(x))/h\` to get:

It was a bit tricky getting this working but the two sets of instructions I found most helpful were How to Post Math Equations in Blogger using ASCIIMathMIL and Equations in Blogger (and other HTML) Made Easy.

While looking for the jsTeXrender, I found a page on MathML which looked promising. I suspect that MathML is likely to be the most future proof solution, but I couldn't get it to work in Blogger at all! Help from scientific/mathematical bloggers who have already sussed this out would be greatly appreciated.


David said...

Answering my own questions... Found this post but I'm not much further forward: http://servalx02.blogspot.com/2007/01/equations-in-blogger.html

mimanifesto said...

Are Jordanhill still taking student teachers from Egypt David ?


Colin Schafer..... said...

Can you not simply create an equation in OpenOffice Math and embed it as an object in your HTML? never tried it myself....

David said...

Hello Jaye

Not this year for an unbelievable reason that's probably best explained offline. :-)

Hello Colin

You can embed as a graphic but it's not as flexible, doesn't look as good and doesn't scale well. I think I have worked out most of the problems and will edit my post in a few minutes. Turns out that it's easier than I thought.