Inserting Mathematical Expressions

This section helps you understand how to create the operators and identifiers that make up the basic structure of mathematical expressions in Zed, including the use of templates, keyboard accelerators, menu items, and palettes.


Tokens
Templates
Operators
Accelerators
Menus
Palettes

As you become familiar with how to view a mathematical expression in Zed and how to navigate from one place to another, the natural next step is learning how to create the content structures necessary to produce a desired expression. This section covers the basic techniques used to create both token elements and the elements that combine them into larger structures. These paragraphs cover the use of templates, keyboard accelerators, menus, and palettes, especially as they relate to the task of inserting new elements into an existing expression.


Tokens

Symbols
Numbers
Operators
Juxtaposition

At the most basic level, an expression is constructed as the application of operators to arguments, building up a syntax tree where each node is an operator in the expression. The leaves of the tree consist of token elements that encode the atomic symbols, numbers, and operators that appear in the expression. This subsection describes the conventions in Zed for entering token elements, to provide a foundation for building more complex expressions using the techniques to be described in the following subsections.


Symbols

A symbol is nothing more than a name that refers to something. The most basic kind of symbol is a one-character name such as a letter than denotes a mathematical variable. Symbols are encoded in content MathML using the <ci> element, and in presentation MathML using the <mi> element.

Creating a one-character symbol in Zed happens almost before you know it. All you have to do is navigate the expression cursor to a placeholder element, and type a letter. The placeholder element is replaced with a <ci> element containing the letter typed.

Of course not all symbols have one-character names. By convention in Zed if you create a one-character symbol as just described, then any successive letters and numbers you type become part of the name of the symbol just created, that is, the letters and numbers become part of the character data for the <ci> element. This convention should cover almost all of the identifiers you will want to create using the editor; to create identifiers whose character data does not match the pattern of a letter followed by letters and numbers, you can use the Edit→Source dialog box to insert exactly the character data you need.


Numbers

Numbers in MathML also have their own encoding, using the special token element <cn> in content MathML and the special token element <mn> in presentation MathML.

Creating a one-character number in Zed is as easy as creating a one-character symbol. All you do is navigate the expression cursor to a placeholder element, and type a number. The placeholder element is replaced with a <cn> element containing the number typed.

Of course not all numbers have only one digit. By convention in Zed if you create a one-digit number as just described, then successive numbers and any decimal point you type become part of the number just created, that is, the numbers become part of the character data for the <cn> element. This convention should cover almost all of the numbers you will want to create using the editor; to create numbers whose character data includes non-numeric characters, you can use the Edit→Source dialog box to insert exactly the character data you need.

MathML also supports certain special numeric types that require more than one numeric piece of character data, such as complex numbers. These numbers are encoded using <cn> elements using the special <sep> element between the separate pieces of character data needed to encode the number. Special attributes on the <cn> element are used to specify which special numeric type is being used. In Zed such numbers can be entered by first entering the concatenated character data for the separate pieces, then entering the <sep> elements at the appropriate positions, then setting the type attribute with the appropriate value.


Operators

Not all token elements in MathML fall into the categories of symbols and numbers. The operator elements in presentation MathML are typically encoded in content MathML using special empty elements that are handled as part of the support for combining elements into more complex expressions, as described below.


Juxtaposition

The conventions described above for entering symbols and numbers are supported by a special token input mode for entering character data in Zed. When this special input mode is active, the color of the expression cursor changes to blue to let you know you are editing the one-dimensional character data contained in the token element being edited. The left and right arrow keys allow you to navigate forward and backward within the character data, and the up arrow key allows you to exit this token input mode and navigate the rest of the expression in the usual fashion.

These conventions imply that when one letter or number is followed by another letter or number, certain assumptions are being made about the structure you intend to create. If a letter is followed by a letter or number, Zed assumes you are creating a symbol with more than one letter in its name, as described above. If a number is followed by a number, Zed assumes you are creating a number with more than one digit. When a number is followed by a letter, however, the most common case is that the number is to be multiplied by the symbol that would be otherwise created by typing the letter (e.g. '2x') and so Zed interprets the juxtaposition of these two characters as multiplication, and creates separate <cn> and <ci> elements respectively.

For those who prefer to use single-character symbols exclusively, the assumptions Zed makes about juxtaposition of characters can be customized to support this alternative, by introducing templates that arrange for a letter following a letter to create a separate <ci> element as is done when the letter follows a number.


Templates

The ability to create token elements provides the basic building blocks for creating more complex expressions involving operators applied to arguments. The primary means of creating new structure in a MathML expression is through the use of named templates. A template is a pattern-based transformation rule that can be used to rewrite the form of an expression from one shape to another. Many of the templates defined in Zed operate to enclose the current expression with the application of a new operator, with additional placeholder elements as needed to ensure the expression remains well-formed. Other templates can be used to introduce special content forms, to supply special attribute values, or to modify the number of child elements contained in the parent element.

A named template may be invoked in any number of ways. Typing Shift+Insert brings up a one-line dialog that allows you to enter a name of a template, which is then applied to the current expression. This alternative provides a completely general keyboard means of accessing any named template, and can be used quite rapidly once you gain familiarity with the template names you use often. Many of the template names are identical to the names of the elements they create; others append a number indicating the number of child elements to create for those elements that accept optional arguments. Other more graphical ways of invoking a named template include the use of menus and palettes, as described below. Special keyboard symbols can also be bound to named templates, as described in the paragraphs on keyboard accelerators.

