Advanced Editing Application Examples

This section illustrates complete application examples that provide you with use cases for different ways that the Zed editor could be included as a component of larger mathematical solutions.


Reading the Zed Users Guide in Internet Explorer
Writing Mathematical Documents using Word
Solving the Quadratic Equation in PowerPoint
Basic Symbolic Computing with Mathematica

The advanced features of the component edition of Zed allow a high degree of customization, using the configuration customization framework, and support a collection of custom properties, methods and events through the Zed Custom API. These advanced features allow an application developer to incorporate Zed into a wide variety of mathematical solutions involving other mathematical components, where each application can customize the behavior of the editor to meet the needs of the application, and can communicate mathematical expressions from the editor to other components of the application using the Zed Custom API. The methods in the API can also be used to produce dynamic effects that involve symbolic mathematical expressions, and that can be coordinated with other numeric and/or graphical illustrations.

The following paragraphs illustrate the use of the component within a variety of different containers, detail how to embed the component in the containers, describe how to access features of the component from the containers and show how the different components come together to present the larger application examples.


Reading the Zed Users Guide in Internet Explorer

The Internet Explorer web browser from Microsoft can be used as a container for ActiveX controls such as the component edition of Zed. Support for ActiveX controls was introduced in Internet Explorer 3.0, and they are supported (to some extent) in other web browsers through the use of third-party plugins. The Zed component brings to the web browser the ability to enter mathematical expressions directly in the browser, thereby enabling the user to interact with symbolic computations as part of more interesting mathematical applications.

By way of introducing the types of applications that one can create in the web browser using Zed, consider this Users Guide. One common limitation of the documentation for a program is that one reads the documentation using a program that is separate from the program itself. Using methods from the Zed Custom API, this Users Guide integrates, within the browser, both the reading of the documentation and user exploration of the features of the editor. Various sections from the Basic Use part of the Users Guide include hyperlinks in the text that activate a separate frame, containing an instance of the Zed component, where you can try out the editing techniques described in the text. The MathML Reference section contains dozens of MathML examples, associated with each of the content elements of MathML, so that by clicking on the example link, you can experiment with the operations that allow you to create each of the elements and attributes available in the editor. Other sections in this Users Guide can contain links and include mathematical information as needed to illustrate certain concepts. Creating the documentation in this fashion provides a concrete starting point for much more complex applications that can be developed using the API.

Embedding an instance of the Zed component is typically done through the use of the HTML <object> element. You will typically want to give the element an id attribute for later reference, supply the desired width and height of the displayed area, and supply initial values for each property you need to use for your application. The following code demonstrates each of these tasks, and also contains the class id attribute that is needed to identify the Zed component:


<object id="zedit" width="100%" height="100%"
        classid="CLSID:8D917303-E449-465A-B882-90EFB15B8492">
</object>

For this Users Guide, since the goal was to have the Zed component available on demand, but not initially displayed, a somewhat different approach is used. The index page for the Users Guide (the file Doc/Users/index.html) is essentially just a frameset that defines a navigation frame with links to each section, a frame for the main viewing area, and a frame for the Zed examples. This last frame is initially given zero height, making it initially invisible.


<html>
<head>
  <link type="text/css" rel="stylesheet"
    href="Style/Sections.css">
  <script type="text/javascript" src="Script/example.js">
  </script>
  <title>Zed Users Guide</title>
</head>
<frameset name="left" cols="180,*">
  <frame name="toc" src="Contents.html">
  <frameset name="right" rows="*,0">
    <frame name="main" src="Cover.html">
    <frame name="zed" src="ZedEdit.html">
  </frameset>
...

Initially, this third frame is loaded with an essentially empty document, which you can find as the file Doc/Users/ZedEdit.html. While the <body> of this file is empty, the <head> contains the same declarations as shown above, including one that loads a few JavaScript methods contained in the file Doc/Users/Script/example.js. The function exopen does most of the work, by clearing the frame document, and creating new markup for the page that includes the <object> element described earlier. It also installs an event handler for the Zed Submit event, so that you can close the window by pressing the Enter key.


function exopen( name )
{
  ...

  if ( parent.right )
    parent.right.rows = "*,120";

  doc.clear();
  doc.writeln(
    '<object id="zedit" width="100%" height="100%" \
       classid="CLSID:8D917303-E449-465A-B882-90EFB15B8492"> \
     </object>' );
  doc.writeln(
    '<script language="JavaScript" for="zedit" event="submit()"> \
     parent.main.exclose();</script>' );
  doc.close();

  doc.zedit.MmlSource = name;
}

The exopen function takes as its argument the name of the MathML example file to be opened. Using this function, the HTML markup used to create the example links can be kept to a minimum:


<a href="javascript:exopen('quadratic')">quadratic.mml</a>

Example: quadratic.mml

