# Mathematica

(Excerpt from "The MathML Handbook" by Pavi Sandhu)

*Mathematica* is best known as a powerful application for doing mathematical computations. However, in addition to its computational abilities, *Mathematica* provides a rich WYSIWYG environment for authoring technical documents. Using MathML for computations: Mathematica discusses *Mathematica*'s computational abilities in the context of MathML. In this section, we focus on *Mathematica*'s notebook interface and how you can use it as an environment for authoring MathML content.

## The Notebook interface

*Mathematica* consists of two separate applications: the front end, which provides the user interface for creating and editing documents, and the kernel, which acts as the computational engine. The front end provides the standard word-processing features such as formatting, outlining, spell checking, and stylesheets. It also includes a sophisticated mathematical typesetting system that allows you to create complex mathematical notation quickly and easily, using palettes, menu commands, or keyboard shortcuts. The front end automatically handles the details of adjusting spacing, font size and style, linebreaking, and other properties according to the normal conventions of mathematical typesetting. But you can also control these properties explicitly using the large number of options provided.

** Mathematica documents are called notebooks**. Notebooks can contain text, typeset equations, graphics, and programs as well as active elements such as buttons and hyperlinks. When you start

*Mathematica*, a blank notebook appears on the screen along with some palettes for entering input. Each notebook consists of a series of cells, indicated by brackets on the right. Cells are a generalization of paragraphs and in addition to text can contain equations, graphics, or commands for evaluation. Each cell has a specific style, such as Text, Input, Output, Graphics, Section, or Subsection, which determines the default properties of its contents. You can create a cell of a specific style using the Format → Style menu.

## Authoring mathematical formulas

You can enter mathematical notation in a notebook in three ways: using palettes, menu commands, or keyboard shortcuts. For somebody new to *Mathematica*, palettes are the most convenient method since they are easy to use. However, for experienced users, the menu and keyboard shortcuts provide a much faster and more efficient way of entering equations.

### Palettes

When you first launch *Mathematica*, the Basic Input palette appears on the left of the screen (see the following figure). This contains buttons for about two dozen commonly used symbols and equation templates. Clicking a button on the palette causes the corresponding symbol or template to be pasted into your notebook at the position of the cursor. You can quickly construct the desired equation by combining templates and symbols and then filling in the placeholders by typing text from the keyboard.

*Figure: The Mathematica front end, which shows a notebook and some palettes for entering mathematical notation and special characters.*

In addition to the Basic Input palette, you can access the Basic Typesetting, Complete Characters, and International Characters palettes using the File → Palette menu. The Complete Characters palette has a much wider selection of technical symbols and other special characters than the Basic Input palette. The characters are arranged into groups, such as Letters, Letter-like Symbols, and Operators. Each group is further divided into subgroups, such as Shapes and Icons, Textual Forms, and Keyboard Characters. You can click the triangle to the left of any group or sub-group to display or hide its contents.

### Menus and keyboard shortcuts

The Edit → Expression Input menu (see the next figure) contains commands for creating common mathematical constructs, such as subscripts, superscripts, fractions, and radicals. Each of these menu commands has a corresponding keyboard shortcut. For example, on Windows, you would press Ctrl+6 to create a subscript or Ctrl+/ to create a fraction. If you use one of the keyboard shortcuts for entering a mathematical expression while in a text cell, *Mathematica* automatically places the equation in an inline cell for better integration with the surrounding text.

*Figure: The Edit → Expression Input menu.*

The keyboard shortcuts are optimized so it is possible to enter complicated equations using only a small number of keystrokes. Using these shortcuts, you can enter equations entirely from the keyboard, as you would, for example, in a text-based markup language such as TeX or LaTeX. However, unlike in TeX or LaTeX, the equations are immediately displayed in properly formatted two-dimensional notation.

### Entering special characters

*Mathematica* includes its own set of fonts for over five hundred mathematical symbols and other special characters. There are three different ways of entering each extended character:

- Using a palette: the Basic Input, Basic Typesetting, Complete Characters, and International Characters palettes have a broad selection of special characters.
- Typing the full name of the character: each extended character has a name (for example, Alpha for alpha and Integral for the integral symbol). For any extended character, you can type \[
*name*] to enter it into the notebook. So, for example, you can type \[Alpha] to enter the α character, or \[Integral] for the integral symbol, ∫. - Using a keyboard alias: to enter any character, you type the Escape key (Esc) followed by a short name of the character and then the Escape key again. So, for example, you can type Esc-a-Esc to enter the a character, or Esc-int-Esc for the integral symbol. The short names for most characters are the same as the names used in TeX.

## Exporting and importing MathML

Once you have used the techniques described so far in this chapter to author formulas, you can then convert the formulas into MathML for display on the Web. There are several ways to export mathematical formulas from a notebook as MathML.

To export a specific formula as MathML, select the formula and then choose the Edit → Copy As → MathML menu command (see the following figure). This copies the selected expression into the clipboard in the form of MathML presentation markup. You can then paste the markup into another application.

*Figure: The Edit menu showing the Copy As → MathML command.*

You can also export an entire notebook as HTML with MathML included. To do this, open the notebook and choose the File → Save As Special → XML (XHTML+MathML) menu command (see the following figure). This produces a well-formed and valid XHTML version of the notebook with all mathematical formulas in the notebook automatically converted into MathML. The resulting document can then be displayed in any suitably configured Web browser, including *Mozilla* or *IE* with *MathPlayer*. Note that you should save the file with a .xml extension for it to be viewable in the widest range of browsers.

*Figure: The File → Save As Special submenu showing the commands for saving notebooks in HTML or XML format with embedded MathML.*

*Mathematica* automatically inserts a reference to the Universal MathML stylesheet into the XHTML+MathML document. A local copy of this stylesheet is placed in a folder called HTMLFiles in the same directory as the XHTML+MathML file. This overcomes the limitation of *IE* not being able to use XSLT stylesheets from a remote location (see The Universal MathML stylesheet for details).

*Mathematica* 4.2 also introduces an option for saving notebooks in an XML format called * NotebookML*. This allows notebooks to be saved as well-formed and valid XML documents so they can be used as part of an XML-based production process. Files in other XML formats, such as XHTML or DocBook, can also be imported into

*Mathematica*as notebooks if you first transform them to NotebookML. To save a notebook in NotebookML format, simply choose the File → Save As Special → XML (NotebookML) menu command. You can also specify that all mathematical formulas in the notebook be embedded in the NotebookML document in MathML format by choosing File → Save As Special → XML (NotebookML+MathML).

You can also copy and paste MathML content from another application directly into a notebook. When you paste a valid MathML expression into a notebook, *Mathematica* brings up a dialog asking if you want to paste the literal markup or interpret it. If you choose to interpret the markup, it is pasted into the notebook as mathematical notation.

<< back | next >> |

**Copyright © CHARLES RIVER MEDIA, INC., Massachusetts (USA) 2003**

Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "The MathML Handbook" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

CHARLES RIVER MEDIA, INC., 20 Downer Avenue, Suite 3, Hingham, Massachusetts 02043, United States of America