Home | | Help | Contribute | Plug-ins | About | Contact | Search
Mathematical formulas
Manual | Top | Previous | Next

One of the main purposes of TeXmacs is to edit mathematical formulas. If the cursor is inside a formula (i.e. inside “math mode”), then the mode sensitive menus and toolbars provide buttons for entering common mathematical constructs. Similarly, as will be detailed in this section, the bahaviour of the keyboard changes so as to allow for the rapid typing of mathematical symbols. For instance, typing - > inserts the arrow .

Starting with version 1.0.7.10, TeXmacs also incorporates several features for the “semantic” editing of mathematical formulas, which will be described at the end of this section. When used appropriately, this allows you to write documents in which all formulas are at least correct from a syntactical point of view. A “syntax corrector” is included to assist you with this task. Documents with more semantics are for instance useful when using formulas as inputs for a computer algebra system. Such documents are also less likely to contain “typos”. Other interesting features, such as semantic search and replace, should be developed in the feature.

1.Incorporating mathematical formulas into documents

TeXmacs provides three main ways in order to enter a mathematical formulas into the main text:

InsertMathematicsFormula or $

This entry corresponds to small inline formulas like inside a textual paragraph. Note that formulas are typeset specially so they do not take too much vertical space. For example, limits are always displayed on the left. Limits can be displayed below in formulas with FormatFormula styleon. In formulas, formula style is off by default.

InsertMathematicsEquation or ⌥$

This entry is used for entering bigger displayed equations, like

which are typeset in a paragraph of their own. You may use the shortcut ⌃# in order to give the equation a number (or to remove the number of an equation). Also, ⌃⇥ allows you to switch between inline formulas and displayed equations.

InsertMathematicsEquations or ⌥&

This entry allows you to create an eqnarray*, a three columns wide table-like environment (see creating tables). This environment is typically used for lists of multiple relations like

The first column is centered to the right, the second one at the middle and the last one at the left. An other typical use of the eqnarray* environment is a step by step computation

in which many entries of the left column are left open.

2.Typing mathematical symbols

The Greek characters are obtained in TeXmacs using the F5-key. For instance, math:greek a yields and math:greek G yields . Similarly, F6, F7, F8 and ⇧F6 can be used in order to type bold, calligraphic, fraktur and blackboard bold characters. For instance, F8M yields , S-F6 R yields and F6F7⇧Z yields .

Greek characters can also be obtained as “variants” of Latin characters using the var-key. For instance, p var yields . The var-key is also used for obtaining variants of the Greek letters themselves. For instance, both math:greek p var and p var var yield . An alternative way to enter blackboard bold characters is to type the same capital twice. For instance, Z Z yields .

Some symbols admit many variants. For instance, < yields , < var yields , < var var yields , < var var var yields , and so on. You may “cycle back” among the variants using S-var. For instance, < var var S-var is equivalent to < var.

Many other mathematical symbols are obtained by “natural” key-combinations. For instance, - > yields , - - > yields and > = yields . Similarly, | var - yields , | - > yields and - > < - yields . The following general rules hold in order to enter mathematical symbols:

tab

is the main key for obtaining variants. For instance, > = yields , but > = var yields . Similarly, < var var yields , < var var = yields and < var var = var yields . Also, P var yields and e var yields the constant .

@

is used for putting symbols into circles or boxes. For instance, @ + yields and @ x yields . Similarly, @ var + yields .

/

is used for negations. For instance, = / yields and < = / yields . Notice that < = var var / yields , while < = var var / var yields .

!

is used after arrows in order to force scripts to be placed above or below the arrow. For instance, - - > ^ x yields , but - - > ! ^ x yields .

The logical relations and are obtained using & and %. The operators and are natural variants & var and % var. Various miscellaneous symbols can be optained using the ⇧F5 prefix.

Notice that certain symbols with a different mathematical meaning are sometimes denoted in a similar way; such symbols are called homoglyphs. For instance, the vertical bar can be used as a separator for defining sets , but also as the binary relation “divides” . Often, but not always, homoglyphs admit a different spacing. The most annoying ambiguity is between invisible multiplication and function application , which are entered using the shortcuts * resp. space.