While you can see the results of this example many other places in this Users Guide, the above example link gives you an opportunity to explore a bit more of the structure of how these examples are constructed, as a starting point for creating your own applications.


Writing Mathematical Documents using Word

The Word software from Microsoft for developing formatted text documents can be used as a container for ActiveX controls such as the component edition of Zed. While support for ActiveX controls in Word has been around for some time, there are some differences in using components in Word that affect the use of Zed in such documents. Basic use of the Zed component allows an author to include mathematical expressions in the same way as other text in a seamless fashion. More advanced features available in Word such as VBScript can also be used to create more dynamic effects such as can be implemented by using Zed in a web browser.

To demonstrate how to use Zed in Word, consider writing a document to explain the solution to the quadratic equation, showing each step in the solution process from start to finish. Such a document could appear as a section in an introductory algebra textbook, and requires the ability to enter both displayed equations as well as expressions included inline in the text. Using the component edition of Zed in this fashion makes it much easier to incorporate the mathematical information involved.

Embedding an instance of the Zed component in Word can be done in a few easy steps. First, bring up the Control Toolbox by selecting the menu item View→Toolbars→Control Toolbox. Then click on the More Controls button in the bottom right corner and you will see a list of all of the ActiveX controls installed on your system. Scroll down and select the entry for the Integre MathML Equation Editor component:

When you select the Zed component, it is assigned a default size and position in the current document, and you should see eight resize boxes indicating the size of the embedded component. These resize boxes also allow you to resize or reposition the component as you like. Other features in Word can also be used to affect the position of the component with respect to other text on the page; see the documentation for Word for details.

Once you've embedded the component in a page, you can access the Zed property pages by right-clicking within the area set aside for the component, and then selecting Integre MathML Equation Editor→Properties. This selection brings up the Zed-specific property pages, described in the Property Pages section of the Scripting reference. These property pages can be used to set the initial values for each property that is available as part of the Zed Custom API. As an example, on the Source property page you will find a drop-down choice box allowing you to enter the MathML content for the initial expression to display in the editor. Enter the desired markup in the dialog box, and press the Set button to set the value of the property.

Word provides one more feature for handling embedded ActiveX controls that is useful for embedding Zed. When a component is embedded in Word, it initially appears in design mode, allowing you to size the component, access its property page, and so on. By clicking on the button in the upper-left corner of the Control Toolbox, you can exit design mode and enter run mode, allowing you to interact with the editor as you would inside other containers. Clicking on this button again allows you to switch back and forth between design mode and run mode as often as needed.

One resource that is often useful when preparing documents of this sort is the ability to increase the font size. The MathML standard attributes for controlling the font size (mathsize in MathML 2.0, and fontsize in earlier versions) are available in Zed and can be added to the content markup by enclosing the appropriate elements in an <mstyle> element. Zed preserves such presentation markup unchanged when it finds it embedded in the content markup for an expression.

The file Other/quadratic.doc is the result of applying these steps to create the document for the entire explanation. While creating this type of material requires having Word on your machine, you can still get an idea of how this example works using the Word viewer download available from Microsoft.


Solving the Quadratic Equation in PowerPoint

The PowerPoint software from Microsoft for developing slide shows can be used as a container for ActiveX controls such as the component edition of Zed. While support for ActiveX controls in PowerPoint has been around for some time, there are some differences in using components in PowerPoint that affect the use of Zed in such slides. Basic use of the Zed component allows an author to present mathematical expressions in the same way as other lesson material in a seamless fashion. More advanced features available in PowerPoint such as VBScript can also be used to create more dynamic effects such as can be implemented by using Zed in a web browser.

To demonstrate how to use Zed in PowerPoint, we once again consider the solution to the quadratic equation, but this time adopt the goal of showing each step in the solution process from start to finish, while providing explanatory text to lead a student through the derivation. This type of exposition is quite common in technical courses, but is difficult to support with standard tools for creating slide shows. Using the component edition of Zed in this fashion makes it much easier to incorporate the mathematical information involved.

Embedding an instance of the Zed component in PowerPoint can be done in a few easy steps. First, bring up the Control Toolbox by selecting the menu item View→Toolbars→Control Toolbox. Then click on the More Controls button in the bottom right corner and you will see a list of all of the ActiveX controls installed on your system. Scroll down and select the entry for the Integre MathML Equation Editor component:

When you select the Zed component you can drag out a region on the current slide where the component will be positioned. If you want to resize or reposition it later, there are several ways to do so. When you complete the drag operation, you should see eight resize boxes indicating the size of the embedded component.

Once you've embedded the component in a page, you can access the Zed property pages by right-clicking within the area set aside for the component, and then selecting Integre MathML Equation Editor→Properties. This selection brings up the Zed-specific property pages, described in the Property Pages section of the Scripting reference. These property pages can be used to set the initial values for each property that is available as part of the Zed Custom API. As an example, on the Source property page you will find a drop-down choice box allowing you to enter the MathML content for the initial expression to display in the editor. Enter the desired markup in the dialog box, and press the Set button to set the value of the property.

