This is documentation for an earlier version of webMathematica.
View current User Guide (Version 3.3)

Documentation6. Advanced Topics


6.3 Evaluation Formatting

The output of an msp:evaluate tag is inserted into the page that is returned as part of the web request. This section will describe the different types of formatting output. This topic is related to the placement of Mathematica commands into webMathematica pages and more information is found in the Appendix: <msp:evaluate>.

Automatic Formatting

Any result that is computed by an msp:evaluate tag that is not a string will be formatted into a string which will use the necessary HTML escapes. An example is shown below.


This type of formatting is equivalent to MSPFormat with a format type of OutputForm. The reference section has more information on MSPFormat.


Different styles of formatting output can be generated with MSPFormat. The example below uses MSPFormat with a format type of TraditionalForm.

   MSPFormat[ Sqrt[ Sin[x]], TraditionalForm]

Output can be generated formatted into HTML, MathML, and images. The latter giving a convenient way to show typeset mathematics. The reference section has more information on MSPFormat.

String Formatting

If the result of msp:evaluate is a string it is left unmodified and added to the output page. This is often useful for constructing HTML as shown in the example below.

   StringJoin[ "<b>", ToString[ x], "</b>"]

If you have a string and you want it to be formatted with HTML escapes, then you can wrap it in MSPFormat.

Graphics and Image Formatting

There are several convenient functions for formatting graphics objects so that a picture appears in the output. The example below displays a plot.

   MSPShow[ Plot[Sin[x], {x, 0, 2Pi}]]

The reference section has more information on MSPShow.

Suppressing Output

Sometimes you want to use the msp:evaluate tag to evaluate something, but you do not want to leave anything in the resulting page. This can be done by adding a semi-colon ';' after the computation as shown below.

   Needs[ "MyPackage"];

Adding a semi-colon causes the Mathematica symbol Null to be returned, and this is formatted to leave no trace in the output.

Output is suppressed whatever the computation, whether it uses one of the formatting functions, a graphics function, or a function that returns Print or Message output. In the following example, no output will be seen from the message output function because it is followed by a semi-colon.


Multiple Calculations

If you wish to calculate more than one result in an msp:evaluate tag the different steps must be separated with a semi-colon ';'. The result of the last computation will be formatted and appear in the output page. In the example below, the numerical result of x+y computation will appear.

   x = Sin[5.6];
   y = Sqrt[x];

If you wish to suppress the result of the last computation you can use a semi-colon ';' as described in the section on Suppressing Output.