How I enabled LaTeX on a shared host

Last updated on
30 April 2025

This post will be of interest if you are running a site that needs the functionality of typesetting mathematical equations but you are on a shared host that does not support LaTeX. Your could either upgrade to a dedicated server (which will increase your monthly cost about 1200%) or transfer to a shared host that supports LaTeX which will be a real pain. Worry no more, this was my problem, and I will discuss how I enabled this important functionality. Take note, however, that this post is about how I did it, and not a "how to". This means that this discussion is not generally applicable but I believe it will be useful to many.

For a test of this mathematical typesetting in action, you may visit the following links to my shared hosting server.

Rendering of equations is via the client's browser:
http://www.mathalino.com/reviewer/derivation-of-formulas/derivation-of-q...

The equations were rendered in the server at cgi-bin directory:
http://www.mathalino.org/forum/5

There are four modules that will allow you to use LaTeX in Drupal namely Mathematics Filter, jsMath for displaying mathematics with TeX, MathJax, and DruTeX. Any one of these modules will accomplish our task of enabling LaTeX in our site.

DruTeX

Of the three modules, this is the most desirable of all, but unfortunately, it can only be enabled if you have LaTeX installed in the root directory. Most shared hosts do not have LaTeX installed and they do not allow their clients to access the root directory. DruTeX will not run unless you've installed several required software packages on your server. It is now clear that this is not the answer for a shared host. You can only use this module if you are on a dedicated server.

MathJax

Added by julou

MathJax is the modern, ajax-based, full-featured LaTeX rendering solution for the web. It is very easy to install as the third-party library is automatically downloaded from MathJax Content Delivery Network (CDN). The CDN will automatically arrange for your readers to download up-to-date MathJax files from a fast, nearby server.

Simply download MathJax module, unarchive it to your module directory, and enable it. You can start typing equation using $ as delimiters. Drupal 7 is supported.

jsMath

JsMath (JavaScript mathematics), is the easiest to install. Download jsMath from Sourceforge.net then upload it to the appropriate directory in your server. You also need to download the jsMath fonts, and upload it inside the jsMath folder. These fonts are in a large file, it is a collection of more than 20,000 small PNG files in 178 folders, so its zip file is about 7.5 MB. If you extract these fonts to your disk, it will amount to 78.7 MB. With jsMath and its fonts in their appropriate directories, all you need to do is call it. Your CMS needs to understand that it is there, this is where some modules play their role; bridging between your CMS and your new software.

Drupal-specific

The following discussion is specific to Drupal-powered websites. If you are using Drupal 5.x or Drupal 6.x, the steps are the same, just download the appropriate module for the version you are using.

Extract the jsMath module to the sites » all » modules directory, you will have a directory called sites » all » modules » jsMath. Extract the jsMath software you just downloaded from Sourceforge.net to sites » all » modules » jsMath, now you will have a directory called sites » all » modules » jsMath » jsMath. Extract jsMath fonts to sites » all » modules » jsMath » jsMath and you will have a folder called sites » all » modules » jsMath » jsMath » fonts.

Go to admin/build/modules and enable the jsMath module. Go to admin/settings/jsmath and configure it the way you want it. Now try your installation by creating any content, just type $(x - h)^2 + (y - k)^2 = r^2$ and see it transformed into your favorite equation of a circle with center at (h, k) and radius r.

Pros and cons

The advantage of using jsMath is that it does not overload your server. It is easy to install and configure. It can be printed at high resolution and the size of your equation will adjust (in percentage) according to your font size. You can have a nice looking equation that grows and shrinks according to the font size displayed in the browser. The downside, however, is that the math equations are rendered in the client browser. Visitors with very slow Internet connections will totally hang while loading the script, dialups cannot view your page with equations. This is not a problem for visitors with a speed of 10 Mbps and faster. So, it is important to know who your visitors are.

mimeTeX

mimeTeX is perfect for you if you don't want to overload your visitors' browsers. It is easy to install. The first thing you need is to install mimeTeX on your server, the good thing is, it doesn't need to be in the root directory. Simply install/compile it in the http://www.example.com/cgi-bin directory. If you have no cgi-bin directory, just create one. To do the installation, you need to upload the file called mimetex.zip and extract it inside the cgi-bin directory. The next step is a little painful on a shared host. It is not difficult, you simply need to know what to do, and if you know it, it will not explode your brain.

Why do I say it is painful? It's because you need to compile an executable for it. Most host providers do not allow their shared hosting clients to compile an executable. If you are in this position, simply contact your host and ask them to compile it for you. Other hosts also are hesitant to do it if they don't trust the software or worst of all, they don't trust you. Your relationship with your host is vital to accomplish this step.

If you are allowed to run the compilation (you are lucky), you need to have private SSH access to your server. I don't really know what is SSH but my host granted me one. With SSH, I was able to access my files via the command line. It is tough on my side in doing this thing because I really don't know any Linux commands, thanks to the open source community, I was directed to use PuTTy. If you need help, just Google PuTTy and you will learn what it is and how to use it.

If you cannot compile mimeTeX and your host won't do it for you, don't give up, there is another alternative. Simply upload a pre-compiled binary of mimeTeX to your empty cgi-bin directory. This is not advisable as it may be that the pre-compiled binaries are not compatible with your system. There's no harm in trying. If you are on a Linux server, there is a 99% chance that the pre-compiled binaries will work for you.

Once you have the executable running in your cgi-bin directory, the next thing to do is a standard step. Tell your CMS that you just installed mimeTeX and let them understand each other. I am talking about writing a code that will allow your CMS and mimeTeX to communicate. If you are using an open source CMS, there is a chance that somebody has already written it for you.

Drupal specific

Upload and extract the Mathematics Filter to the modules directory and enable it. The process of doing so is the same as above in enabling the jsMath module. Configure the input formats of your site, just go to admin/settings/filters and select which input format to use with Mathfilter. Test your installation by creating content and copy this code to your page: [text](x - h)^2 + (y - k)^2 = r^2[/tex]. The code will transform into an equation of a circle with radius r and center at (h, k).

Pros and cons

Pages containing equations will load fast. Unlike jsMath, the rendering of equations is done on the server. This is good if your users have lower bandwidth. Your server will not be overloaded as the equation will only be rendered once, just make sure the server will cache the equations; this option is available in Drupal's Mathfilter module. Your equation will look a little ugly in mimeTeX and sometimes the alignment is not very good in inline equations. It is a little complicated to install.

I am not sure if this is an advantage or a disadvantage. Other websites can actually create their equation via your server, or let me say, you can share this functionality with other websites by using your bandwidth. For example, try copying the code below into your page and see what happens.

<img src="http://www.mathalino.org/cgi-bin/mimetex.cgi?f(x)=\int_{-\infty}^xe^{-t^2}dt" >

My server is actually doing the work of rendering the equation and sending the image to your page. Some will call this an advantage and some will look at this as a disadvantage. In my case, I am not sure.

Do you really need LaTeX?

If you only have one line of equation on every page, you don't need LaTeX. Simply write the equation in a word processor, take a screenshot, crop it then upload it the way you upload pictures. You will only need LaTeX if you are doing heavy mathematics on your site and you are running a community whose central conversation will involve mathematical equations.

Help improve this page

Page status: Not set

You can: