12.4 IBM techexplorer

 < Day Day Up > 



12.4 IBM techexplorer

IBM techexplorer is designed to be a general purpose rendering application for scientific documents that can interpret and display TeX and LaTeX markup as well as MathML. As discussed in Section 7.4, the markup to be rendered by techexplorer is inserted into an HTML document using either an embed tag (for Netscape) or object tag (for IE). A better solution is to place the embed tag inside the object tag,. This ensures that the markup can be rendered in both Netscape and IE. Here is an example:

     <object name="techexplorer"    class    width=200 height=100>    <param name="DataType" value="1">    <param name="Data" value= string >        <embed name="techexplorer"        type="application/x-techexplorer"        mmldata=string        width=200 height=100>      </embed>    </object> 

techexplorer also provides support for interactivity in two ways. You can directly author a number of equation actions (such as toggling between two displays or creating links) using built-in techexplorer commands. In addition, you can use the built-in class libraries and API functions in conjunction with JavaScript or Java programs to interactively control techexplorer in response to user input. We shall see some examples of both types of interactivity in this section.

Actions in techexplorer

techexplorer supports a number of special commands that you can insert into a document to implement specific features, such as creating hyperlinks, opening pop-up windows or menus, and toggling between two different expressions. The name and syntax of techexplorer commands are modeled on those of LaTeX. Most commands take the form \commandname{arg1}..{argn}. The name of the command is preceded by a slash(\) and followed by one or more arguments, each of which is enclosed in curly brackets.

Here are some of the important techexplorer commands for implementing actions:

  • \doclink{url}{expression}: creates a hyperlink to the URL specified by url. Here, expression specifies the content to be rendered by techexplorer.

  • \doclink{url}{label}{expression}: links to the specified URL and causes the window to scroll to the position indicated by label. If the label is not found, the window is positioned at the top of the document.

  • \labellink{label}{expression}: creates a hyperlink to another part of the same document.

  • \labellink{label}: defines the target of the links defined by \doclink{url}{label}{expression} and \labellink{label}{expression}.

  • \popuplink{popupText}{caption}{expression}: causes a pop-up window to appear with popupText displayed in the window and caption in its title bar. This feature is useful for adding footnotes in a document.

  • \altlink{expression1}{expression2}: toggles between the display of expression1 and expression2 each time a user clicks the displayed expression.

These commands can be freely interspersed with the markup to be rendered by techexplorer. However, most of these commands do not work with MathML markup. If you want to implement equation actions using these commands, you must encode all mathematical expressions in LaTeX format.

Scripting techexplorer

The Professional version of techexplorer contains a set of APIs. These consist of several class libraries with functions that JavaScript and Java programs can access to control techexplorer and implement interactive behavior. Table 12.4 shows a selected list of the API functions that techexplorer makes available to external programs.

Table 12.4: API Functions That techexplorer Makes Available to External Programs

Method

Description

getMMLString()

Returns the MathML data displayed in the techexplorer window

reloadFromMMLString( String mmlSource)

Replaces the document with the supplied MathML source

getWidthFromMMLString( String mmlSource)

Returns the width of a MathML expression

getHeightFromMMLString( String mmlSource)

Returns the height of a MathML expression

getDepthFromMMLString( String mmlSource)

Returns the depth of a MathML expression

convertMMLtoTeX()

Converts the document from MathML source to TeX

convertTeXtoMML()

Converts the document from TeX source to MathML

Example 12.9 illustrates the use of the techexplorer API functions to implement interactive behavior in a Web page. It shows an HTML document that contains a text area and a button. A user can enter a MathML expression in the text area and then click the button to render the MathML using techexplorer.

Example 12.9: An HTML document for rendering MathML expressions using techexplorer.

start example
    <html>      <head>        <title>IBM techexplorer</title>        <script language="JavaScript">          function displayMML( ) {          var expr = document.MMLForm.MMLString.value          document.te.reloadFromMMLString(expr);          document.MMLForm.MMLString.value=          document.te.getMMLString();        }        </script>        </head>        <body bgcolor="white">      <h1>techexplorer scripting example</h1>      <p>Enter MathML string:        <p><form name="MMLForm">          <textarea name="MMLString" ROWS=10         COLS=30></textarea>           </form>             <p><input type="button" name="MMLSend"              value="Display in techexplorer"                            onClick="displayMML()">      <p><object name="te"      class      width=500 height=80>          <param name="DataType" value="0">          <param name="Data" value="Equation will be            displayed here.">              <embed name="te"                type="application/x-techexplorer"                mmldata="Equation will be displayed here"                width=400 height=100>              </embed>            </object>      <body>    </html> 