While the use of named templates provides a good first approximation for creating two-dimensional mathematical expressions, there is one common case whereby such templates can produce an undesired result. Consider the example "2x+3". After entering the first monomial ("2x"), the expression cursor will be positioned on the "x" that was just entered. You would expect typing the "+" key to invoke the "plus" named template that would allow you to enter the "3" to produce the result. Instead, the direct application of the "plus" template would produce "2(x+3)". To overcome this behavior, Zed implements a notion of template precedence, whereby the operator precedence of the operators used in the template are used to determine whether the template is applied to the current expression, or to some parent element of the current expression. So in this example, since the precedence of "plus" is weaker than that of "times", the template is applied at the outer element and the result produces "2x+3" as was intended.

So then how does Zed handle the example "2(x+3)"? After entering the first factor ("2"), the expression cursor will be positioned on the "2" that was just entered. Upon typing the "(" key, a new parenthesized expression is introduced that will allow you to type the second factor ("x+3") in the usual way. The parenthesized expression limits the template precedence so that it operates within the parentheses. Upon typing the ")" key, the expression cursor navigates out to the parenthesized expression, which is then removed from the content expression, and retained in the presentation expression as needed to show the proper nesting of the operators in the expression.

Zed provides a large collection of named templates in the standard configuration that cover most any of the content elements in MathML. Each of the templates provided for creating a particular MathML element are described in the MathML Reference section, organized by element. These templates may be customized, extended, or replaced altogether using the mechanisms described in the Template Rules subsection of the Configuration section.


Operators

There are many different content elements in MathML and no template-based mechanism can hope to cover all of the cases of convenient input conventions in a uniform fashion. In Zed an effort is made to keep the template matching machinery as simple as possible, and provide collections of special operations for handling classes of operator that fall outside the scope of the generic template mechanisms.

The special operations implemented in Zed fall into three broad categories: operations for inserting and removing parentheses in associative operators, operations for inserting and removing additional arguments of nary operators, and operations for inserting, removing and navigating rows and columns of array operators. The complete list of these special operations can be found in the Operators section in the Reference part of the Users Guide.


Accelerators

While the use of named templates is appropriate for a large class of elements with no special character abbreviation, a moderately-sized collection of templates can naturally be bound to special keys that serve as mnemonic equivalents for those elements. So one would expect "+" to create the <plus> element, "!" to create the <factorial> element, and so on. Zed defines a number of such keyboard accelerators for its named templates, where appropriate.

The keyboard accelerators provided by Zed include those for the common arithmetic operations, logical operations, relations, and a few others. The complete list may be found in the Keyboard Accelerators paragraphs of the Events reference.

The selection of which keys to bind to which templates is, in some cases, somewhat arbitrary. These bindings can be overridden in much the same way as the templates themselves can be customized, by redefining the template action associated with a given keyboard combination, as described in the Template Rules subsection of the Configuration section.


Menus

Nearly all of the named templates can also be invoked by selecting a particular menu item on the Math menu, which is organized roughly according to the description of the content MathML elements in the MathML 2.0 Recommendation. The Math menu is available on the frame menu in the application edition, and on the context menu in both the application edition and in the component edition. Simply selecting a menu item from this menu invokes the corresponding template.

As with many other things, the particular arrangement of the menus themselves is quite arbitrary. The configuration mechanisms supported by Zed allow you to define additional menus, rearrange items on any of the predefined menus, or completely replace the entire set with ones that are more convenient to the types of expressions you create. See the Menus subsection of the Configuration section for more details.


Palettes

For those who prefer a more graphical organization of the available templates, Zed provides a collection of palettes that can be used to invoke the templates. A palette is simply a two-dimensional array of buttons, each of which is bound to a named template. The label on each button is borrowed from the result of applying the template, to suggest the operation to be invoked by clicking on that button. The collection of available palettes in Zed is roughly as extensive as the collection of available menus, and is organized in roughly the same fashion, following the descriptions in the MathML 2.0 Recommendation. To see all of the available palettes, use the menu item Palette→Open All. To close all of the open palettes, use the menu item Palette→Close All.

Invoking a named template from a palette is as easy as clicking the button. The template associated with the button is applied to the current expression, and the current window retains the input focus so additional keyboard input can be accepted by the main editing window. In situations where several instances of the editor may be running at the same time, Zed avoids any confusion over which palettes are associated with which window, by hiding the open palettes when the Zed window loses the input focus. When the focus is regained, the open palettes are made visible again.

With such a large collection of palettes, it can be quite cumbersome to raise and position the palettes one uses often. So Zed saves the palette state, including which palettes are visible and where they are located, between sessions in much the same way as it saves the toolbar state in the application edition.

Each palette will contain one or more placeholder elements that will be created to receive further input. On the palette buttons, a placeholder element will appear in yellow to indicate which placeholder element in the palette will be replaced by the current expression. A placeholder element appears in green on a palette to indicate the position of the expression cursor after the associated template is invoked.

As with the menus, the arrangement of the palettes and the buttons they contain is quite arbitrary. The configuration mechanisms supported by Zed allow you to define additional palettes, to arrange the buttons on the palettes as desired, or to completely replace the entire set with ones more appropriate to your application. See the Palettes subsection of the Configuration section for more details.