Community Documentation

# Displaying mathematics with TeX

Last updated August 31, 2011. Created by LeeHunter on July 13, 2007.

The standard syntax that mathematicians use to type mathematical expressions is TeX and its extensions LaTeX and AMSLaTeX. Almost all mathematical research is written in TeX. It is not surprising therefore that TeX has also become the de-facto standard for writing mathematics online.

While TeX syntax is a convenient way of entering mathematics, when you look at the mathematics you don't want to have to read the TeX syntax but want the mathematics to appear nicely typeset.

Drupal has several modules that achieve this. These are compared briefly below so that you can judge which one will be the most appropriate for your installation.

The choice will depend on the complexity and amount of mathematics that you are planning to display on your site and also on whether you are willing and able to install additional software on your server.

## Client side

### MathJax

MathJax is the succesor of jsMath. It is the modern, ajax-based, full-featured LaTeX rendering solution for the web. You can check impressive demos by the developers. Using MathJax, mathematics are rendered by the user's browser, and the default configuration fetches MathJax source from the web directly. So this solution is extremely light-weighted as it does not increase the load or decrease the disk space on your server. As a result, it works fine even with shared hosting service.

### jsMath

jsMath is a piece of javascript that renders the TeX on the client's browser. This means that you do not have to install any TeX rendering software on your server and the processing of TeX does not increase the load on your server. The downside of course is that the user's browser has to work harder and the display of the mathematics takes a bit longer. With the default setting jsMath will display the page to the browser initially with all the TeX syntax still in place and will then start converting this into typeset mathematics. So the user can already start reading the page while jsMath is still converting the TeX. You can get an impression of how well this works by looking at examples.

### Wysiwyg ASCII Math

Wysiwyg ASCII Math is a Wysiwyg editor plugin that adds ASCII and TeX entry of math/formulas and plots/graphs entered in ASCII/TeX.

It allows for Client-side conversion of ASCII & TeX equations into nicely typeset formulas and falls back to Server-side generation of images (using mimetex.cgi) for browsers that don't support MathML.

## Server side

If you do not want to shift the work of processing the TeX to your user's browser then you should go with one of the next modules.

### Math filter

Mathematics Filter uses MimeTeX to convert the TeX to images that are then included in the webpage. This requires you to install the mimeTeX executables on your server. MimeTeX does not use the standard TeX engine but renders directly to images. This makes it very fast. It does however mean that, like jsMath, it can render only a subset of the complete TeX syntax. For most applications this will not be a problem. But if it is, then you should go with the DruTeX module instead.

### DruTex

DruTeX uses the full LaTeX engine to convert the TeX to dvi and then uses ImageMagic and dvipng to convert the dvi to images. This means that unlike the other solutions DruTeX can handle the entire TeX syntax. The drawback however is that you need to install several software packages on your server before DruTeX will work. Also the processing of the TeX will put extra load on your server. DruTeX is quite an impressive module with its own plugin architecture. It has its own discussion group.

Note that if you must use ImageMagick (convert), it does not support dvi input. You must use an additional program to convert form dvi to ps (PostScript), an input that convert will accept. Summation: tex code -> into latex -> dvi output -> convert dvi to ps -> ps to png using ImageMagick.

### Tex filter

TeXfilter is similar to DruTeX in that it requires a LaTeX installation on your server and therefore brings similar advantages and disadvantages. It is a simpler module than DruTeX.

### Wysiwyg ASCII Math

Wysiwyg ASCII Math is a Wysiwyg editor plugin that adds ASCII and TeX entry of math/formulas and plots/graphs entered in ASCII/TeX.

It allows for Client-side conversion of ASCII & TeX equations into nicely typeset formulas and falls back to Server-side generation of images (using mimetex.cgi) for browsers that don't support MathML.

## Web services

### For websites doing non-heavy mathematics

If your website is doing only a few lines of mathematical equations, you can use my server to run the Latex code. This offer is not for websites doing heavy mathematics; I will ban any site that may significantly eat-up my bandwidth.

To post math equations in your page, simply type the following code:

<img src="http://www.mathalino.com/cgi-bin/mimetex.cgi?\int\frac{du}{\sqrt{a^2-u^2}}=\arcsin\frac{u}{a}+C" >

Replace your latex code with the actual latex code. The http://www.mathalino.com/cgi-bin/mimetex.cgi? must be written to call my server and for my server to generate the image and send it to your page.