webMathematica 2.0

Tom Wickham-Jones
Director of Kernel Technology
Wolfram Research

This talk will give some preview of the upcoming version: webMathematica 2.0

All examples taken from standard webMathematica 2.0 distribution

Please note that this notebook is optimized for display by Mathematica 4.2. Also that it may refer to hyperlinks that are not included in the file archive.

Initialization

Off[General::spell];
Off[General::spell1];

SetDirectory[
        DirectoryName[
          ToFileName["FileName" /. 
              NotebookInformation[ SelectedNotebook[]]]]];

History of webMathematica

Jan 2001: testing started.

Sept. 2001: release of webMathematica 1.0.

Jan. 2003: beta release of webMathematica 2.0.

XXX 2003: release of webMathematica 2.0.

webMathematica 2.0 Features

● Simplified installation

● Extended documentation and examples

● A new templating mechanism based on JSP custom tags

● Support for Mathematica Version 4.2

● MathML, SVG, and XML support

● Support for catching message and print information

● Added HTTP file uploading functions

● Added support for HTTP session variables

● Added HTML formatting functions

webMathematica 2.0

Simplified Installation

webMathematica 1.0 required a number of manual configuration steps in order to run.

Significantly reduced in webMathematica 2.0, much more able to run out of the box.

webMathematica is not consumer software, it involves servers etc... 

However, always useful to make installation easier.

Extended Documentation and Examples

Documentation available in HTML on-line from front-page. 
Also as NB and PDF formats.

All important features documented.

Extended template system, easier to use.

Helps to promote ease of use and energize to benefits.

JSP Custom Tags

Alternative HTML templating mechanism.

Easier to understand, uses standard technology which is very widely used.

Files have .jsp file extension.

<form action="Expand" method="post">
      Enter a polynomial (eg x+y): 
      <input type="text" name="expr" size="10">
      Enter a positive integer (eg 4):
      <input type="text" name="num" size="3">
      <br/>
      
      <msp:allocateKernel>
      <msp:evaluate>
             MSPBlock[{$$expr,$$num},
                     Expand[$$expr^$$num]]
      </msp:evaluate>
      </msp:allocateKernel>
                     
      <br/>
      <input type="submit" name="button" value="Evaluate">
	</form>

Very similar to Mathlet idea, everything that works in MSPs works in JSPs. 
Easy to convert.

Use of Mathematica 4.2

webMathematica 1.0 ships with Mathematica 4.1

webMathematica 2.0 will ship with Mathematica 4.2

Mathematica 4.2 many features relevant for webMathematica,  most important XML support.

Mathematica XML Support

XML becoming very popular, widely supported in browsers, other applications, and tools such as XSLT, and DTDs.

Strong support in Mathematica:  XML and Mathematica share the basic principle of structured data.

Here is a basic XML file.

!! coffee.xml

Import into Mathematica

xml=Import["coffee.xml"]

Symbolic representation in Mathematica, can be worked on with regular Mathematica techniques.

Value of XML

No need to invent a special data format, use XML.

Parsers, formatters, transformation, validators etc... all readily available in many places including Mathematica.

XML is useful for math with MathML, graphics with SVG, and web publishing with XHTML.

All immediately work well with Mathematica.

Mathematica commands, input, output many controls.
Mathematica XML dialects: MathML, SVG, also notebooks with NBML, expressions with ExpressionML, text with XHTML etc...

Many uses for webMathematica.

More information in the XML docs.

XML for webMathematica

Standard XML Formats

Especially useful: XHTML and MathML, but also SVG.

Benefit for sites where presentation is important.

XML Data

Import and export XML data with a webMathematica site.

Useful as an interchange format.

Benefit for sites that want to exchange data.

MathML

Designed to allow mathematical, scientific, and other technical information to be served, received, and processed on the World Wide Web.

Official recommendation of the World Wide Web Consortium (W3C), working group on mathematics.

Wolfram Research founding member of the mathematics working group and host of the first two official MathML conferences in 2000 and 2002.

Mathematica contains many features for working with MathML and there is a strong relationship between the Mathematica typesetting system and MathML.

Wolfram Research sponsored web site, http://www.mathmlcentral.com (uses web Mathematica).

MathML and webMathematica

Users of webMathematica can benefit from MathML in a number of ways.

1) Generate MathML dynamically on their webMathematica site.

2) Enter MathML into their web browser and send this to webMathematica for computation.

Problem with supporting MathML, all sorts of different technologies ⟹ different markup.

Solution: XSLT stylesheet that decides which solution is being used.

Now browser support for MathML good enough (makes use of general XML tools).

More discussion in http://www.wolfram.com/products/webmathematica/updates/MathML.nb.

Generating MathML from webMathematica

Page needs to be delivered as an XML page,and to reference the XSLT stylesheet.

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/webMathematica/XSL/mathml.xsl"?> 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MathML Example</title>
</head>
<body>
<msp:allocateKernel>
<msp:evaluate>
	MSPPageOptions[ "ContentType" -> "text/xml"];
	MSPFormat[ Sin[x^2], MathMLForm]
</msp:evaluate>
</msp:allocateKernel>

</body>
</html>

See example in action, http://localhost:8080/webMathematica/Examples/MathML/IntegrateForm.jsp.

Works for IE and Mozilla!  MathML flows naturally with the XHTML.

Supported Browsers

Supported in the following browser (plug-ins).

