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 one can use MathML, for graphics one can use SVG, and an 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&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 Mathematica Function Reference section, especially under MSPFormat, MSPShow, and MSPShowAnimation.
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
There are various MSP functions that return images: MSPShow, MSPShowAnimation, and MSPExportImage; in addition MSPFormat may return an image. The workings of these commands are detailed in the Mathematica Function Reference section. It should be noted that these all work by returning a string that contains the necessary img tag to reference the image file which is stored on the server. An example is shown below.
<msp:evaluate> MSPShow[ graphics] </msp:evaluate>
Therefore, if the MSP function is followed by a semi-colon ';', as shown below, this will suppress the output. The use of a semi-colon to suppress output is discussed in the section on Evaluation Formatting.