]>
I would be happy to hear from you if you have problems, so I can improve this tutorial.
Gemse is inspired by the texteditor Vim. It is difficult to learn, but hopefully will be a powerful tool once it is finished. However, I am sure you will master it, if you want to.
You wont need any knowledge about vim for this tutorial. But you will need knowledge about Presentation MathML. How you can edit Content MathML is discussed as well in this tutorial, but you may skip the corresponding section if your are unfamiliar with it. Gemse's documentation contains a short introduction to presentation MathML. Additionally, you can find tutorials and the specification of MathML on the MathML page of the w3c. Of course learning presentation MathML requires learning the fundamentals of XML. Gemse directly edits the XML structure of presentation MathML.
Gemse 1 is an application written in Javascript using Mozilla. So, if you have installed Firefox 3, you are already lucky. If you do not like the idea of installing Firefox 3, you can use XULRunner 1.9. Please refer to the base documentation to find out how to install and run Gemse.
There is an input box at the very bottom. The cursor should be placed there automatically. If not, do that manually, for example by clicking in the box. Now you can start typing commands. As soon as you have entered a complete command, it will be executed and the box will be cleared. If you have typed something wrong, you can clear the box manually by hitting the escape key.
Let's try it: Enter :help&enter; (&enter; means that you have to hit the enter key.) This opens the index of Gemse's help sites in a new window or a new tab. Close it to get back to the editor. Observe that the input box is empty at this point. If you have made a typo, hit &esc; (that is, hit the escape key.) to clear the input box and try again.
There are a couple example equations included in the documentation of Gemse. We will use some of them. You will now learn how to load them.
Basically loading works like this: You enter :load followed
by a space and the URI of the file you want to load. Finally, you hit
enter. Yes, you have to enter the URI. This allows you to load any
file from the web you can access. Of course, files on your computer
also can be loaded like that too. Their URIs begin with
file://. So, for example, in order to load the file
/home/urs/foo.xml you have to use the URI
file:///home/urs/foo.xml and in this case, the command is
:load file:///home/urs/foo.xml&enter;. You can also use
a relative URI.
In this tutorial, when I tell you to load a file
examples/foo.xml, you have to do that like this: If you use
Gemse as Firefox extension or as XULRunner application, type
:load chrome://gemse/content/doc/examples/foo.xml&enter;.
If you use the demo on the web or if you opened
editor.xul in your browser not using a
chrome:// URI, try
:load doc/examples/foo.xml&enter;.
Alternatively, you can just enter :example foo.xml&enter;.
Try it: Load the file examples/pres.xml.
You should see something like shown below.
The topmost box contains the rendering of the current equation, whereas the second box from the top shows the MathML tree structure of it. Below the second box, you can see the (a little bit simplified) source of the equation and a table of attributes of the selected element. On the righthand side, you can see a list of all equations that you currently have opened. At the bottom, there is a status line which informs you about the current state the editor is in. In the following sections you will learn what all this means.
From now on, I will show you only those boxes that I think are important. Actually, these boxes are called views as you will learn in a later section of this tutorial.
The most important thing is the cursor. It highlights an element of
the equation. If you issue a command, it gets applied on the
highlighted element. Currently, the cursor is at the math
element, the topmost element of the equation.
You can move the cursor
around using the keys h, j, k,
l. (Well, I am actually writing what you have to enter. So
J means that you have to press the shift key and the key
with the letter J on it. When I write j you have to press
the key with the J on it, which enters a lower case j.) h
moves the cursor to the left, l moves it to the right. Of
course, the math element does not have an element to the right nor one
to the left. It has no siblings, if you want to express it in XML
terms. k moves the cursor to the parent of the currently
highlighted element. However, the math element is the
topmost element. Now press j.
The cursor has been moved, but it is difficult to see where exactly. In order to see exactly which element the cursor is on now, look at the tree view in the box below the equation. Press j again.
j moves the cursor to the first child element. Now you
can press l to move the cursor to the next sibling. Now the
mo element with the = in it is higlighted.
h moves the cursor to the previous sibling, usually the
element to the left. Now use these command several times to get used
to it.
Observe that h, l do not always mean to
the right
or to the left
respectively. For example, select
the mfrac element. You can reach it by putting the cursor
over the math element by using k several times
followed by jjlljl. (Note that I sometimes join commands
that you have to enter one after the other. This for example means that you have
to hit j, then j, then l and so on.)
Now hit j once again. This selects the first child of the
mfrac element.
In MathML, the first child of an mfrac element is the
enumerator of the fraction. The second one is its denominator. So
enumerator and denominator are siblings in the XML tree. That means
that you have to use h and l to switch between
the two. j and k do have a different meaning in
this context: k moves to the parent, i.e. the
mfrac element. j moves to the first element
contained in the enumerator or denominator respectively. Try it. Also
try to find out what happens on the msup and
munderover elements.
Now you know how to move around. You also have seen that movements are relative to the XML tree structure, not relative to where something appears in the rendered equation. There are and will be many more commands to move around faster, but what you have seen should suffice for now.
We start with the easy thing. Its deleting. (Who would have thought
that it is something destructive?) If you hit x the
element that is highlighted by the cursor gets removed, including all
its descendants. Move the cursor to the ( after the
exp and hit x. What you get is
Do the same with the closing bracket ) by
lx. Now you have
Beware: x can be dangerous: Select the denominator of the fraction by hitting klljljl. Now hit x to delete it. You immediately see that this was not good.
What does cause this? Well, some MathML elements must have a fixed
number of children, in case of mfrac this number is two.
If a mfrac element does not have two children, it is
invalid. The MathML renderer no longer understands what is meant by
the mfrac element and can not render the equation
completely. If something like this happens, you have to look at the
tree view in order to fix the problem, since the rendering of the
equation is incomplete. You can also fix it by undoing your mistake,
as you will learn in the next section.
Of course, Gemse has also undo and redo commands. u undoes your last change. &ctrl;r undoes your last undo. (&ctrl;r means that you have to hold down the control key and hit r. Something like &ctrl;ab&alt;c says that you have to hold control, hit a, releae control, hit b, hold down alt, hit c and releaste alt.) Now hit u. The denominator you just deleted is back.
You can not only undo the last change, you can even undo changes before it. For this hit uu. Now the two brackets you deleted are back too.
If you have undone too many changes, you can reapply them by hitting &ctrl;r. Now, do that twice. The brackets are gone again.
Of course, you can undo again what you have redone, and so on.
Vim provides history information in form of a whole history tree. Gemse only stores changes in a linear fashion. In vim, if you make changes after an undo, the undone change gets remembered. Gemse forgets all undone changes if you make new changes.
Being destructive is fun, but being constructive is even more fun.
Well, to insert something, you have to switch from the edit mode to the insert mode. This can be done with various commands, depending where you want to insert something. a (think: append) calls the insert mode such that it inserts new elements behind the current cursor. If you want to insert before it, you have to use i. The insert mode also has a cursor quite like the edit mode, but it looks different. Well, it doesn't only look different, it has a further very important difference: It lies between two elements, not on an element.
It is important to know that the insert mode of gemse is not yet mature and will most certainly change in the future. Even more, different insert modes can coexist. At the moment, there are two insert modes, the UCD insert mode and the trivial insert mode. While in edit mode, you can switch the insert mode to be used by hitting &tab; (the tabulator key). In this tutorial we will use the UCD insert mode which is the default. If you want, you can also take a look at the documentation of the trivial insert mode. This mode is called like that because it was trivial to implement, not because it is trivial to use it. Though it is tricky to use it, it is easy to grasp how it works.
But let us concentrate on the UCD insert mode:
Position the cursor over the munderover element of the
sum sign, like this:
Now hit i. Do you see the cursor? It is right in front
of the sum sign, or more precicely, in front of the
munderover element.
However, for the moment we let it be. Press &esc;. (Well, here you have to hit the escape key, not E then S then C.) This puts you right back into the edit mode.
What is an infinite sum? Well, it is the limes of partial sums.
Now, let us write it as such. First, let us change the
Press n. The insert mode recognizes n as a
letter and inserts it as an identifier into the equation. Now close the
insert mode with &esc;.
Now press k in order to put the cursor on the
munderover element. Now we are going to insert the
limes. Press i.
Well, the current implementations of the insert modes are sometimes
cumbersome. The
main problem (of both insert modes) is that if you want to write
We want to insert an operator
If you make a mistake in the insert mode, you can hit &esc; (maybe twice) to leave the insert mode and then use u and try again.
To do that we need an munder element. Press
&ctrl;u to tell the insert mode that you want to have such an
element.
You can see it already. When you now continue to insert elements,
they will replace the boxes you can see. Now press &ctrl;o. This
says that you are going to insert an operator. Now insert
lim&enter;. We can not insert lim directly
without indicating explicitely that we enter an operator using
&ctrl;o, because if we did, the insert mode would think
that we want the identifier l followed by the identifier
i followed by m.
Actually, always if we need an identifier or an operator which is longer than one character or which is treated by the insert mode the wrong way, we have to first hit &ctrl;o for an operator or &ctrl;i for an identifier, then we have to enter the characters and finally terminate with &enter;. Similarly, for numbers you can use &ctrl;n, but normally you do not need to do that, since the UCD insert mode is more clever when it comes to numbers.
Good. Since what we want to write below the limes consists of
multiple elements, we have to insert an mrow element. Do
that by hitting &space; (denoting the space bar).
Now press n. It is put as an identifier into the
mrow element. Hit → to get the arrow operator
and finally ∞ for the infinity sign.
Now hit &esc; and we are done.
I think we have done enough to get a break. You do not need to save the equation for this tutorial, since later, you can just load the equation as it is now from a file included in the documentation. But anyway, I want to tell you here how to save an equation to a file.
Important: Be careful! This software is very young and the implementation of laoding and saving is rather a hack. For example, it will overwrite existing files without moaning. If you give the save or load commands a relative URI, then it is considered to be relative to the current working directory, as indicated by firefox. Also be aware, that if you are using gemse not as firefox extension or XULRunner application, it has no permission to write to your harddisk.
For saving you simply write :save&space;, followed by the URI where you want to save your equation, followed by &enter;. The URI may be a relative one, which then is interpreted as reltive to the current working directory. If the URI points to a remote resource on a HTTP server, Gemse tries to save the file using the PUT method. However, if the URI points to a local file, Gemse will use the filesystem to save it.
So you can write :save example.xml&enter; to save the equation as an XML file in your current working directory. Or use something like :save file:///home/urs/math/example.xml&enter; to give an absolute path. Depending on your operating system, this looks a little bit different.
If you have loaded the equation from a file, Gemse remembers that. In such a case you can use :save&enter; to write it back into this file.
Alternatively, instead of saving to a file, you can also use the command :serialize&enter; which displays the XML source code on the screen.
Let us construct the following formula:
Nothing easier than that. First, create a new equation with :new&enter;. Your other equation is still here, with :previous&enter; and :next&enter; you can switch between the two. (And :close&enter; or :close!&enter; gets rid of one.) Here, I show you only the new one.
The newly created equation is a math element
containing an mrow element. Move the cursor to the mrow element.
Unfortunately, we can not use i nor a, since
they would insert before or after the mrow element. We want to insert
in the mrow. To do this, there is the command
&ctrl;i, which you now perform.
Press &ctrl;r. This creates a squareroot. (&ctrl;R would
give you a general root.) Now type ^a2&enter;.
Then +&space;. Here, the spacebar
creates an mrow element. Go on with
2ab&enter;, +^b2&enter;&enter;,
=.
And now &ctrl;r(&space;a+b&enter;).
Rats! We have forgotten something important. The expression inside the brackets including the brackets actually should be the base of a potency. Actually, we should have hit ^&space; right before the (. This mistake happens regularly (at least to me). Usually, one thinks of the potency after having written the base. Unfortunately, the current insert mode does not work like that, it needs you to enter the ^ before writing the base. However, there is a feature that allows you to fix this situation. Find out yourself what the commands &ctrl;h and &ctrl;l do. Well, they select what you already wrote. Good. use these two commands to select the brackets and their content:
Now, hit ^. The selected elements are enclosed inside an
mrow which becomes the first element of the new
msup element.
Now, we put the exponent 2 and continue with our work: &enter;&enter;=.
To finish the whole thing, press &space;(&space;a+b&enter;)&enter;&enter;. Actually, the last hit of the enter key terminates the insert mode, you also could have used &esc; instead.
Done. Note that at certain places, we could have skipped the
insertion of an mrow. As you will see in the next section, such
optional mrows can be added easily later on in the edit mode.
You can now close this equation. Since you do not have saved your changes, :close&enter; will not work. Instead, use :close!&enter;, which will throw away all unsaved changes.
In this section we are going to use the equation from the file
examples/pres01a.xml. If you started from the beginning of
this tutorial, this is what you should have now. If this is not the
case, simply load it as described in the introduction to this
tutorial.
Sometimes you want to do something not only with the element the cursor is on, but with a whole sequence of elements. Using the visual mode (name inspired by vim), you can select a set of siblings.
Put the cursor on the munderover element of the sum
sign. We are going to put the munderover element and the
following mfrac element into an mrow element. This makes
sense, since they together form the argument of the lim operator.
Press v. This throws you directly into visual mode.
If you use the default skin, you now see a beautiful blue. You can now use l, h and o. Find out yourself what they do. Be careful not to hit any other key. Now select the sum and the fraction.
Now you can hit a command from the editMode. In this case, execute
the command &space; (i.e. hit the space bar). This
command puts an mrow element around the selected
elements.
You are back in the edit mode. In the tree view you can see the
new mrow element. The cursor is currently on it.
Since you now know how the visual mode works, copying is no more
difficult. Gemse uses the command y for copying the
(with visual mode) selected elements into a register. A register is
simply a place where copied elements are stored. If you use a command
that works on a register and you do not say on which one, it will use
the default register (which is called ").
Delete commands put the removed nodes into a register. Let us try that. Move the cursor to the left side of the equation.
Hit x to remove it and move the cursor to the right side of the equation.
Hit p. This command pastes the content of a register after the cursor.
Move the cursor to the equal sign and hit xp again.
You can use xp to interchange the numerator and denominator: Put the cursor on the numerator.
Now hit xp.
There is also the command P which puts the content of a
register before the cursor as opposed to after it. Sometimes one wants
to put something into an empty element. In such a case, P
and p do not help. Select all children of the topmost
mrow element (not the element itself, but its children).
You can do that for example by typing ggjjv$.
(gg moves the cursor to the math element.
$ moves to the last sibling of the current element.)
Now delete the selected stuff, that is, hit d. This
leaves you with an empty mrow element.
Press &ctrl;p. What we removed is back in.
Select the equal sign and the right hand side of the equation using the visual mode (v).
Hit y. This copies the selected nodes into a register
without removing them. (This command is not named c, since
this letter is already used for the change command. You can think of
y as yank
.) Move the cursor to the right and press
p.
Be aware that delte, copy and even change commands all put the
respective elements into a register. By default, they use the default
register. This makes it sometimes tricky to use the default register.
You gan prepend "x to such a command or to a paste command
in order to use another register, where you have to write the name of
the register in the place of x.
Every register
has a name consisting of exactly one character. (Unlike in vim, you
can use every unicode character as name. This extends the amount of
available registers far beyond 26. Gemse's register names are case
sensitive, for example, register A and a are distinct registers.)
Hit u once to undo the mess from above. Move the cursor to the left hand of the equation and type "ay. Put the cursor on the righthand side and hit "by. Now try "ap and "bp and see what happens. Undo your changes afterwards.
Note that the commands that put something into a register always put the stuff in the default register as well when you tell them to use another register. The main reason for this is that it is done like that in Vim.
If you start here, load examples/pres01a.xml. It is
what you should have now if you went through the last section.
In MathML, one can put various attributes on elements. They control their (semantically significant) appeareance. It is also possible to put attributes of a foreign namespace on them. One useful example for this are attributes from XLink, which allow you to make links out of MathML elements.
In edit mode, you can call the attribute mode which allows you to edit the attributes of this element. At the moment, the attribute mode is called with @. This may change in the future, since in vim, @ has another meaning, which could be important for gemse too.
Select the fraction, i.e. the mfrac element. Now hit
@. You are now in the attribute mode. The selected element
does not yet have any attributes declared. However, the attribute view
below the tree view does also show you the default values of all
attributes. If an attribute is not declared, MathML uses its default
value. Let us add the attribute bevelled. For this, write
ibevelled&enter;true&enter;. Note that the i
at the beginning tells the attribute mode that you want to insert a
new attribute. Behind the i you have to write the name of the
attribute, then hit enter followed by the value of the attribute and
then enter again. As you can see, the attribute has been added to the
list of attributes and indeed, the fraction changed its
appeareance.
Let us add another attribute: ilinethickness&enter;0&enter;. And antother one: ifoo&enter;bar&enter;.
By looking at the attributes table you can see that there
is also a cursor in the attribute mode.
You can move it with j and k. Select the
bevelled attribute and insert cfalse&enter;.
This changes the value of the attribute under the cursor. You can also
remove an attribute by moving the cursor to it and hitting
x. Do that now with the foo attribute.
Don't forget to hit &esc; after you are done with the attributes in order to get back to the edit mode.
Gemse provides different ways to look at an equation: Its rendering, its tree structure shown by using nested boxes, its XML source and more. These are what is called views in Gemse. But in Gemse the concept of views goes even further. The list of attributes of the selected element, the list of dictionary entries, the list of the other opened equations and the status bar are views as well. (However, the input box is not a view.) The arrangement of views in the window is called a viewset.
There are some predefined viewsets. The command :viewset lets you choose the viewset you want to use. Currently, you are using viewset 0. Type :viewset 1&enter; and note the difference. In oder to get a list of all available viewsets, enter :viewset&enter;. As you can see, every viewset has a name. Indeed, you can give the command :viewset also the name of a viewset instead of its number.
Although the viewsets can not be changed while Gemse is running,
you can deactivate a view of the current viewset: Enter
:hideview 1&enter;. The tree view is no longer visible. The
views are counted in the order they appear in the XUL description of
the viewset in editor.xul, beginning at 0. Type
:hideview 0&enter; and the view of the rendering of the
equation is gone. Now reactivate the tree view by writing
:showview 1&enter;. You can also reactivate all hidden views
with :showview all&enter;.
Counting views and remembering the numbers of the viewsets is not very userfriendly. This situation will be improved in a future version of Gemse. Also, hiding a single view does not deactivate it, it is constructed anyway but just not shown. This will change in the future as well, because constructing a view can take too much time on slow machines and deactivating a view should be a way to speed up things.
Many aspects of the behaviour of Gemse can be configured (without messing around in
the source code). The command :set is used to set
options. Here you will see some options and their effect. We take
examples/pres02.xml for the equation. Again, the
screenshots here only show the relevant views.
Perhaps you want to see the attributes in the source view. Enter
:set SourceView.showAttributes=yes&enter; and voilà, here
they are. The source view has another useful feature: folding. When
you have a big equation, the source view spans below the window. You
can fix that by configuring the source view such that it only shows an
extract of the source. Enter :set SourceView.foldingDepth=3&enter;.
Now the source view only shows
the elements three levels deep. Does an element at the third level,
like the munderover contain children, they are replaced
by ....
Unfortunately, there is no way to see the children of the
munderover anymore, even moving the cursor to one of its
children won't help. Here comes another option into play. Set it with
:set SourceView.foldingStart=-1&enter;. This causes the
view to begin with the element that is the parent of the element under
the cursor. (Using -2 as value, the view would begin at
the grandparent, for -3 at the grandgrandparent and so
on.)
Now, move the cursor and see what happens. Perhaps you also want to do :set SourceView.syntaxHighlighting=on&enter;. Try it and see the effect.
Note that options that can be set either to true or
false, also allow the values yes,
on, 1 which are handled as
true and no, off,
0 which are handled as false.
Of course, gemse has many more options.
What you learned up to now extends to Content MathML in a natural way. All you have to do is to choose the content insert mode. Hit &tab; until the content insert mode is selected.
Load the file examples/content01.xml.
As you can see, the equation view is now little helpful, it does not show the equation in a rendered form. Instead, it seems to just shows garbage. The reason for this is that Mozilla's MathML rendering engine does not handle Content MathML. Indeed, it is not trivial to render Content MathML, i.e. to transform it to Presentation MathML. However, there is a view that can do that, called the NTNView. It uses the java library JOMDoc. Unfortunately, Gemse can only load java libraries if it is running with full permissions, that is, you have to run it as Firefox extension or XULRunner appilcation. Additionally, you must have installed a Java plugin which supports LiveConnect. Please read the instructions. If you get it working, you can enter :viewset content&enter; and you can see the rendered equation, as in the screenshots of this section. In any way, you should not forget that Gemse always acts on the XML structure of the equation and that the rendered equation can differ significantly in its structure. Therefore, you will have your eyes on the source view or on the nested boxes most of the time. Whether you get the NTNView working or not, you can go through this section anyway.
Move around the cursor and watch how the NTNView shows the cursor in the rendered equation as well.
When your cursor is on a Content MathML element, or the first
element of the selection is a Content MathML element, then the command
&space; creates an appply element instead of
an mrow element. Move the cursor to the identifier
element for b. Hit &space; once.
Now enter ji*. As you see, * places a times
symbol, +, -, / do the analogue.
(Note: If you got an mo element instead of a
csymbol, you haven't selected the content insert mode. In
this ase, hit escape, undo your wrong change, select the content
insert mode and try again.)
Do &esc;Acde.
Assume, instead of multiplying
d and e with the rest, we want to multiply
their sum with the rest. We are still in insert mode. hit
&ctrl;h&ctrl;h. At this point, we could use
&space; in order to put an apply around them
and the insert a csymbol manually later on. But it is even easier:
Just hit + and watch the magic happen. Terminate the insert
mode with &esc;.
Of course you want to be able to insert an arbitrary symbol from a content dictionary of your choice. Hit ggjj and then c. Finally, do $relation1&enter;eq&enter;.
The content insert mode has more features: Numbers can be inserted like in the UCD insert mode. That is, just type them. Should it ever happen that you want to insert a number right after a number, hit first &ctrl;, so that the digits you type are not appended to the preceding number. Cotent MathML has many elements (especially a lot of pragmatic elements). Therefore, Gemse has the commands # and < which allow you to insert arbitrary MathML elements. Please look up their meaning in the documentation of the content insert mode.
Now we are done with Content MathML, at least for this tutorial.
If you want to change the appearance of Gemse, you have to lay hands on
the file gemse.css. Note that the documentation also uses this
stylesheet file, so the examples in it are always consistent with your
changes.
For example, if you want to change the size of the renderings of
the formula, open gemse.css in a text editor, look out for
*[internal|viewClass="DirectView"], *[internal|viewClass="EquationView"]
and change the
font-size for example to large.
If you want to modify the viewsets, you find them in the file
editor.xul.
If you do not like the keyboard layout, i.e. you want to change the
name of the commands, you have to look into the javascript file
for the table for the respective mode. For example, if you want to
change the commands of the attribute mode, open the file
attributeMode_commandTable.js. Those files are not
exactly self-explaining, but you can try to change them.
We reached the end of the tutorial. You should now read the important basic information. Afterwards, you can peek into the rest of the documentation.