10.3 Converting Individual Formulas

 < Day Day Up > 



10.3 Converting Individual Formulas

Now that we have reviewed the basic features of LaTeX syntax and noted some similarities and differences with MathML, let's look at specific tools for converting LaTeX formulas into MathML.

WebEQ

The WebEQ Publisher application provides a convenient way of creating Web pages that contain MathML. This application allows you to use the WebTeX language for authoring mathematical notation. WebTeX is a markup language for describing mathematics that was developed by Design Science. WebTeX markup is simple enough to author directly by hand and can be readily converted into MathML. This makes WebTeX a convenient input method for authoring MathML, especially for users who are already familiar with the LaTeX syntax for mathematical formulas.

For information on how to create an HTML+MathML file starting with a document that contains WebTeX markup, see the description of WebEQ Publisher in Section 9.3. WebEQ Publisher is a Java application that takes a source file that contains WebTeX equations and produces an HTML file with all the equations automatically converted either to Viewer Control applet tags or to MathML, depending on your preference.

The WebTeX Language

The syntax of WebTeX is almost identical to that of LaTeX. However, there are some differences. For example, in LaTeX the \sqrt command is used to indicate any type of root or radical. Hence, the cube root of x would be indicated as shown below:

    $\sqrt[3]{x+1}$ 

In WebTeX, the same expression would be written as:

    $\root{x}{3}$ 

The WebTeX expression is clearly much easier to translate into MathML since it has the same structure as the MathML mroot element.

Another area in which WebTeX commands differ from those of LaTeX is when you are entering tables and matrices. In WebTeX, as in LaTeX, matrices are entered using the \array command, as shown below:

    $\left(\array{1 & 2 \\ 3 & 4}\right$ 

However, WebTeX provides a set of options that make it easier to control various features of the array. To use these options, you must specify the command \arrayopts{} as the first argument of \array{}. The \arrayopts{} command can have as arguments one or more options, each controlling a specific property of the array.

For example, the options \colalign and \rowalign determine the alignment of columns and rows, respectively. Possible values for \colalign are left, right, and center. Possible values for \rowalign are top, bottom, center, and axis. Here is an example:

    \array{\arrayopts{\colalign{left left right}} 
    1 & x+1 & x^2+1 \\ x^2-1 & x-1 & 1} 

The option \equalrows{true} causes all rows in the array to have the same height, while \equalcolumns{true} causes all columns to have the same width. However, if either of these options is set to the default value, false, each row or column is adjusted to fit the entry with the largest height or width. The options \rowlines{} and \collines{} determine if a line is drawn between any two rows or columns, while \frame determines if a frame is drawn around the entire array. The possible values for all these options are solid, dashed, and none.

These array options in WebTeX correspond directly to attributes of the mtable, mtr, and mtd elements in MathML-namely rowalign, columnalign, rowspacing, columnspacing, rowlines, columnlines, and frame. This makes it easy to translate tables in WebTeX syntax into MathML. In contrast, specifying properties of tables in LaTeX requires more complicated commands that do not fit well with the structure of MathML.

WebTeX also includes a few commands that allow for interactivity in equations:

  • The command \href{url}{expr} can be used to turn an equation into a hyperlink. The first argument is the URL to be followed, and the second is the expression that should appear as a link.

  • The command \statusline{message}{expr} causes the text of message to be displayed in the status line of the browser when the cursor is moved over the expression expr.

  • The command \fghighlight{color}{expr} causes the expression expr to be displayed in a different color when the cursor is moved over it. The color is specified in six-digit hexadecimal notation; for example, #ff0000 for red.

  • The command \toggle{expr1}{expr2}{prompt1}{prompt2} can be used to toggle between two different expressions. Initially, expr1 is displayed in the Web page and prompt1 appears in the browser status line; however, clicking the expression using the left mouse button causes expr2 to be displayed in the browser window and prompt2 in the status line.

When you translate WebTeX markup into MathML using WebEQ Publisher, as explained in Section 9.3, these commands get converted into maction elements. They can then be displayed in browsers as WebEQ applets. For details on using maction elements in WebEQ to get interactive behavior, see Section 12.3.

WebTeX also allows you to define macros to create shorthand notation for commands that you use frequently. A macro is specified using the command

    \define{expr1}{expr2} 

where the first argument is the name of the macro and the second argument is the expression that the macro stands for.

Example 10.1 shows a simple HTML file that contains WebTeX markup.

Example 10.1: An HTML document called calculus.html that contains WebTeX equations.

start example
    <html>     <head ><title>Calculus</title></head>       <body>         <h1>Fundamental Theorems of Calculus</h1>    <p>The first fundamental theorem of calculus states that, if $f$ is continuous on the closed interval $[a,b]$ and $F$ is the antiderivative (indefinite integral) of $f$ on $[a,b]$, then </p>    <p>\[\int _{a}^{b}f(x)\DifferentialD x=F(b)-F(a)\]</p>    <p>The second fundamental theorem of calculus holds that if $f$ is a continuous function on an open interval $I$ $a$ any point in $I$, and if $F$ is defined by </p>    <p>\[\int _{a}^{b}f(x)\DifferentialD x=F(b)-F(a)\]</p>    <p>then $F(x)=f(x)$ at each point in $I$. </p>    <p>The fundamental theorem of calculus along curves states that if $f(z)$ has a continuous antiderivative $F(z)$ in a region $R$ containing a parameterized curve $\gamma: z=z(t)$ for $\alpha \leq t \leq \beta$, then</p>    <p>\[{{\int }_{\gamma }}f(z)\DifferentialD z=F(z(\beta))-F(z(\alpha))\]</p>      </body>    </html> 
end example

If you process this file using WebEQ Publisher, you get an output document in which all the WebTeX equations have been translated to MathML. You can also set an option to automatically insert a reference to the Universal MathML stylesheet. The resulting output file can then be viewed in IE.

Note that the output file may not contain well-formed XHTML, so it cannot be viewed in Mozilla. In order to view the file in Mozilla, you may have to first convert the file into XHTML using the free utility Tidy. As discussed in Section 7.3, Tidy is a C program for converting HTML files into XHTML.

Figure 10.1 shows the document produced by processing the document calculus.html in WebEQ Publisher. The resulting document contains MathML equations that can be rendered in IE using MathPlayer.

click to expand
Figure 10.1: Viewing the document produced by processing calculus.html in IE.

itex2mml

itex2mml is a freely available C program that converts mathematical formulas written in a special dialect of TeX called itex into MathML. The program was written and is maintained by Paul Gartside of the University of Pittsburgh.

itex is like WebTeX, a LaTeX-like syntax for specifying mathematical notation. itex is a superset of WebTeX; any command that you can use in WebTeX is also a valid itex command. The main difference is that itex defines some extra commands that use the natural names for some LaTeX commands. For example, in itex you can use \infinity instead of \infty to describe the symbol and \Union instead of \bigcup for the symbol.

To create a Web page that contains MathML using itex2mml, you first prepare the HTML document as you normally would and include all mathematical formulas using the itex syntax. You then process this document using the itex2mml program. This program replaces every instance of itex markup in the document into the corresponding MathML equation, leaving all other text in the document unchanged.

You can download an archive that contains the files for itex2mml from the following URL: http://pear.math.pitt.edu/mathzilla/itex2mml.html. This contains precompiled binaries for the Linux platform as well as raw C source files that can be compiled for any other platform. To convert an HTML document into an XHTML document that contains MathML, you process the document using a command like the following:

    itex2MML < input.xml > output.xml 

This reads input from a file called input.xml and writes the output to a file called output.xml. In order to view the document in Mozilla, you might need to run Tidy on the document to convert it into a well-formed XHTML document, as discussed in Section 7.3.

Since itex2mml is a C program, you can easily configure it to run on a Web server and to process input submitted to it from a Web page. This type of setup has been implemented at the following URL: http://pear.math.pitt.edu/mathzilla/itex2mmlFrag.html. This Web page contains a text area in which you can paste a sample HTML document that contains itex equations. When you click a button, the text you entered is submitted to the server, it's processed using itex2mml, and the resulting output is returned back to the Web page. You can either see the source of the resulting HTML+MathML file or display the file in the same Web page. This process is demonstrated in Figure 10.2.

click to expand
Figure 10.2: Submitting the text of an HTML file that contains itex equations for processing using itex2mml.

Alternatively, you can upload your input document and submit it to the server from the following Web page: http://pear.math.pitt.edu/mathzilla/itex2mmlFile.html. This page allows you specify a sample HTML file, which contains itex markup, located on your computer. When you click a button, the file is uploaded to the server, it's processed using itex2mml, and the resulting output is returned back to the Web page. You can either see the raw text of the resulting XHTML+MathML file in the same Web page or download the file and save it on your computer.

The Ontario Research Center for Computer Algebra (ORCCA) Converter

Another approach to converting LaTeX equations to MathML has been adopted by Stephen Watt and his colleagues at ORCCA. They have developed a Java program that takes LaTeX equations as input and translates them into presentation MathML. The translation is determined by a map file, which contains a collection of templates. Each template defines the MathML markup that corresponds to a particular type of TeX construct.

The map file is written in a specific XML syntax, for which a DTD is provided. For example, the following template replaces the opening parenthesis in a TeX expression with the <mo>(</mo> element in MathML:

    <pat:template>     <pat:tex op="("/>     <pat:mml op="(">       <mo>(</mo>     </pat:mml>    </pat:template> 

Similarly, the following template replaces the TeX command \alpha with the corresponding Unicode character:

    <pat:template>     <pat:tex op="\alpha"/>     <pat:mml op="&#x03B1;">       <mo> &#x03B1; </mo>     </pat:mml>    </pat:template> 

All the elements defined for use in the map file have the namespace prefix pat. Each template is represented by a pat:template element. The pat:tex element, via its op attribute, specifies a particular TeX command to which the template applies. The pat:mml element defines the MathML markup that corresponds to a TeX command. A user can edit the templates in the map file, for example, to specify a different set of notational preference. Details about the syntax of the map file and the various elements and attributes it can contain are given at http://www.orcca.on.ca/mathml/texmml/MapSpecWeb.html.

This conversion process is very similar to the XSLT transformations discussed in Chapter 8. The map file plays the role of the XSLT stylesheet, and the Java program that does the transformations is like an XSLT processor. The difference is, of course, that XSLT stylesheets can be applied only to well-formed XML documents, while the map file and Java program used here have been specially defined for use with TeX documents, which do not conform to XML syntax.

By specifying an appropriate map file, you can use a Java program to process LaTeX equations and translate them into the corresponding MathML. An online demo of the ORCCA converter is available at the following URL: http://www.orcca.on.ca/mathml/texmml/textomml.html. You can type in a particular equation in TeX syntax into the text area and then click a button to view the result in the same Web page (Figure 10.3). The demo page also gives you the option of uploading a TeX file from your computer and receiving the output in a separate file.

click to expand
Figure 10.3: Converting LaTeX equations into MathML using the online converter at ORCCA.



 < 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