end example

The HTML document of Example 12.9 has the following features. The "Display in techexplorer" button calls the JavaScript function displayMML. This function reads the MathML expression entered by the user and passes it as the argument of the reloadFromMMLString function. This function causes the techexplorer window in the Web page to be redrawn so that the MathML markup entered by the user is rendered in the page (Figure 12.14). Example 12.9 is the techexplorer equivalent of Example 12.3, which also renders a MathML expression but using the WebEQ Viewer Control. The reloadfromMMLString function in techexplorer is analogous to the setEquation function in the WebEQ Viewer Control.

click to expand
Figure 12.14: Viewing the techexplorer rendering of an arbitrary MathML expression.

One of the useful features of techexplorer is that it can interpret and render LaTeX markup in addition to MathML. The techexplorer API includes functions for converting between LaTeX and MathML. Thus, you can easily modify Example 12.9 to set up a Web page that allows users to type in the LaTeX markup for a formula and convert it to MathML, or the other way around. For example, LaTeX users who want to convert existing equations in their documents into MathML for posting on the Web can use this type of tool. Example 12.10 shows an HTML document that implements this type of conversion.

Example 12.10: An HTML document for converting between MathML and LaTeX.

start example
    <html>    <head>      <title>IBM techexplorer</title>      <script language="javascript">        function submitMML( ) {          document.te.reloadFromMMLString(          document.MMLForm.MMLString.value);          document.MMLForm.MMLString.value=          document.te.getMMLString()          document.TeXForm.TeXString.value=          document.te.convertMMLtoTeX()         }        function submitTeX( ) {          document.te.reloadFromTeXString(          document.TeXForm.TeXString.value);          document.TeXForm.TeXString.value=          document.te.getTeXString()          document.MMLForm.MMLString.value=          document.te.convertTeXtoMML()        }      </script>    </head>    <body bgcolor="white">      <h1>techexplorer scripting example</h1>      <table><tr><td>Enter MathML string:</td>      <td>Enter LaTeX string:</td></tr>      <tr><td><form name="MMLForm">        <textarea name="MMLString" rows=10 cols=30>        </textarea>      </form></td>      <td><form name="TeXForm">      <textarea name="TeXString" rows=10 cols=30>      </textarea>      </form></td></tr>      <tr><td>        <form><input type="button" name="MMLSend"          value="Convert to LaTeX" onclick="submitMML()">          </form></td>          <td><form><input type="button" name="TeXSend"          value="Convert to MathML" onclick="submitTeX()">          </form></td></tr></table>        <object name="te" class>          <param name="AutoSize" value="true">          <param name="DataType" value="1">          <param name="Data"           value="<math><mrow></mrow></math>">           <embed name="te"               type="application/x-techexplorer"               mmldata="<math><mrow></mrow></math>"              width=200 height=100>           </embed>        </object>      </body>    </html> 
end example

The document in Example 12.10 contains two text areas, two buttons, and a techexplorer window. One of the text areas is for entering MathML markup, and the other is for entering LaTeX markup. Below each text area is a button for converting the markup contained in that text area from one format to the other. For example, suppose you type in a LaTeX expression in the text area with the name TeXString and then click the button marked "Convert to MathML". This calls the JavaScript function submitTeX, which uses the convertTeXtoMML function to translate the LaTeX markup into MathML. The resulting MathML expression is then displayed in the MathML text area, and the equation is rendered in the techexplorer window as well (Figure 12.15).

click to expand
Figure 12.15: Converting between MathML and LaTeX encodings of a formula using techexplorer.



 < Day Day Up > 



The MathML Handbook
The MathML Handbook (Charles River Media Internet & Web Design)
ISBN: 1584502495
EAN: 2147483647
Year: 2003
Pages: 127
Authors: Pavi Sandhu

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net