Incorporating MimeTeX into WordPress

November 6th, 2007 | Categories: Other

I get asked all the time, “how did you manage to add mathematical equations to your blog?”

Well, maybe not all the time (actually, never, but lets pretend I do).

The mathematical equations in the blog are typed in a mathematical markup language known as LaTeX. LaTeX is widely used in prestigious scientific journals such as Physical Review to properly format their papers. It produces professional results, and often looks much better than, say, Microsoft Word in the hands of a non-designer.

A full installation of LaTeX is a complicated business, and isn’t possible on most shared servers. However, the LaTeX community has been lucky enough to have a guy named John Forkosh create a web-compatible program, named MimeTeX, which is light-weight and easy to use. Here is the program’s homepage: MimeTeX.

MimeTeX isn’t hard to install - it’s finding the proper instructions that is so difficult! I’ve therefore decided to write a short guide myself on installing the software. Keep in mind I am no expert, and am simply recounting my own installation tale, along with all of the mistakes I’ve managed to make - and I believe that’s almost all of them.

This is not a LaTeX tutorial. If you wish to learn LaTeX, you will have no trouble finding many tutorials on the web. Knowing LaTeX is a real cool trick to have under your belt, as it produces such professional looking documents.

What You Will Need

Here’s the grocery list:

  1. A site with WordPress installed.
  2. A cgi-bin directory for your site. This is, basically, a directory in which you can place scripts and executable files. I’ll be assuming you’ll be using a Linux based server, although a Windows installation shouldn’t be different. The difference is that, executable files in Linux appear sometimes with a .cgi extension. I would like to note that there is a programming language called PERL, the scripts of which also end with a .cgi. It is written in c and then compiled. Being a Windows guy, my Linux expertise is quite limited, but I am definitely sure that MimeTeX is not a PERL script. In a Windows environment, mimetex.cgi would be mimetex.exe. There’s nothing ASCII about it. Should any problems arise during the installation, one thing you should check out with your hosting service is whether they can execute MimeTeX at all. If not, I suggest finding a host who can.
  3. Go to MimeTeX and download the compiled binary for the operating system your host uses. Mine, for example, uses FreeBSD. Ask your host if you’re not sure. There is a possibility of compiling MimeTeX on the host’s computer, but that is something that should be left as a last resort and is not covered in this tutorial, as it requires shell access. You will probably need to contact your host and ask them specifically to compile the files for you.
  4. An FTP program, such as FileZilla, with FTP access to your site.

What You Will Need To Do

Installing MimeTeX:

  1. Upload mimetex.cgi to your cgi-bin directory. Make sure you upload it as a binary file. Most (99%) FTP programs will allows you to specify whether to upload a file as ASCII, binary, or auto (let the program decide). Do not set the upload to “auto”, as the FTP program will think that your .cgi file is a script written in ASCII.
  2. Using your FTP program, change the permission of mimetex.cgi to 755. In FileZilla, this means right clicking on the file, selecting “File Attributes”, and setting:
    1. All owner permissions to “on”,
    2. Group read and execute permissions to “on”,
    3. Public read and execute permissions to “on”.
  3. Now give your mimetex.cgi a spin: in your browser’s window, write “http://www.mysite.com/cgi-bin/mimetex.cgi?x^2+y^2=z^2″ and you should see Pythagoras’s theorem in all of its glory on the screen.

Incorporating MimeTeX into WordPress:

  1. Download Ander Dahnielson’s plugin for WordPress from here. This particular file was modified by myself a bit. Edit the file and change the www.my-domain.com address to the address of your site.
  2. Upload the plugin to the wp-content/plugins directory of your WordPress site.
  3. Create a directory wp-content/cache/, and chmod it to 755 (see above for chmod-ing something this way using FileZilla).
  4. Go to the administrator’s panel in WordPress, select Plugins from the tabbed menu, and activate the plugin.
  5. To add equations, switch to code view when writing a new post, and encase the post between <tex></tex> tags. For example, try <tex>x^2+y^2=z^2</tex>. Remember, you need to be in code view - visual view will not work.

That’s it! You should have MimeTeX up and running this way in no time.

A Few Comments

  1. Take a look at the following line in daniehlson_mimetex.php: return "<img src=\"$cache_formula_url\" alt=\"$formula_text\" class=\"simple\" />"; This line tells WordPress to output MimeTeX’s equations as images of the “simple” class. What “simple” means is specified in the CSS file of your WordPress site. If you want to change the appearance of your equations - float properties, borders, background color and so forth - you will need to edit the appropriate CSS style sheet of your current theme. Doing this is beyond the scope of this tutorial, but
  2. For the plugin to work you will need PHP’s CURL library to be enabled. This is usually the case, but for some hosts it is not enabled by default. CURL is the library used to write PHP spiders, which can be used for spamming and spying, so it is understandable why some hosts wouldn’t be too keen to turn it on by default. I’m pretty positive that a brief email to your host would convince them you mean no harm.
  3. There is one flaw in the installation described above: mimetex.cgi is accessible to all, including outsiders. This means that hordes of greedy mathematicians and physicists might use YOUR server and bandwidth to output THEIR images. Yes, such true horror stories have been known to happen. Well, not really, but just in case they do, John Forkosh, the creator of MimeTeX, has created a way of blocking requests from outside the server. This entails recompiling mimetex.cgi on the server, with a certain flag (DREFER, unless I’m mistaken) enabled. John’s homepage explains all you’d ever want to know about compiling MimeTeX and has several examples clearly illustrating the point. You’d probably need your host’s help with this, though, as you’re using a shared server and don’t have shell access.

Happy LaTeXing!

  • Share/Save/Bookmark
  1. April 10th, 2010 at 23:25
    Reply | Quote | #1

    тут интересно, но надо и поспать.