In order to facilitate certain automated treatments of your documents, such as mathematical syntax checking, we incite authors to pay attention to the homoglyph problem when entering formulas. For more information on this issue and how TeXmacs can assist you to use the appropriate notations, we refer to our section on the semantics of mathematical symbols.

3.Main mathematical constructs

The main mathematical objects are created using the math prefix as follows:

Shortcut Purpose Example
math $ Text
math f Fractions
math s Square roots
math S -th Roots
math n Negations

Table 1. Creation of major mathematical markup.

Primes, subscripts and superscripts are created as follows:

Shortcut Purpose Example
' Primes or
Back-primes
_ Subscripts or
^ Superscripts , or
math l _ Left subscripts
math l ^ Left superscripts or

Table 2. Creation of primes, subscripts and superscripts

Some important mathematical constructs are actually tabular constructs and are documented separately.

4.Typing large delimiters

Brackets inside mathematical formulas should always match: as soon as you enter an opening bracket “(”, TeXmacs will automatically insert the matching closing bracket “)”. You may disable this feature using EditPreferencesKeyboardAutomatic bracketsDisable. Attention (see also below): brackets in old documents will be automatically be upgraded to matching brackets.

Sometimes, you do not want the closing bracket, or you may want to replace it by another closing bracket. No problem: if your cursor is just before the closing bracket inside , then pressing ] will turn the expression into . Alternatively, deletion of a bracket will actually turn it into an invisible bracket, after which you can replace it by an arbitrary opening or closing bracket.

By default, the sizes of the brackets are adjusted to the expression between the brackets. Small delimiters, which are created using the -prefix, keep their sizes independently of the enclosed expression. Alternatively, you may use ⌃* in order to toggle between large and small delimiters.

For some delimiters, such as , the opening and closing delimiters coincide. For instance, entering a vertical bar | will produce an absolute value. The (small) bar-separator is obtained using F5|, or as a variant using | var. The big bar-separator is entered using ⌥M|. In TeX and LaTeX, such large separators do not exist; they are used for producing the vertical bars in formulas like

There may be as many middle delimiters between a left and a right delimiter as one wishes. Notice that there are still another number of variants of vertical bars. For instance, the binary relation “divides” is entered using F5| or | var var var var.

In TeXmacs, large delimiters may either be “left delimiters”, “right delimiters” or “middle delimiters”. By default, and are left delimiters, and are right delimiters. But there status can be changed using the ⌥L, ⌥R and ⌥M key combinations. For instance, math:left ) produces , considered as a large left delimiter.

Sometimes you may want large delimiters of a particular size, instead of self-adjusting ones. This can be achieved by resizing the expression in between the brackets using the items in FormatAdjust.

Notice that it is possible to insert a pair of invisible brackets using ?. This is for instance useful in computational contexts, in which formulas should admit a precise, not merely visual semantics. Alternatively, one may put the formula inside a “rigid box” using ⌘⇧R, which additionally prevents the formula from being hyphenated.

5.Typing big operators

The following key-combinations are used in order to create big symbols:

Shortcut Result Shortcut Result
symbol I symbol O
symbol P symbol A
symbol S symbol @ +
symbol @ x symbol @ .
symbol U symbol N
symbol V symbol W

Table 3. Big mathematical operators.

The scopes of big operators are indicated visually, through the light cyan boxes around the tags which contain the cursor.

The big integral signs admit two variants, depending on where you want to place subscripts and superscripts. By default, the scripts are placed as follows:

The alternative rendering “with limits”

is obtained using symbol L I. Similarly, you may type symbol L O in order to obtain with limits.

6.Wide mathematical accents

The table below how to type mathematical accents above symbols or entire formulas. Indeed, some of these accents automatically become as wide as the formulas below them.

Shortcut Example Wide variant Shortcut Result
math ~ math '
math ^ math ‘
math B math .
math V math "
math C
math U

Table 4. Keyboard shortcuts for wide mathemarical accents.

The same accents may be inserted below the expressions using the ⌥U prefix. For instance, math:under B x + y can be used in order to enter .

