Saturday, May 7, 2011

Latex for Bloggers: Watchmath not Working

Alright a little diversion. For those of you who have seen previous posts know that I use a lot of latex equations. You can too it is simple.

Writing Latex Equations
Here are a few simple steps which you could find on a number of blogs. I am sorry if I do not remember those tens of blogs / sites to give them due credits.

1. Go to the design tab of your blogger dashboard.

2. Then click the Page Elements.

3. By default you should have your blog post on the left and some free space on the right (with some default gadgets already included). This should be the layout of your blog page.

4. On the right hand side of your page, click add a gadget. Another window will pop up. Scroll down in this window until you fine HTML/Java Script. Click on the plus sign and it will be added.

5. In the configure HTML/Java Script window copy and paste the following code:

<script src="http://www.watchmath.com/cgi-bin/mathtex3.js" type="text/javascript"></script>
<script type="text/javascript">
replaceMath( document.body );</script>

6. Now write your equations as shown below:
$ y=mx+c $
$$ y=\frac{1}{1+e^{x}}\ $$;

7. The result will be as follows:
$y=mx+c$
$$y=\frac{1}{1+e^{x}}\ $$

Watchmath not Working
Seldom you find out that the site which is hosting the javascript is down. For example the watchmath site which was hosting the latex javascript is down. Click this link and you will know. There, however, is a way around. Simply host the script at your site. Simply go to google sites and get yourself one for free. And if you do not want to do that, simply copy and paste the following code into the HTML/Java Script gagdet of your blogger and you are done.

<script src="https://sites.google.com/site/onestopallsolutions/course-materials/mathtex3.js?attredirects=0&d=1" type="text/javascript"></script>
<script type="text/javascript">
replaceMath( document.body );</script>

Known Issues
Now, if you know latex, you can easily write beautiful mathematical equations, just by enclosing them between single $ or double $$ signs. But what if you literally want to write the $ sign. The solution to this is proposed by Declan1991 at this site. Copy and paste the following code instead:
<script src="https://sites.google.com/site/onestopallsolutions/course-materials/mathtex3.js?attredirects=0&d=1" type="text/javascript">
</script>
<script type="text/javascript">
onload = function () {
 var els = document.getElementsByTagName("div");
 var i = els.length;
 while (i--) {
  if (els[i].className=="latexparse") {
   replaceMath(els[i]);
  }
 }
};
</script>

Now, whenever you want to write latex equations just enclose your argument between the $ signs as shown below:

< div class="latexparse"> $your latex argument here$ < /div>

There you go. See you next post.

6 comments:

  1. A million thanks bro! This is really working.

    ReplyDelete
  2. the hosting servoce in the post is bad one. Use this:
    src="http://defencedog.googlecode.com/svn/mathtex3.min.js?"
    one can see this in action here:
    http://engineering.forumotion.info/t20-forum-tester

    ReplyDelete
  3. hi. the latex is working fine. but not always. it has always the color: black. i chose a black templete for my blog. so the writings should be white to be readable. but whenever i want to write equations, those become all black. and if i select the equation and color it with a different color using formatting options, then the latex doesn't work. how can i get rid of this problem?

    ReplyDelete
  4. I wish I could respond to your problem in a direct way by doing what I am suggesting next but I cannot. My quick and dirty response to your problem is that it has got to do with the mathtex3.js file. You need to edit the file. Upload it to one of your sites (make yourself one if there isn't any as explained in the post) and you should be done.

    However, it is strange that it is not working on a black background. Use the server as suggested by SeerSucker in the posts above and if it resolves the problem then do post back please.

    ReplyDelete

Follow Husnain_Inayat on Twitter View Husnain Inayat Hussain's LinkedIn profile