MSPFormat

MSPFormat[expr]
format expr in the format style $MSPFormatType


format expr in the format style fmt


format expr in the format style fmt, using type as the content type

DetailsDetails

  • 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.

ExamplesExamplesopen allclose all

Basic Examples  (1)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.

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

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.

In[3]:=
Click for copyable input
Out[3]=

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.

In[4]:=
Click for copyable input
Out[4]=

It is also possible, though rather strange, to get a text-based format type (for example OutputForm) rendered into an image.

In[5]:=
Click for copyable input
Out[5]=

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[6]:=
Click for copyable input
In[7]:=
Click for copyable input
Out[7]=

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.

In[8]:=
Click for copyable input
Out[8]=

More information on working with MathML is provided in the section MathML.