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.