Windows:
	• Internet Explorer 6.0 with either the MathPlayer or techexplorer plug-in
	• Internet Explorer 5.5 with either the MathPlayer or techexplorer plug-in
	• Internet Explorer 5.0 with the techexplorer plug-in 
	• Netscape 7.0 
	• Netscape 6.1 with the techexplorer plug-in 
	• Amaya (Presentation MathML only) 
	• Mozilla 1.0 
Macintosh: 
	• Internet Explorer 5.0 with the techexplorer plug-in 
	• Mozilla 0.9.9 
Linux/Unix: 
	• Netscape 7.0
	• Netscape 6.1 with the techexplorer plug-in 
	• Mozilla 1.0
	• Amaya (Presentation MathML only)

Sending MathML to webMathematica

Not so many different technology solutions, one that works is WebEQ, needs a Java enable applet.

See example in action, http://localhost:8080/webMathematica/Examples/MathML/IntegrateWebEQ.jsp.

MathML really starting to come of age, supported in main-stream browsers etc...

MathML useful for education, and for applications where presentation is particularly important.

SVG

SVG is a language for describing two-dimensional graphics in XML.

Developed by a W3C working group, many Adobe applications support SVG, in addition Java and C++ support from Apache.

Mathematica 4.2 can generate SVG by conversion from graphics functions:

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

ExportString[%, "SVG"]

Can use the XML tools in Mathematica 4.2 for processing and modifying the SVG that is generated.

SVG Rendering

Variety of technologies, Apache provide a browser, and Adobe support SVG in a range of their products.

Adobe also supply a browser plug-in.

http://localhost:8080/webMathematica/Examples/SVG/Plot.jsp

Higher quality picture, can be resized, prints well, integrates with Adobe products.

File size is often much smaller than an image.

Many extra dynamic features.

Dynamic SVG

Integration with JavaScript. Integration with Java APIs. Also many animation features built-in.

http://localhost:8080/webMathematica/Examples/SVG/NDSolvePlot.jsp

Steps involve, solving ODE, plotting solution, generating symbolic XML, modifying XML to add animation, generating SVG, returning to browser.

SVG provides an interesting alternative for graphics. Especially where animation or quality is important.

Generating XML

Convenient way to send structured data from a web site. Quite simple to write for this...

<?xml version="1.0" ?>

<msp:evaluate>
	MSPSetOptions[ "ContentType" -> "text/xml"];
...
	MakeXMLPhoneList[ d_]:=
  		XMLElement[ "PhoneList",{},Map[ MakeUsers,d]];
	If[ MSPValueQ[ $$query],
		phoneData = Select[ phoneData, 
					( StringPosition[#[[1]],$$query]=!={})&]];
	ExportString[ MakeXMLPhoneList[ phoneData], "XML"]	
</msp:evaluate>

Load URL into browser...  http://localhost:8080/webMathematica/Examples/XML/Phone.jsp.

Accessing XML from webMathematica.

Can read into any XML aware application, not just a browser.

For example, a Mathematica function to call to the server.

Contact[query_String] := 
      Cases[XML`Parser`XMLGet["http://localhost:8080/webMathematica/\
Examples/XML/Phone.jsp?name=" <> query], 
        XMLElement["Person", x_List, {}] :> x, 
        Infinity]

Contact[ "Tom"]

This is a webMathematica web site connecting to Mathematica.

XML provides a convenient way to transmit structured data, it can be validated (etc...) with standard tools.

Leads into notion of web services (can run with web Mathematica but out of scope of this talk).

HTML Formatting

Convenient functions for formatting into HTML, supports tables and select.

Can use in regular Mathematica, especially useful in webMathematica.

Needs["MSP`HTML`"]

HTMLTableForm[ {{a, b}, {c, d}}]

Can set attributes, headings etc...

HTMLSelect[ {a, b, c, d}, name]

http://localhost:8080/webMathematica/Examples/HTML/RegressTable.jsp

Very convenient to have Mathematica functions for formatting in HTML.

Uploading Data

Important new feature of webMathematica 2.0.

Supported in HTML with multipart/form-data FORM

<form method=post enctype="multipart/form-data" action="UploadFileAction">
	<p>Enter a file to upload:</p>

	<input type="file" size=40 name="file">

	<input type="reset" value="Clear">
	<input type="submit" value="Submit">
</form>

Uploading Data...

Read into Mathematica with MSPGetUploadFile[], file is saved on server in temporary location.

<msp:evaluate>
	file = "FileName" /. MSPGetUploadFile[];
	Read[ file, Record, RecordSeparators-> {}] 
</msp:evaluate>

Also transmits original filename and contenttype. Also support for multiple files.

Many applications of file upload, basic HTTP feature.

Session Support

Save results in the server from one request to the next

<msp:evaluate>
	MSPSessionVariable[ storedInputs, {}];
</msp:evaluate>

...

<p>
Current inputs.
</p>
<msp:evaluate>
	If[ StringQ[ $$expr] && StringLength[ $$expr] > 0, 
			storedInputs = Append[ storedInputs, $$expr]];
	storedInputs
</msp:evaluate>

The variable storedInputs is made a session variable, and is set an initial value.

Uses HTTP sessions (same as a shopping cart). The value lives in the server not the Kernel.

Example of use, http://localhost:8080/webMathematica/Examples/Data/Session.html.

Store data on server continue to compute with it.

Many applications of session support, basic web site feature.

webMathematica 2.0 Summary

First update to webMathematica, many new features.

Just shipping in beta.

Includes Mathematica 4.2.

Beta available to all users of webMathematica (with upgrade program).

To get beta, get webMathematica.