How I enabled LaTeX on a shared host
If you are reading this blog, you are most probably come into a point where you wanted to enable Latex to your website. Your problem is, you are in a shared hosting and your host do not support Latex. You are running a site that badly needs the functionality of typesetting mathematical equation and you can't move on without this functionality. Your desperate move is either to upgrade to a dedicated server which will increase your monthly cost for about 1200% or to transfer to a host that supports Latex in a shared hosting which will be a real pain. Worry no more, this was my problem before, and I will discuss here how I enable this important functionality to my websites. Take note however that this blog is about "how did I", not "how to". This means that this discussion is not generally applicable to all but I believe this is useful to many.
For a test of this mathematical typesetting in action, you may visit the following links in my shared hosting server.
Rendering of equation is via the clients 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/general-discussion/math-softwares-latex-e...
What is LaTex?
Here is what latex is from the Latex site itself. You can learn more about latex by visiting the link.
LaTeX is a high-quality typesetting system; it includes features designed for the production of technical and scientific documentation. LaTeX is the de facto standard for the communication and publication of scientific documents. LaTeX is available as free software.
First let me clarify one thing, I did not use LaTex. Yes, you read it right, I actually use other typesetting software; namely jsMath and Mimetex. I just used the word Latex in the title because this is the common term used for mathematical typesetting software, the general term for this is Tex. It is like the brand "Xerox" that becomes a proper term for photocopying in the Philippines. In this post I will use the word Latex to mean any mathematics typesetting software.
The CMS I used
First of all, it is important to mention the CMS I am using. The bridge between the typesetting software and to your platform is different in every CMS. I successfully enabled math typesetting in Wordpress but never goes live, I just did it for curiosity. Wordpress is not the answer of my need, I am looking for a more flexible CMS suitable not only for blogging. This blog is not about which CMS is good or CMS1 versus CMS2, so please don't comment here about the CMS. It is important to note that this discussion is focused not on the CMS I used.
I use Drupal, and I am using free modules to enable this functionality. Although much of what I discuss are already on the module's instruction page, there are still things that need to explain that maybe useful to non-developer like me. This is where this post came in. Now, if you are just starting to build a website, I suggest you use Drupal if you really need Latex to your site, this writeup will help you through it. If you already have a website running and it is not powered by Drupal, just read on, you may find some useful information ahead.
There are three modules that will allow you to accomplish Latex in Drupal namely Mathematics Filter, jsMath for displaying mathematics with TeX, and Drutex. Any one of these modules will accomplish our task of enabling Latex in our site.
The Drutex
Among the three, this is the most desirable of all, but unfortunately, this can only be enabled if you have Latex installed in the root directory. Most shared hosting do not have Latex installed and do not allow their client to access the root directory. Drutex will not run unless you've done installing several software packages in your server, software that are required by Drutex. It is now clear that this is not the answer for a shared hosting. You may use this only if you are running in dedicated server.
The jsMath
JsMath stands for Java Script Mathematics, it is the easiest to install. The installation is straighforward, download the 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 large file, it is a collection of more than 20,000 small png files in 178 folders, its zip file is about 7.5 MB. If you extract these fonts to your disk, it will amount to 78.7 MB. I think this is not an issue to you, unless you are running a very large site and you're almost out of disk space. With the jsMath and its fonts already 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 its rule; bridging between your CMS and your new software.
Drupal Specific
The following discussion is specific to Drupal powered website. 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 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.
The next thing is the routine steps in enabling any module in Drupal, 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 saw it transform into your favorite equation of a circle with center at (h, k) and radius r.
Pros and Cons
The advantage of using jsMath is to accomplish your purpose without over loading 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 good looking equation that grows and shrink according to the font size displayed in the browser. The downside however is that, the math equations are rendered in clients browser. Visitors with very slow internet connection will totally hang while loading the script, dial-up's 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 visitor's are in using this module.
The mimeTex
mimeTex is perfect for you if you don't want to overload your visitors' browser. The steps to enable it is easy, you can do it in no time by reading further. The first thing you need is to install mimeTex in your server, the good thing is, it doesn't need to be in the root directory. Simply install/compile it in 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 in shared hosting. It is not difficult, you simply need to know what to do, and if you know it, it will not explode your brain in thinking.
Why I called it painful? It's because you need to compile an executable for it. Most host provider do not allow their clients in shared hosting to compile some 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 worse 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 a private SSH access to your server. I don't really know what is SSH but my host grant me one. With SSH, I was able to access my files via command line. It is tough on my side in doing this thing because I really don't know any Linux command, thanks for the open source community, I was directed to use the PuTTy and it is easy to use and there is a help on how to use it. Just Google PuTTy and you will learn what it is and how to use it. This blog is not about it, so let me just say this; PuTTy will help you compile the mimeTex.
If you cannot compile the mimeTex and your host won't do it for you, don't give up, there is another alternative. Simply upload a pre-compiled binaries of mimeTex to your empty cgi-bin directory. This is not advisable as may the pre-compiled binaries are not compatible with your system. There's no harm of trying, if you are in Linux server, there is 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 install 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 already write it for you. Wordpress is using mimeTex for typesetting equations.
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 the Mathfilter. Test your installation by creating a content and write 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
The loading of your pages containing equations is fast. Unlike jsMath, the rendering of equation is done in the server. this is good if your users are in shared bandwidth like a school laboratories. Your server will not be overloaded as the equation will only be rendered once, just make sure the server will cache equations; this option is available in Drupal's Mahfilter 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 website can actually create their equation via your server, or let me say, you can share this functionality to other website by using your bandwidth. Try for example copying the code below into your page and see what will happen.
<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 send the image to your page. Some will call this advantage and some look this as disadvantage, in my case, I am not sure.
Do you really need LaTex?
If you only have one line of equation in every page, you don't need LaTex. Simply write the equation in word processor, take a screenshot to it, crop it then upload it the way you upload pictures. You will only need LaTex if you are doing heavy mathematics in your site and you are running a community whose central conversation will involve mathematical equations.
- RTFVerterra's blog
- Printer-friendly version
- 319 reads
Re: How I enabled LaTeX on a shared host
I copied this blog to the Drupal.org commmunity. This is my ever-first contributed post in Drupal.org, what a great feeling. I remeber the time when I keep on asking in the forums, but now I started to share what I learned. Here is the link to my post in Drupal.org:
http://drupal.org/node/351985
It was revised to fit into that section. Anybody can actually edit that, there comes a time that there will be a significant difference between the post in this blog and the post in Drupal.org. The good thing is, I started that page and it really feels great. Hurray!
Re: How I enabled LaTeX on a shared host
Thank you for sharing this, this saves me from 2 am sleep. I am using Wordpress and your discussion in mimeTex works.
Post new comment