Editing Fōrmulæ expressions

From Fōrmulæ wiki
Jump to: navigation, search

This page is a tutorial for editing Fōrmulæ expressions. It applies to any Fōrmulæ front-end, including the Fōrmulæ Desktop.

Basic concepts

Selected expression

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:

SelectedExpression1.png SelectedExpression2.png SelectedExpression3.png
First addend selected Second addend selected Whole expression selected

Uniqueness

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:

HighlightExpression1.png HighlightExpression2.png HighlightExpression3.png
HighlightExpression4.png HighlightExpression5.png HighlightExpression6.png
HighlightExpression7.png HighlightExpression8.png HighlightExpression9.png

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:

Traversal1.png KeyRight.png Traversal2.png KeyRight.png Traversal3.png KeyDown.png Traversal4.png KeyUp.png Traversal1.png


Escaping

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 KeyEscape.png 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.

Traversal2.png KeyEscape.png Traversal7.png KeyEscape.png Traversal8.png KeyEscape.png Traversal9.png KeyEscape.png Traversal10.png KeyEscape.png Traversal11.png

Editors

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).
Example Result
Division1.png Division4.png
Division2.png Division6.png
Division3.png Division8.png

Editor icon

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.

For the previous edition example, the icon is DivisionNumerator.png

Editor shortcut

An editor can have a shortcut (a key or combination of keys) to invoke the edition. In our example, this editor has the KeyDiag.png key as shortcut.

Multiple editors

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
Division1.png DivisionNumerator.png KeyDiag.png Division4.png
Divisiondenominator.png Division5.png
Division2.png DivisionNumerator.png KeyDiag.png Division6.png
Divisiondenominator.png Division7.png
Division3.png DivisionNumerator.png KeyDiag.png Division8.png
Divisiondenominator.png Division9.png

Invoking editors

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:

DesktopEditorPane.png

For editors with shortcut, pressing the key (or combination of keys) will perform the associated editor.

Undoing/redoing editions

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.

Operation Button Shortcuy key
Undo IconUndo.png KeyControl.png + KeyZ.png
Redo IconRedo.png KeyControl.png + KeyY.png

Interactive editors

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.

InteractiveEdition1.png

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
InteractiveEdition2 1.png InteractiveEdition2 4.png InteractiveEdition2 2.png InteractiveEdition2 3.png

Actions

An action is a special kind of editor.

While an editor can operate on any kind of expression, an action is always focused in the Tag of the expression. it is, a given action operates only if the selected expression has an specific Tag.

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.

Invoking actions

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
Action0.png Action1.png Action2.png Action3.png

If there are multiple actions associated with the Tag of the selected expression, the first of them can be invoked by pressing the KeySpace.png key.

If there is no action associated with the Tag of the selected expression, pressing the KeySpace.png key does nothing.

Sources of editor/actions

There are tow sources of editors/actions, Fōrmulæ packages and those provided by the front-end.

Packages

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.

Front-end

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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
Deletion2.png KeyDelete.png KeyFn.png + KeyBackspace.png 1 Deletion2a.png
Deletion1.png KeyDelete.png KeyFn.png + KeyBackspace.png 2 EditionNull.png
Deletion3.png KeyDelete.png KeyFn.png + KeyBackspace.png 2 EditionNull.png
Deletion4.png KeyDelete.png KeyFn.png + KeyBackspace.png 3 Deletion4a.png
Deletion5.png KeyDelete.png KeyFn.png + KeyBackspace.png 4 Deletion5a.png
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
Insertion1.png Insert after KeyInsert.png KeyOption.png + KeyRight.png Insertion1a.png
Insertion2.png Insert before KeyAlt.png + KeyInsert.png KeyOption.png + KeyLeft.png Insertion2a.png
Insertion3.png 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 ButtonCut.png KeyControl.png + KeyX.png 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 ButtonCopy.png KeyControl.png + KeyC.png 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 ButtonPaste.png KeyControl.png + KeyV.png 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-line

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.

Step Activity Editor Shortcut key Result
(Initial Null expression) EditionNull.png
1 Creation of a negative expression Negative10.png EditionInline02.png
2 Creation of the b symbol EditorSymbol.png KeyS.png Editioninline03.png
3 Selection of the entire expression, or escaping KeyEscape.png Editioninline04.png
4 Creation of an addend Addition.png KeyPlus.png Editioninline05.png
5 Creation of a square root EditorSquareRoot.png Editioninline06.png
6 Creation of the b symbol, or copied/pasted EditorSymbol.png KeyS.png Editioninline07.png
7 Creation of an exponentiation EditorExponentiation.png KeyPow.png Editioninline08.png
8 Creation of number 2 EditorNumber.png KeyN.png Editioninline09.png
9 Selection of the exponentiation expression, or escaping KeyEscape.png Editioninline10.png
10 Creation of a subtraction Minus.png KeyMinus.png Editioninline11.png
11 Creation of number 4 EditorNumber.png KeyN.png Editioninline12.png
12 Creation of a new factor Multiplication.png KeyMult.png Editioninline13.png
13 Creation of the a symbol EditorSymbol.png KeyS.png Editioninline14.png
14 Creation of a new factor EditorNumber.png KeyMult.png or KeyInsert.png Editioninline15.png
15 Creation of the c symbol EditorSymbol.png KeyS.png Editioninline16.png
16 Selection of the entire expression, or escaping 4 times KeyEscape.png (x4) Editioninline21.png
17 Creation of a division DivisionNumerator.png KeyDiag.png Editioninline22.png
18 Creation of number 2, or copied/pasted EditorNumber.png KeyN.png Editioninline23.png
19 Creation of a factor Multiplication.png KeyMult.png Editioninline24.png
20 Creation of the a symbol, or copied/pasted EditorSymbol.png KeyS.png Editioninline25.png

Skeletal

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.

Step Activity Editor Shortcut key Result
(Initial Null expression) EditionNull.png
1 Creation of a division DivisionNumerator.png KeyDiag.png EditionGeneralParticular01.png
2 Selection of the numerator KeyUp.png EditionGeneralParticular02.png
3 Creation of an addend Addition.png KeyPlus.png EditionGeneralParticular03.png
4 Selection of the first addend KeyLeft.png EditionGeneralParticular04.png
5 Creation of a negative expression Negative10.png EditionGeneralParticular05.png
6 Selection of the second addend KeyRight.png EditionGeneralParticular06.png
7 Creation of a square root EditorSquareRoot.png EditionGeneralParticular07.png
8 Creation of a subtraction Minus.png KeyMinus.png EditionGeneralParticular08.png
9 Selection of the minuend KeyLeft.png EditionGeneralParticular09.png
10 Creation of an exponentiation EditorExponentiation.png KeyPow.png EditionGeneralParticular09a.png
11 Selection of the sustraend KeyRight.png EditionGeneralParticular10.png
12 Creation of a new factor Multiplication.png KeyMult.png EditionGeneralParticular11.png
13 Creation of a new factor Multiplication.png KeyMult.png or KeyInsert.png EditionGeneralParticular12.png
14 Selection of the divisor KeyDown.png EditionGeneralParticular13.png
15 Creation of a new factor Multiplication.png KeyMult.png EditionGeneralParticular14.png
16+ Creation of remaining symbols and numbers Editioninline25.png