2008/05/13

LaTeX equation on drupal blog

If you want to put mathematical equations on your website but you do not have latex, dvipng, imagemagic installed on your shared hosting server, you will probably search Google with the following questions:

  1. how to type latex on website
  2. how to put mathematical equations on blogs or websites
  3. latex on drupal site, latex on wordpress
  4. codecogs online equation editor for typesetting (rendering) latex

The purpose of this talk is to share my experience with the Internet community (webmaster, managers, forum moderators/admins) who are in search of a way to enabling their users to add mathematical equations in their posts typeset in LaTeX. This talk is not about how to typeset in LaTex, though. If you are looking for typesetting (i.e., typing) in LaTex, please search Google and you will find lots of good references. (I find this one to be the most comprehensive yet short guide to LaTeX2E).

What I've found lately:

There are basically four different ways one can put mathematical equations typeset in LaTex. These are:

I could not try DruTeX since it is not available for Drupal 6. Also it requires LaTeX, dvipng and ImageMagic or other latex renderer installed on the server, which you won't usually have on a shared hosting account. I've tried JsMath, CodeCogs equation editor and lately Mathfilter based MimeTeX solutions. I will share my experience about each of those.

The beauty of JsMath is describe on the project webpage

"It overcomes a number of the shortcomings of the traditional method of using images to represent mathematics: jsMath uses native fonts, so they resize when you change the size of the text in your browser, they print at the full resolution of your printer, and you don't have to wait for dozens of images to be downloaded in order to see the mathematics in a web page"

However, I did not find JsMath very effective or efficient for my site. First of all, it took unusually big amount of space on my server (about 30MB). The font installer that comes with the software iteself is 7MB. Also it is really very slow to render the fonts when you visit the page containing equations. I would say that is really very inefficient.

CodeCogs solutions are by far the best among these. They produce really good images of the equations and you dont have to worry about linking those images from your page. All images will be hosted on CodeCogss server. All you need is to go to CodeCogs Web Equation Editor and paste your LaTeX equation in the appropriate box. Then click "Render Equation". If what you typed is correct, it will show you the equation as-it-will-show on your webpage. All necessary html code will also be generated at the botton of that equation editor window. You can copy and past it on your website. But the possible limitation of this method is that you are basically depending on somebody else's server and if, in future, they discontinue this service, you have no way to recover those equation images.

Lastly, Mimetex based solution is very easy one. First, install MimeTex. Download mimetex.zip and then type
unzip mimetex.zip
cc -DAA mimetex.c gifsave.c -lm -o mimetex.cgi
mv mimetex.cgi to your cgi-bin/ directory.

To test before installing drupal module, run http://www.yourdomain.com/cgi-bin/mimetex.cgi?x^2+y^2

if you see [tex]x^2+y^2[/tex], then mimetex is installed successfully. Please see more details here. MimiTex works nicely with Mathfilter. But Mathfiler has bug in it and please see the discussion at http://drupal.org/node/205994. The solution I got is to remove the argument from line 16 of the mathfilter.module file.

I just removed $may_cache from the following line (line 16 in the mathfilter.module) and that seems to be working for me.

function mathfilter_menu($may_cache) {

Softwares that I use:

I used TinyMCE editor for creating content but it has some issues with linebreaks. So I have turned to FCKEditor which is working very nicely on my server. Its very easy to configure and very easy to add or remove buttons from the editor by simply editing the configuration file. Detail help can be found in the installation folder.

CodeCogs has a plugin for FCKEditor which enables you to add a button on the menu to launch the equation editor from the editing window.

Results:

This following equation has been created using the web-equation editor provided by CodeCogs. Following is a Box-Cox transformation equation that is widely used to transform nonnormal data into normality by choosing an appropriate \inline \lambda.

0 \\ \ln U_t, & U_t >0, \,\, \lambda=0. \end{array}\right." border="0">

Now, I the same equation using MimeTeX based solution:

[tex] \left\{\begin{array}{lc} 1/\lambda (U_t^\lambda -1), & U_t \ge 0, \, \lambda>0 \\
\ln U_t, & U_t >0, \,\, \lambda=0.
\end{array}\right.[/tex]

Thank you for visiting StatTalk.Org.

References:

  1. Some discussion at http://drupal.org/node/130348.
  2. CodeCogs Online Equation Editor.
  3. Drupal modules for displaying math on webpage

If you find this page useful, I would appreciate if you place our link on your site. Thank you.

No comments:

Post a Comment