7.Semantic editing facilities

Starting with version 1.0.7.10, TeXmacs incorporates several features for the “semantic” editing of mathematical formulas. When used appropriately, this allows you to write documents in which all formulas are at least correct from a syntactical point of view. For instance, in the formulas , the computer will understand that is an operator which applies to the arguments and . Notice that our “semantics” does not go any further: TeXmacs is unaware of the mathematical nature of addition.

Semantic editing does require additional efforts from the user, at least a little adaptation. For instance, it is the user's job to enter multiplications using the shortcut * and function applications using space. Indeed, from the graphical point of view, these operations cannot be distinguished, since they are both printed as invisible whitespace. However, the semantics of these operations is clearly very different.

Although semantically correct documents are usually not very different from informal presentation-oriented documents as far as typesetting is concerned, the additional user effort may pay off for several reasons:

Furthermore, other semantic facilities might be integrated in the feature, such as semantic search and replace, or semantic search on the web.

In order to activate the semantic editing facilities, please toggle EditPreferencesMathematicsSemantic editing. In the semantic editing mode, several of the structured editing features of TeXmacs apply to the syntactic structure of the formula, rather than the visual structure of the document. For instance, the semantic focus is usually a subformula of the current focus. Similarly, only syntactically meaningful subformulas can be selected when making a selection.

The semantic focus is useful for several reasons. First of all, it is displayed in green if the formula is syntactically correct and in red if you made an error. This allows to quickly notice any typos while entering a formula. Secondly, if you have any doubt on the precedence of a mathematical operator or relation, then the semantic focus will inform you on the default interpretation: by putting your cursor right next to your operator, the subexpression to which the operator applies will be highlighted. In the case of an addition, or a more general associative operator, all summands are highlighted.

8.Common errors and syntax correction

By default, the semantic editing mode “understands” most classical mathematical notations. This is achieved through the use of a carefully designed grammar for mainstream mathematics. Obviously, the use of a fixed grammar may cause the following problems:

Besides these intrinsically hard to avoid problems, the following common and “easy-to-make” mistakes are a further source of trouble for associating semantics to mathematical formulas:

After activation of the semantic editing mode, you may check whether a formula is correct by positioning your cursor inside it and looking at the color of the bounding box of the semantic focus: a green color corresponds to a correct formula and a red color indicates an error in the formula. Alternatively, assuming that the focus is on a mathematical formula, you may select FocusPreferencesHighlight incorrect formulas, in which all incorrect formulas are highlighted inside red boxes.

For the second kind of “easy-to-make” errors, TeXmacs includes an automatic syntax corrector. Assuming that your cursor is inside a formula, you may use EditCorrectCorrect all for the correction of all formulas in your document, or the correction of the current selection. If the versioning tool is activated, then you may use EditCorrectCorrect manually to show the differences between the original and the corrected versions. You may then use the versioning tool to go through these differences and select the preferred versions.

The precise algorithms which are used for the correction may be enabled or disabled from EditPreferencesMathematicsManual correction:

Remove superfluous invisible operators

This algorithm is used in order to remove any superfluous function applications or multiplications. For instance, users who are accustomed to editing ASCII files often type spaces around binary infixes such as addition. Such “function applications” will be removed by this algorithm.

Insert missing invisible operators

In LaTeX, multiplications and function applications are never entered explicitly. When importing a LaTeX document, it is therefore important to detect and insert missing multiplications and function applications.

Homoglyph substitutions

This algorithm may perform some other useful substitutions of symbols by visually similar, but semantically distinct symbols. For instance, the backslash symbol is replaced by the binary set differences infix (as in ), whenever appropriate.

From the EditPreferencesMathematicsAutomatic correction, you may also select those corrections algorithms which should be applied automatically whenever you open a file. The various corrections are always carried out when importing a LaTeX file.

After syntax correction, the remaining errors indicate genuine typos at worst or non standard or non supported notations at best. We also notice that “correct” formulas do not necessarily have the intended meaning. In order to check whether the operators indeed apply to the intended arguments, you should keep an eye on the current focus while typing your formulas.

9.Semantics of mathematical symbols

