Mathematical formulas 
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.
TeXmacs provides three main ways in order to enter a mathematical formulas into the main text:
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
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.
This entry allows you to create an
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
in which many entries of the left column are left open.
The Greek characters are obtained in TeXmacs using the F5key. 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 , SF6 R yields and F6F7⇧Z yields .
Greek characters can also be obtained as “variants” of Latin characters using the varkey. For instance, p var yields . The varkey 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 Svar. For instance, < var var Svar is equivalent to < var.
Many other mathematical symbols are obtained by “natural” keycombinations. For instance,  > yields ,   > yields and > = yields . Similarly,  var  yields ,   > yields and  > <  yields . The following general rules hold in order to enter mathematical symbols:
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.
The main mathematical objects are created using the math prefix as follows:



Primes, subscripts and superscripts are created as follows:



Some important mathematical constructs are actually tabular constructs and are documented separately.
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
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) barseparator is obtained using F5, or as a variant using  var. The big barseparator 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 selfadjusting ones. This can be achieved by resizing the
expression in between the brackets using the items in
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.
The following keycombinations are used in order to create big symbols:



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



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 .
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 presentationoriented documents as far as typesetting is concerned, the additional user effort may pay off for several reasons:
Documents with more semantics are for instance useful when using formulas as inputs for a computer algebra system.
Syntactically correct documents are less likely to contain “typos” or more intricate mathematical errors.
For certain editing operations, such as cut and paste, one may directly select subformulas which are meaningful from the syntactical point of view.
It reduces the risk of using non standard notations, which will be difficult to understand for potential readers of your work.
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
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.
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:
Mathematical formulas frequently contain ad hoc notations. For instance, the formulas might contain some text or meaningful whitespace. Another example of an ad hoc notation is the sign sequence . In such cases, the user should explicitly annotate the appropriate parts of the formula in order to make them semantically meaningful.
The TeXmacs grammar used for the interpretation of mathematical formulas may be incomplete or inadequate for certain situations. It is possible to customize or extend the grammar using the standard TeXmacs macro mechanism. Notations for specific areas may be grouped together in dedicated style packages.
Besides these intrinsically hard to avoid problems, the following common and “easytomake” mistakes are a further source of trouble for associating semantics to mathematical formulas:
Since TeXmacs is a wysiwyg editor, some of the structure of the document is invisible for the user. For instance, the presence of a mathematical formula is indicated through the use of an italic slant and special spacing. However, in the formula it is easy to type the closing bracket outside the formula, with no visual difference.
Various mathematical notations are visually ambiguous. For instance, would usually be understood as , whereas rather corresponds to a function application. In the semantic editing mode, the user is expected to resolve this ambiguity by hand by entering multiplications using * and spaces using space. The multiply/apply ambiguity is one of the main sources of syntax errors, since many users do not pay attention to invisible differences. Similarly, the glyph could be the “logical and” or the “wedge product”. This “homoglyph” issue will be adressed in more detail in the section on the semantics of mathematical symbols.
It could be that a text was originally written in LaTeX or an old version of TeXmacs. In that case, the document contains no special indication on matching brackets or the scopes of big operators. For instance, in the formula , should we interpret the second bracket as a closing bracket? This is indeed the standard french notation for an interval with an open right end. More generally, all problems that we have mentioned so far tend to be present simultaneously when trying to associate semantics to existing documents.
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
For the second kind of “easytomake” errors, TeXmacs
includes an automatic syntax corrector. Assuming that your cursor is
inside a formula, you may use
The precise algorithms which are used for the correction may be
enabled or disabled from
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.
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.
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
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.
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:
The multiplication, entered by *. Example: .
Function application, entered by space. Example: .
An invisible separator, entered by ,Space. Example: the matrix .
An invisible addition, entered by +Space. Example: .
An invisible symbol, entered by .Space. Example: the increment .
An invisible bracket (mainly for internal use). A matching pair of invisible brackets is entered using ( space.
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.



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
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
The
<assigntwopii<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
<assigntwopii<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.