Editing Fōrmulæ expressions
This page is a tutorial for editing Fōrmulæ expressions. It applies to any Fōrmulæ front-end, including the Fōrmulæ Desktop.
- 1 Basic concepts
- 2 Editors
- 3 Actions
- 4 Sources of editor/actions
- 5 Styles of edition
In Fōrmulæ, there is the notion of a selected expression. It is a either a complete expression or a part of it.
A selected expression should be visually indicated in any way. For example, in the Fōrmulæ Desktop is shown as a dark box that encloses the selected expression:
|First addend selected||Second addend selected||Whole expression selected|
There cannot be more than one selected expression at any time. It is usual that the front-end manages many expressions at the same time, but at most one expression (or a part of it) can be the selected expression.
Changing the selected expression
Using the pointing device
When you move the pointing device over an expression, it shows a highlighted expression. It is the most general expression that contains the coordinates pointed by the device. In the Fōrmulæ Desktop it is shown as a blue frame drawn around the highlighted expression:
Making click (with the primary button) on your pointing device will just make that the highlighted expression becomes the selected expression.
Using the keyboard
Traversing with the arrow keys
Pressing the arrow keys will make that a different expression becomes selected. Depending on the direction of the key pressed a suitable expression will be chosen.
The new selected expression will always be one containing no sub-expressions. See the following examples:
Given that a traversal using the arrow keys only selects expressions with no sub-expressions, how can more general expressions be selected (using the keyboard) ? Pressing the key will make that the parent expression of the selected expression becomes the new selected expression.
The next example shows a repeatedly escaping. Once that the entire expression becomes the selected expression, an escape cannot be performed.
An editor is piece of code that, given a selected expression, makes changes to an expression (usually the expression that contains the selected expression), or creates new expressions. Once the changes have been performed, a new selected expression is defined (usually the new selected expression belongs to the expression that contained the then selected expression).
Example. The following is an example of an editor. This editor is used to create arithmetic divisions. It makes the following:
- It creates a new division expression, it is, an expression containing two sub-expressions, the numerator and the denominator.
- The numerator is set to be the selected expression.
- It creates a new Null expression, and it is set to be the denominator.
- In the place where the selected expression used to be, the division expression will be put.
- The new selected expression will be the Null expression (the denominator).
An editor can have an icon associated to it. This icon is used to graphically represent the operation pretended. It is common to represent the selected expression as a solid black box, and newly created expressions as white boxes.
There can be more than one editor for he creation of a given expression.
For our example there can be two editors, the first one uses the selected expression as the numerator, and the second one uses the selected expression as denominator:
|Example||Edition performed||Shortcuy key||Result|
The way of editor invocation depends of the front-end used. With the Fōrmulæ Desktop, the left part of the window contains a tree with the known editors:
For editors with shortcut, pressing the key (or combination of keys) will perform the associated editor.
All editions are undoable/redoable.
Fōrmulæ front-ends also support undo/redo operations of many levels, this is, you can undo several times back. The number of levels you can undo depends on every front-end.
Some editors require interaction with the user. This is usually performed through dialog boxes.
Example 1. A Symbol is fundamental kind of expression. Every symbol has a name. The editor intended to create a symbol opens a dialog box in order to the user can write its name.
Example 2. Editors are not limited to create a single expression. There is an editor to create a matrix, which is an array of arrays of elements. The following editor opens a dialog box in order to the user defines the number of rows and columns, and then duplicates the selected expression to be every element of the matrix. The element in the first row/column of the matrix becomes the new selected expression:
|Example||Edition performed||Dialog box||Result|
An action is a special kind of editor.
An action neither creates new expressions nor deletes any expression, it is intended to alter the nature of the selected expression, but it remains the same.
Actions, being editors, are also undoable/redoable.
As an example, we showed above an example of an editor to create a symbol with a name. An action will be useful to change the name of a symbol previously created.
In the Fōrmulæ Desktop, making click with the secondary button of your pointing device while the desired expression is the selected expression will display a pop-up showing the list of actions associated with the selected expression, such as follows:
|Example||Action selection||Dialog box||Result|
If there are multiple actions associated with the Tag of the selected expression, the first of them can be invoked by pressing the key.
If there is no action associated with the Tag of the selected expression, pressing the key does nothing.
Sources of editor/actions
There are tow sources of editors/actions, Fōrmulæ packages and those provided by the front-end.
Remember that most of the functionality (including editors/actions) of the Fōrmulæ framework is provided though packages. They are units of code that can be used as libraries (in programs), or embedded dynamically in the front-ends.
As an example, an arithmetic package will contains editors/actions to create arithmetic expressions, such as numbers, arithmetic operations, trascendental functions, etc.
Because of that, a definitive or complete list of editors/actions will be necessarily incomplete. Refer to packages or expressions.
Editors can be built-in directly in front-ends. While front-ends offer different editors they will provide, at least, the following built-in editors:
Deletion of expressions
This editor tries to be as less destructive as possible, according with the following rules:
- If the selected expression is not the Null expression and it has exactly one sub-expression, the expression will be substituted by its only sub-expression. This sub-expression becomes the new selected expression.
- If the selected expression is not the Null expression and it has a number of sub-expression different than 1 (zero, two or more), the selected expression will be substituted by a new Null expression, and it becomes the new selected expression.
- If the selected expression is the Null expression, and its parent expression can hold a number of sub-expressions equal to the actual number less one, the selected expression is deleted.
- If the selected expression is the Null expression, and its parent expression is holding exactly two sub-expressions (division, exponentiation, etc.), the entire parent expression is substituted by the sibling expression, and it becomes the new selected expression.
|Example||Shortcut key (Windows/Linux)||Shortcut key (MacOS)||Rule||Result|
Insertion of expressions
This editor only works if the parent expression of the selected expression can hold a number of sub-expressions equal to the actual number plus one.
There are two editors, the Insert after which appends a new Null expression after the selected expression, and the Insert before which appends the Null before. In both cases, the new Null expression becomes the selected expression.
|Example||Editor||Shortcut keys (Windows/Linux)||Shortcut keys (MacOS)||Result|
|Insert after/before||No edition. A division cannot have more than 2 sub-expressions|
Cut / Copy / Paste
These editors do the typical operations with the clipboard.
|Editor||Button||Shortcut keys||What it does|
|Cut||+|| The selected expression is copied to the clipboard.|
The current selected expression is replaced by a new Null expression, that becomes the new selected expression
|Copy||+|| Formally spoken, it is not an editor, because it does not change any visible expression and therefore it is not undoable/redoable.|
A copy of the selected expression is put in the clipboard.
|Paste||+|| Replaces the selected expression by a copy of the expression in the clipboard.|
This expression becomes the new selected expression
Styles of edition
Given an expression to be created, there is not an unique way to editing it.
There are different styles of edition that people usually adopt. They are not imposed, different persons tend to adopt one of them, sometimes they change the style and they even use a mixture of them.
The following are the two most used styles, exemplified to create the famous equation :
In this style, the parts of the expression are created as they are needed, in a continuous and logic sequence. it is a very natural style that resembles the human handwriting.
|(Initial Null expression)|
|1||Creation of a negative expression|
|2||Creation of the b symbol|
|3||Selection of the entire expression, or escaping|
|4||Creation of an addend|
|5||Creation of a square root|
|6||Creation of the b symbol, or copied/pasted|
|7||Creation of an exponentiation|
|8||Creation of number 2|
|9||Selection of the exponentiation expression, or escaping|
|10||Creation of a subtraction|
|11||Creation of number 4|
|12||Creation of a new factor|
|13||Creation of the a symbol|
|14||Creation of a new factor||or|
|15||Creation of the c symbol|
|16||Selection of the entire expression, or escaping 4 times||(x4)|
|17||Creation of a division|
|18||Creation of number 2, or copied/pasted|
|19||Creation of a factor|
|20||Creation of the a symbol, or copied/pasted|
In this style, structures are generated from general to particular. Usually (but it is not a rule) at the end, only Null expressions remain, which are substituted by their final expressions.
|(Initial Null expression)|
|1||Creation of a division|
|2||Selection of the numerator|
|3||Creation of an addend|
|4||Selection of the first addend|
|5||Creation of a negative expression|
|6||Selection of the second addend|
|7||Creation of a square root|
|8||Creation of a subtraction|
|9||Selection of the minuend|
|10||Creation of an exponentiation|
|11||Selection of the sustraend|
|12||Creation of a new factor|
|13||Creation of a new factor||or|
|14||Selection of the divisor|
|15||Creation of a new factor|
|16+||Creation of remaining symbols and numbers|