Navigating Mathematical Expressions

This section helps you understand how to navigate the expression cursor around the hierarchical structure of a mathematical expression in Zed, including the use of the arrow keys, extended selection, placeholder elements, and the use of the mouse.


Expression Cursor
Structural Navigation
Traversal Order
Structural Arrow Keys
Extended Selection
Placeholders
Using the Mouse

The recursive nature of a mathematical expression constrains what parts of an expression can be navigated, and in what order they should be traversed. These constraints require additional means for moving from place to place in an expression that are quite different than those used to move around in other documents. The following paragraphs describe the structural traversal conventions supported by the editor and illustrate how to use them to locate the expression cursor to define the current expression.

In many cases, there are both keyboard accelerators and mouse events that achieve the same effect. Both alternatives are described below, and more complete information can be found in the Reference part of this Users Guide.


Expression Cursor

Navigating an expression consists of successively moving the expression cursor from one position to another in the expression. The position of the expression cursor calls out one distinguished expression as the current expression, and also indicates whether the insertion point is to the left or the right of that expression. The current expression selected by the expression cursor is often the source or target of other operations supported by the editor, and the insertion point is often used to determine where new structures come into or move out of the document as editing progresses.

You will see the expression cursor as a visible graphic that partially surrounds the current expression. The expression cursor takes the appearance of an underline along the extent of the current expression, plus a vertical bar along the height of the current expression, placed either to the left or to the right of the expression, indicating whether the insertion point is located to the left or to the right of the current expression.

The color of the expression cursor is used to indicate whether or not the associated window has the input focus. When the window has the focus, the cursor changes to black, when the window loses the focus, the cursor changes to gray. In addition, the cursor changes to blue when the current expression is a piece of character data located within a token element such as <ci> or <cn>.


Structural Navigation

When navigating a mathematical expression, the expression cursor is positioned in such a way as to select at each stage a well-formed content expression. This approach to navigating an expression is called structural navigation, as opposed to the more familiar visual navigation used by word processors and other kinds of document editors. Much of the motivation for supporting structural navigation derives from the highly recursive nature of the expression content being created by Zed, and by the wide variety of two-dimensional layout transformations available.

One advantage of structural navigation is that at each stage the expression cursor supplies a complete piece as the current expression, regardless of the presentation used to display the expression. So editing operations can operate solely on the content, which in turn drives changes to the presentation. The main disadvantage of this approach arises when the structural navigation operations are poorly matched with the more natural visual navigation operations, especially in the order in which visible symbols are traversed by structural navigation conventions.


Traversal Order

The content elements used to encode an expression provide a well-defined traversal order for the complete set of valid positions for the expression cursor in that expression. A complete inorder traversal of these positions begins with the entire expression as the current expression, and with the insertion point to the left of the expression. The traversal ends with the entire expression as the current expression, and with the insertion point to the right of the expression. In between the traversal will recursively traverse each of the child elements of the current expression that are referenced (and therefore visible) in the presentation markup used to display the expression. The child elements are visited in an order determined by the presentation, in roughly a left-to-right, top-to-bottom sequence obtained from the MathML elements used in the presentation.

The layout transformations for operators in Zed are allowed to reference each child element more than once, not at all, or in any arbitrary order. By way of example, an infix operator will often be referenced more than once, as will the elements specifying the degree of differentiation. In the case of infix operators, each instance of the operator will be visited, while in the case of other operators such as for derivatives, repeated instances of a child element are only visited once. Furthermore, since only well-formed content elements are visited, if the presentation elements include visible symbols not driven by a particular child element, these symbols will be omitted in the traversal of that element. One such example is the "differential d" symbol that appears in a definite integral.

The traversal order for a particular operator can be customized with much the same generality as is possible for the layout transformations used to present the operator. This feature is especially useful in helping the editor to provide a somewhat more natural traversal for those operators where the desired traversal order cannot be inferred directly from the markup. Details on how to override the traversal order for a particular operator can be found in the Traversal Orders subsection of the Configuration section.


Structural Arrow Keys

Example: quadratic.mml

As you would expect, the arrow keys are one of the primary means of navigating from one place to another in an expression. You can use the expression in the above example link to follow along and try out the various arrows as they are discussed.

The basic inorder traversal defined in the previous subsection is bound to the Left and Right arrow keys. Successively pressing the Left arrow moves through the traversal in order, and the Right arrow key moves backward through the traversal. Using these keys you can see the complete set of places that can be visited as the current expression.

Each expression has a unique well-defined parent element that immediately encloses it and is structurally well-formed. The Up arrow key moves the current expression to its parent element, and the Down arrow key moves the current expression to either its first or last child element as determined by whether the insertion point was to the left or right, respectively, of the previous current expression. Typing Ctrl+Up moves the expression cursor to the outermost element in the expression, and typing Ctrl+Down moves the expression cursor to the innermost element in the current expression, either the leftmost or rightmost depending on whether the insertion point was to the left or right, respectively, of the previous current expression.

Much of the time the left and right arrows move in increments that are much smaller than desired. In that case, typing Ctrl+Left moves to the previous sibling element of the current expression and Ctrl+Right moves to the next sibling element of the current expression. The Home key moves to the first sibling element of the current expression, and End key moves to the last.


Extended Selection

Some operators such as nary operators or associative operators present a linear list of child elements in such a way that it is often useful to be able to select a range of child elements that appear within a parent element. Using arrow key conventions borrowed from other Windows applications, you can type Shift+Left and Shift+Right from within such elements to extend the range of child elements being selected in the corresponding direction. This operation is known as extended selection.


Placeholders

As is discussed more fully in the sections on Inserting and Deleting elements from the expression, a large number of the templates for introducing new structure do so by creating placeholder elements for those child elements that have yet to be created. These placeholder elements appear as a small blue box that can be filled in with additional input as needed.

If you have created an expression that contains a number of placeholder elements, you may move back and forth between them using the the Tab and Shift+Tab, which are defined to move the expression cursor to the next (respectively, previous) placeholder element in the document.


Using the Mouse

While using the keyboard is quite often the fastest way to make short movements from one place to another in an expression, more distant movements may be accomplished more quickly using the mouse instead of the keyboard. In general, clicking the left mouse button moves the expression cursor so that the smallest well-formed expression surrounding the point clicked becomes the current expression. This operation is known as click to select.

An extended selection can also be created using the mouse, using the drag to select operation. By clicking the left mouse button on the expression at one end of a range, and dragging the mouse to the expression at the other end of the range, the editor causes the entire range to be included in the extended selection.

Other mouse events may interact with the mouse traversal operations, depending on the location of the mouse click with regard to the current expression. The Mouse Actions paragraphs in the Events section describe these interactions in more detail.