![]() |
Text and mathematics | ![]() |
Text mode is implemented in
progs/text/
. Its predicate in-text? holds when the environment variable mode is text and the cursor is not in a graphics; many definitions are further restricted to the standard styles (in-std-text?) or to a language (in-french?, in-cyrillic?, …).
text/text-drd.scm
declares the groups which the editing routines test: section-tag and section*-tag, list-tag with its subgroups itemize-tag, enumerate-tag and description-tag, enunciation-tag (theorem-tag, definition-tag, …), doc-title-tag and author-data-tag, frame-tag, the variant-tag and numbered-tag groups used by variant-circulate and numbered-toggle, and others. New list environments defined by a document are registered at run time with tm-register-new-list-tag, which adds them to the new-list-tag group.
text/text-edit.scm
defines, for each kind of markup, a context predicate, the commands used by the menus and keyboard, and the redefinitions of the generic hooks:
The doc-data and author-data blocks: make-doc-data, make-doc-data-element, make-author-data-element, the activation and deactivation of hidden title fields (doc-data-activate-all, …). ↩ in a title adds an author, in an author name adds an affiliation, and in the keyword and classification fields of an abstract adds a new field.
section-context?, make-section (which turns a one paragraph selection into the title), make-unnamed-section, go-to-section-title. ↩ in a section title leaves the title.
text/text-structure.scm
contains the routines which analyse the section structure of a document, used for instance to split a document into parts.
list-context?, make-tmlist, make-item. ↩ in a list inserts a new item (of the right kind for itemize, enumerate or description lists), ⇧↩ a plain paragraph; numbered-toggle switches between itemize and enumerate; standard-parameters and parameter-choice-list give the parameters of the focus menu (item tags, levels).
Context predicates (enunciation-context?, algorithm-context?, frame-context?, float-context?, …), toggles for names, numbers and titles (algorithm-toggle-name, titled-toggle-name, frame-toggle-title, …), the conversion between floating and non floating forms (turn-floating, turn-non-floating) and the customizable-parameters of the decorated environments.
make-equation, make-equation*, make-eqnarray* and the focus-label of numbered equations; the editing inside equations belongs to math mode.
In text mode, kbd-space-bar implements the text spacebar preference: a second space is ignored, or turned into a wider space.
text/text-kbd.scm
contains the text shortcuts: special symbols (quotes, dashes, …), font dependent and Greek symbols, language specific blocks (conditioned on in-cyrillic?, in-spanish?, in-polish?, …), overrides for verbatim text and for references (in-verbatim?, in-variants-disabled?) and paragraph alignment shortcuts; the input methods for Chinese, Cyrillic and Vietnamese are in the subdirectories of text/.
text/text-menu.scm
defines text-format-menu (in a full and a compressed form, according to the preferences), text-icons and text-format-icons, the menus for sections, lists, enunciations, floats and notes, and redefinitions of the focus menus for document titles, authors, abstracts, sections and floats. text/text-speech*.scm define speech commands.
Math mode is implemented in
progs/math/
. Besides in-math?, the main modes are in-math-or-hybrid?, in-math-not-hybrid? (the hybrid command line, entered with the backslash key, behaves partially as math), in-math-in-session?, the language variants (in-math-english?, in-math-french?, …) and the semantic mode in-sem-math?.
math/math-drd.scm
declares fraction-tag, vertical-script-tag (above, below), textual-operator-tag and the math-annotation-tag group of the semantic annotations (math-relation, math-ordinary, …), and declares the alternates wide/wide* and around/around*.
math/math-kbd.scm
is the largest keyboard file of TeXmacs (about 2600 lines). It consists of kbd-map blocks conditioned on in-math?, in-math-or-hybrid?, in-math-not-hybrid? and the language modes, and binds ordinary characters and their variants (A followed by ⇥ gives \(\alpha\)), brackets, scripts, fractions, big operators and symbols, often through symbolic prefixes such as math:small, math:left or math:greek, which are resolved by the wildcards of
texmacs/keyboard/prefix-kbd.scm
. Before the keymaps, it redefines disable-pre-edit? and downgrade-pre-edit for math mode, so that accented characters produced by the input method of the system are turned into plain letters.
math/math-edit.scm
contains
kbd-space-bar implements the math spacebar preference; kbd-insert removes a space typed just before an infix, postfix or closing symbol.
↩ in math, equation and equation* leaves the formula; the variants of formulas and equations (variant-formula, variant-equation, and variant-circulate on math and equations) switch between inline and displayed mathematics, and equation->eqnarray and eqnarray->equation between single equations and equation arrays.
Context predicates and variants for lsub, rsup, … (script-context?), for roots (sqrt-toggle) and for wide accents.
math-bracket-open, math-bracket-close and math-separator are bound to the bracket keys. With the automatic brackets preference (the default), opening a bracket inserts a matching pair (around or around*, according to the use large brackets preference), closing a bracket fills a missing bracket of an adjacent pair or moves after it, and a selection is wrapped in the new pair. Without it, single left, mid and right brackets are inserted and brackets-refresh rebuilds the pairs around the cursor. variant-circulate changes the shape of a bracket and geometry-vertical its size.
math-correct-all and math-correct-manually apply the kernel routine manual-correct (see
Data/Tree/tree_correct.cpp
) to the selected formula or the whole document; the manual variant shows the changes as a version comparison.
math/math-sem-edit.scm
is loaded (lazily, for the mode in-sem-math?). It wraps kbd-insert, make, kbd-backspace, kbd-delete, the space keys and several insertion commands with former, so that each edit is checked against the mathematical grammar:
the formula around the cursor is tested with packrat-correct? on the grammar std-math, using the rule Main for displayed formulas, Cell in table cells and Strict otherwise;
the macro try-correct tries a list of alternative ways of performing the edit, each inside try-modification, and keeps the first one which leaves the formula correct;
missing operands are represented by suppressed placeholders ((suppressed (tiny-box))), which are added and removed automatically around the cursor.
math/math-menu.scm
defines math-format-menu, math-icons, math-insert-icons and the focus menus for formulas, equations and scripts.
math/math-speech.scm
and the language files
math-speech-en.scm
,
math-speech-fr.scm
,
math-adjust-en.scm
and
math-adjust-fr.scm
implement speech input for formulas;
math/math-stats.scm
analyses the statistical properties of the formulas of a document. The math versus text decision for a single tree is made by the DRD (tree-child-env, see the DRD from Scheme).