Displaying Mathematics and Graphics

In order to display typeset mathematics and graphics, the server can generate images. These provide a simple way to view the results of computations. However, they suffer from the serious defect that they cannot be used by the client. They cannot be resized, drawn with different fonts, or viewed in some alternative way. It is also hard for a computer program to extract any meaning from an image. Alternatives to images exist. In the case of mathematics you can use MathML, for graphics you can use SVG, and the LiveGraphics3D applet can be deployed for three-dimensional graphics. These alternatives are not always the appropriate solution and, for this reason, functions for generating images are provided.

When a Mathematica kernel generates an image, it is stored in a file on the server and adds a reference in the HTML file that is returned. For example, the following img element may be generated.

<img src="/webMathematica/MSP?MSPStoreID=MSPStore1042942578_0&amp;MSPStoreType=image/gif" alt="Created by webMathematica"/>

The src attribute references the MSP servlet through a URL, which includes a parameter that gives the name of the file. The MSP servlet returns the contents of the file and periodically deletes old image files. The actual location in which image files are saved is a workspace directory provided by the servlet container.

More information about generating images can be found in the function pages for MSPFormat and MSPShow.

An alternative way to generate images is to use the Mathematica command Export, available for use with the function MSPExportImage. This provides more features, such as transparent backgrounds, but takes longer to generate. MSPExportImage always makes use of the Mathematica front end.

MSP Functions Returning Images

MSPShow is an MSP function that returns an image; in addition MSPFormat may return an image. It should be noted that these work by returning a string that contains the necessary img tag to reference the image file that is stored on the server. An example is shown below.

Therefore, if the MSP function is followed by a semicolon ';', as shown below, the output is suppressed. The use of a semicolon to suppress output is discussed in Evaluation Formatting.

Another use of these functions is to embed their results into some other formatting function such as those in the HTML Package. The example below will return an HTML table with two images.


The LiveGraphics3D applet displays Mathematica three-dimensional graphics and provides support for features such as interactive rotation and resizing. A simple example that shows how to use MSPLive3D to embed a three-dimensional graphics object into a web page follows.

A bigger example that shows more of the applet is discussed in Live 3D Plotting: Plot3DLive.jsp. Reference information is found in the appendix LiveGraphics3D.

New to Mathematica? Find your learning path »
Have a question? Ask support »