## Friday, July 2, 2010

### Javascript, HTML, jQuery and the Milk of Human Kindness

Some of you who read this blog (optimistically) would have noticed the ugliness which was perpetrated on this blog in this previous post since I put up this other post. This was largely because the $LaTeX$ parser I use to display math was also encoding certain bits of R code with the character "$!$" as $LaTeX$.

Since then I have had a great if sometimes frustrating time googling and querying the developer forums and have learnt a lot about how HTML, Javascript and jQuery work. Thank you in particular to the anon. moderator on the webdeveloper forums who spent quite a bit of time helping me through this.
The trick is to define and send the contents of a user-defined div class to the parser on load. This involves setting up your Blogger "HTML/Javascript" widget to contain the Javascript:

var els = document.getElementsByTagName("div");
var i = els.length;
while (i--) {
if (els[i].className=="latexparse") {
replaceMath(els[i]);
}
}
};


and then include everything you want the parser to parse as in the following example:
$\frac{1}{2}$