MSPFormat
MSPFormat[expr]
format expr in the format style $MSPFormatType
MSPFormat[expr, fmt]
format expr in the format style fmt
MSPFormat[expr, fmt, type]
format expr in the format style fmt, using type as the content type
Details
- MSPFormat is the key function for formatting results from Mathematica.
- The formatted result can appear in the different format types that Mathematica provides for output such as OutputForm, InputForm, StandardForm, TraditionalForm, and MathMLForm.
- The result can be returned as HTML, an image format, or as MathML.
- The second argument of MSPFormat is a symbol that selects the Mathematica format type, and the third argument is a string that sets the actual content type of the result.
- The result is correctly escaped to be valid HTML that will work in a web page.
- Note that the result must be displayed in a fixed-width font for correct alignment of multiline output.
- An alternative way to format expressions into HTML is provided by the HTML functions.
Examples
Basic Examples (1)
You can simulate how the function works by installing and loading the package.
The following demonstrates formatting output into HTML using the format OutputForm; it is formatted to a page width set by the variable $PageWidth.
An alternative to formatting into text is to format into an image; this is done for StandardForm and TraditionalForm, creating an image file and saving it on the server. An img tag, which can be used to retrieve the image, is then returned as the result.
By default, the images are in GIF format. This can be changed by specifying the format as a third argument. Here the image is stored in JPEG format.
It is also possible, though rather strange, to get a text-based format type (for example OutputForm) rendered into an image.
The width that is used for typeset images is set by the variable $TypesetImageWidth.
An alternative way to generate images is with the function MSPExportImage. For information on image generation, see the section Displaying Mathematics and Graphics.
If the format is set to MathMLForm, the system will format the expression into MathML.
In addition, you can specify a content type of RawMathML. This can be useful to get the MathML for the StandardForm rendering of an expression. This output is raw in the sense that it does not use any reference to a plug-in, applet, or special browser that would be necessary to activate the MathML.
More information on working with MathML is provided in the section MathML.