The mathematical symbols in TeXmacs all come with a certain number of properties which correspond to their intended meaning. For instance, TeXmacs is aware that is an infix operator, whereas ! is rather a postfix, and , a separator.

TeXmacs has special symbols , and for important mathematical constants, which display differently from the mere characters , and , and which can be entered using the shortcuts E, P and I. We recommend to systematically use these shortcuts.

Inversely, semantically distinct symbols may display in a similar way. For instance, the comma separator, as in , is different from the decimal comma, as in . Notice that the two symbols admit different spacing rules. Semantically distinct symbols which are rendered by the same glyph are called homoglyphs. Notice that our semantics is purely syntactic: for instance, the infix is commonly used for addition, but sometimes also for the concatenation of strings. Nevertheless, these two uses do not differ from a syntactical point of view, since the symbol remains a binary infix with the same precedence with respect to other symbols.

The most confusing homoglyphs are the various invisible symbols supported by TeXmacs:

Again it is recommended that authors carefully enter these various invisible symbols when appropriate. It is particularly important to distinguish between multiplication and function application, since there is no 100% safe automatic way to make this distinction (we already mentioned the formulas and before).

TeXmacs supports two quite general schemes for entering homoglyphs. On the one hand, we often rely on the standard variant system. For instance, and are obtained using * and *. When applicable, we also support the following convention: first type the character with a similar semantics and then type the character which corresponds to the rendering. This convention was already used above for the invisible homoglyphs, and often allows for shorter shortcuts. In table ? we have given the complete list of homoglyphs supported by TeXmacs.

Shortcut Glyph Example Semantics
* Multiplication
space Function application
, space Invisible separator
+ space Invisible addition
. space Invisible symbol
( space Invisible bracket(s)
| Absolute value
| var Separating bar
| var var Extensible middle bar
| var var var var Divides relation
, , Comma separator
, var , Decimal comma
. . Decimal point
. var . Dot connector
* var var var Dot multiplication
. var var Dummy widcard
\ var Backslash
\ var var Set minus
& Logical and
* & Wedge product

Table 5. Homoglyphs supported by TeXmacs.

10.Customized mathematical semantics

We have done our best to support most of the classical mathematical notations. Nevertheless, the user may sometimes want to define notations with a non standard semantics. Certain areas may also require special notations which are not supported by default.

TeXmacs provides a very simple syntax primitive, which allows the user to manually override the default syntactical semantics of a formula. Assuming that semantic editing was activated, you may insert the syntax primitive using ⌥XX or InsertSemanticsOther. The first argument contains the formula as it should be displayed, whereas the second argument contains the formula as it should be interpreted.

For instance, if we enter as the first argument and as the second one, then the will be interpreted as a binary relation, exactly in the same way as . Moreover, the spacing around will be adapted, so as to mimick the spacing around . In this particular example, we might have obtained the same result by using the math-relation primitive, which is equivalent to syntax with as its second argument. Most standard operator types are available from InsertSemantics, or using the ⌥X keyboard prefix. In particular, you may use ⌥XSpace to simply ignore a formula and ⌥XO in order to make the formula behave as an ordinary symbol (such as the letter “o”).

The syntax primitive is especially powerful when used in combination with the TeXmacs macro language. For instance, consider the formula . It is likely that the inteded interpretation of is and not . Therefore, if we often use the constant , then we might want to define a macro twopii by

<assign|twopii|<macro|<syntax||>>>

Such macros may be grouped together into a style package with the user's favourite notations. Future versions of TeXmacs might also provide style packages with notations dedicated to specific areas.

Let us finally notice that there are usually several ways for redefining the semantics of a formula. For instance, an alternative way to define the macro twopii is using

<assign|twopii|<macro|>>

where we inserted a pair of invisible brackets around . Similarly, in the formula

we may either select the whole formula and give it the semantics of an ordinary symbol, by pressing ⌥XO. However, a nicer solution is to only select the subformula , and give it the semantics of an ordinary symbol. Yet another example is the sign sequence mentioned earlier. This sequence can be interpreted correctly by inserting invisible separators between the different signs using the , space shortcut.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".