new MathAtom(mode: string, type: string, body: string | MathAtom[], style?: [string]:any): MathAtomprivate
An atom is an object encapsulating an elementary mathematical unit, independent of its graphical representation.
It keeps track of the content, while the dimensions, position and style
are tracked by Span objects which are created by the decompose()
functions.
mode
:
string
type
:
string
body
:
string
|
MathAtom[]
style
:
[string]:any
= {}
A set of additional properties to append to the atom
Properties
mode
:
string
'display'
, 'command'
, etc...
type
:
string
Type can be one of:
mord
: ordinary symbol, e.g.x
,\alpha
textord
: ordinary charactersmop
: operators, including special functions,\sin
,\sum
,\cap
.mbin
: binary operator:+
,*
, etc...mrel
: relational operator:=
,\ne
, etc...mpunct
: punctuation:,
,:
, etc...mopen
: opening fence:(
,\langle
, etc...mclose
: closing fence:)
,\rangle
, etc...minner
: special layout cases, overlap,\left...\right
In addition to these basic types, which correspond to the TeX atom types, some atoms represent more complex compounds, including:
space
andspacing
: blank space between atomsmathstyle
: to change the math style used:display
ortext
. The layout rules are different for each, the latter being more compact and intended to be incorporated with surrounding non-math text.root
: a group, which has no parent (only one per formula)group
: a simple group of atoms, for example from a{...}
sizing
: set the size of the font usedrule
: draw a line, for the\rule
commandline
: used by\overline
and\underline
commandsbox
: a border drawn around an expression and change its background coloroverlap
: display a symbol over anotheroverunder
: displays an annotation above or below a symbolarray
: a group, which has children arranged in rows. Used by environments such asmatrix
,cases
, etc...genfrac
: a generalized fraction: a numerator and denominator, separated by an optional line, and surrounded by optional fencessurd
: a surd, aka rootleftright
: used by the\left
and\right
commandsdelim
: some delimitersizeddelim
: a delimiter that can grow
The following types are used by the editor:
command
indicate a command being entered. The text is displayed in blue in the editor.error
: indicate a command that is unknown, for example\xyzy
. The text is displayed with a wavy red underline in the editor.placeholder
: indicate a temporary item. Placeholders are displayed as a dashed square in the editor.first
: a special, empty, atom put as the first atom in math lists in order to be able to position the caret before the first element. Aside from the caret, they display nothing.
body
:
string
|
MathAtom[]
superscript
:
MathAtom[]
subscript
:
MathAtom[]
numer
:
MathAtom[]
denom
:
MathAtom[]
captureSelection
:
boolean
if true, this atom does not let its
children be selected. Used by the \enclose
annotations, for example.
skipBoundary
:
boolean
if true, when the caret reaches the first position in this element's body, it automatically moves to the outside of the element. Conversely, when the caret reaches the position right after this element, it automatically moves to the last position inside this element.
Methods
toSpeakableText(atoms?: MathAtom[], options?: [string]:any)static
atoms
:
MathAtom[]
The atoms to represent as speakable text.
If omitted, this
is used.
options
:
[string]:any
bind(context: Context, span: Span)
Add an ID attribute to both the span and this atom so that the atom can be retrieved from the span later on (e.g. when the span is clicked on)
context
:
Context
span
:
Span
decompose(context: Context, phantomBase?: Span[]): Span[]
Return a representation of this, but decomposed in an array of Spans
phantomBase
:
Span[]
= null
If not null, the spans to use to calculate the placement of the supsub
decomposeGenfrac()
Gengrac -- Generalized fraction
Decompose fractions, binomials, and in general anything made of two expressions on top of each other, optionally separated by a bar, and optionally surrounded by fences (parentheses, brackets, etc...)
Depending on the type of fraction the mathstyle is either display math or inline math (which is indicated by 'textstyle'). This value can also be set to 'auto', which indicates it should use the current mathstyle
decomposeLeftright()
\left....\right
Note that we can encounter malformed \left...\right, for example a \left without a matching \right or vice versa. In that case, the leftDelim (resp. rightDelim) will be undefined. We still need to handle those cases.
decomposeLine()
\overline and \underline
decomposeRule()
\rule
filter(): MathAtom[]
Iterate over all the child atoms of this atom, this included, and return an array of all the atoms for which the predicate callback is true.
makeSpan(context: Context, body: string | Span[]): Span
Create a span with the specified body and with a class attribute equal to the type ('mbin', 'inner', 'spacing', etc...)
context
:
Context
body
:
string
|
Span[]
toAST(): object
Return an AST representation of a single atom
toLatex(expandMacro: boolean): string
Return a LaTeX representation of the atom.
expandMacro
:
boolean
If true, macros are fully expanded. This will no longer round-trip.