# editor/editableMathlist

This module contains the definition of a data structure representing a list of math atoms that can be edited. It is an in-memory representation of a mathematical expression whose elements, math atoms, can be removed, inserted or re-arranged. In addition, the data structure keeps track of a selection, which can be either an insertion point — the selection is then said to be collapsed — or a range of atoms.

### Methods

#### parseMathString(s: string)static

Attempts to parse and interpret a string in an unknown format, possibly ASCIIMath and return a canonical LaTeX string.

The format recognized are one of these variations:

• ASCIIMath: Only supports a subset (1/2x) 1/2sin x -> \frac {1}{2}\sin x 1/2sinx -> \frac {1}{2}\sin x (1/2sin x (x^(2+1)) // Unbalanced parentheses (1/2sin(x^(2+1)) -> \left(\frac {1}{2}\sin \left(x^{2+1}\right)\right) alpha + (pi)/(4) -> \alpha +\frac {\pi }{4} x=(-b +- sqrt(b^2 – 4ac))/(2a) alpha/beta sqrt2 + sqrtx + sqrt(1+a) + sqrt(1/2) f(x) = x^2 "when" x >= 0 AA n in QQ AA x in RR "," |x| > 0 AA x in RR "," abs(x) > 0

• UnicodeMath (generated by Microsoft Word): also only supports a subset

• "JavaScript Latex": a variant that is LaTeX, but with escaped backslashes \frac{1}{2} \sin x

s : string

#### arrayAdjustRow(array: Array.<Array.<MathAtom>>, colRow: object, dir: number)inner

Adjust colRow to point to the next/previous available row If no more rows, go to the next/previous column If no more columns, return null

array : Array.<Array.<MathAtom>>
colRow : object
dir : number

#### arrayCell(array: Array.<Array.<MathAtom>>, colrow: number | string | object)inner

Return the array cell corresponding to colrow or null (for example in a sparse array)

array : Array.<Array.<MathAtom>>
colrow : number | string | object

#### arrayCellCount(array: Array.<Array.<MathAtom>>)inner

Total numbers of cells (include sparse cells) in the array.

array : Array.<Array.<MathAtom>>

#### arrayColRow(array: Array.<Array.<MathAtom>>, index: number | string): objectinner

Convert an array index (scalar) to an array row/col.

array : Array.<Array.<MathAtom>>
index : number | string
: object
• row: number
• col: number

#### arrayColumnCellCount(array: MathAtom, col: number): numberinner

Return the number of non-empty cells in that column

array
col : number
: number

#### arrayFirstCellByRow(array: Array.<Array.<MathAtom>>): stringinner

Return the first non-empty cell, row by row

array : Array.<Array.<MathAtom>>
: string

#### arrayIndex(array: Array.<Array.<MathAtom>>, rowCol: object): numberinner

Convert an array row/col into an array index.

array : Array.<Array.<MathAtom>>
rowCol : object
: number

#### arrayJoinColumns(row: MathAtom[], separator: string, style: object): MathAtom[]inner

Join all the cells at the indicated row into a single mathlist

row : MathAtom[]
separator : string
style : object
: MathAtom[]

#### arrayJoinRows(array: MathAtom, separators: strings, style: object): MathAtom[]inner

Join all the rows into a single atom list

array
separators : strings
style : object
: MathAtom[]

#### arrayRemoveColumn(array: MathAtom, col: number)inner

Remove the indicated column from the array

array
col : number

#### arrayRemoveRow(atom: MathAtom, row: number)inner

Remove the indicated row from the array

atom
row : number

#### atomContains(atom: MathAtom, target: MathAtom): booleanprivateinner

atom
target
: boolean

True if atom is the target, or if one of the children of atom contains the target

#### isNumber(atom: object)inner

Return true if the atom could be a part of a number i.e. "-12354.568"

atom : object

#### parseMathArgument(s: string): objectinner

Parse a math argument, as defined by ASCIIMath and UnicodeMath:

• Either an expression fenced in (), {} or []
• a number (- sign, digits, decimal point, digits)
• a single [a-zA-Z] letter (an identifier)
• a multi-letter shortcut (e.g., pi)
• a LaTeX command (\pi) (for UnicodeMath)
s : string
: object
• match: the parsed (and converted) portion of the string that is an argument
• rest: the raw, unconverted, rest of the string