In PowerPoint, when you are editing your slides, any components on the slides are automatically in design mode. When you run the slide show, the components are automatically in run mode. PowerPoint does not provide any explicit means of switching back and forth between these modes, other than running the slide show.

One resource that is often useful when preparing slides of this sort is the ability to increase the font size. The MathML standard attributes for controlling the font size (mathsize in MathML 2.0, and fontsize in earlier versions) are available in Zed and can be added to the content markup by enclosing the appropriate elements in an <mstyle> element. Zed preserves such presentation markup unchanged when it finds it embedded in the content markup for an expression.

The file Other/quadratic.ppt is the result of applying these steps to create the slides for the entire derivation. While creating this type of material requires having PowerPoint on your machine, you can still get an idea of how this example works using the PowerPoint viewer download available from Microsoft.


Basic Symbolic Computing with Mathematica

The Mathematica computer algebra system developed by Wolfram Research is an extensive application for performing a wide range of symbolic computations for scientific computing. While Mathematica itself is not intended to be a container for ActiveX controls in the same way as Internet Explorer or PowerPoint, the Mathematica kernel can be used as a separate component through the use of the techexplorer addin for Mathematica. By embedding both the Mathematica kernel (via techexplorer) and the Zed component in the same HTML page, the two components can communicate by way of JavaScript functions to create mathematical applications for the web that support both a rich computational behavior and a compelling visual user interface.

To demonstrate how the Zed component can be used to communicate with a Mathematica kernel, consider the problem of providing a simple command-line user interface to a computer algebra system, but one that can be used from within a web browser. A command-line user interfaces for a computer algebra system typically supplies a linear input syntax for expressions, using a specialized syntax. The system reads user input, one expression at a time, evaluates each expression to produce a result, and outputs the result before asking for the next input expression. This behavior can be implemented in a web browser by embedding two instances of the Zed component, one for input, and another for output. An invisible techexplorer component is also present in the page, to provide access to the Mathematica kernel. The resulting web page provides two-dimensional expression input that communicates with the kernel through the standard MathML syntax.

The HTML code required to embed the two instances of the Zed component is similar to that shown in the previous examples. The input component is assigned the attribute id="In", and the output component is assigned the attribute id="Out". JavaScript event handlers are provided to handle the Onload and Submit events generated by these two components. Note that the input component is also set up to grab the focus.


<object id="In" width="100%" height="50"
    classid="CLSID:8D917303-E449-465A-B882-90EFB15B8492">
  <param name="GrabFocus" value="true">
</object>

<script language="JavaScript" for="In" event="onload()">
  z1 = true;
</script>

<script language="JavaScript" for="In" event="submit()">
  if ( z1 && z2 )
    CallMathKernel();
</script>

<object id="Out" width="100%" height="50"
    classid="CLSID:8D917303-E449-465A-B882-90EFB15B8492">
  <param name="GrabFocus" value="false">
</object>

<script language="JavaScript" for="Out" event="onload()">
  z2 = true;
</script>

Embedding the Mathematica kernel is accomplished by embedding the techexplorer component, as described in the techexplorer documentation. The component can be included in the <head> of the document, where it will remain invisible. Notice the classid attribute value appropriate for techexplorer is used, rather than the classid attribute value appropriate for Zed.


<object name="te" width=3 height=3
    classid="clsid:5AFAB315-AD87-11D3-98BB-002035EFB1A4">
  <param name="AutoSize" value="true">
  <param name="DataType" value="0">
  <param name="Data" value="">
</object>

Finally, a few simple JavaScript functions are used to provide the connections between these three components:


var kmime = "application/x-mathlink-mathml-mathml";
var kernelStarted = false;
var z1 = false;
var z2 = false;

function StartMathKernel() {
  if ( ! kernelStarted ) {
    te.addInInitialize( kmime );
    kernelStarted = true;
  }
}

function StopMathKernel() {
  if ( kernelStarted ) {
    te.addInShutdown( kmime );
    kernelStarted = false;
  }
}

function CallMathKernel() {
  StartMathKernel();
  Out.MmlContent =
    te.addInBlockingEvaluate( kmime, In.MmlContent );
}

The file Doc/Users/Other/wolfram.html provides the complete HTML source for this simple example. Clicking on the above link will open the example in a separate window, and allow you to interact with Mathematica using the Zed editor as its user interface. While not intended as a replacement for the extensive Notebook user interface provided by the Mathematica front-end, this example does demonstrate how Mathematica functionality can be brought to the web using existing technology. Running this example requires having Mathematica installed locally on your machine.