Interface Node

A node represents a single mathematical object in the document structure, such as a variable, a digit, or parentheses.

Complex nodes have one or more Fields, which are lists of child nodes. Each field represents a contiguous semantic subpart of the object. For example, a node representing a fraction would have two fields: one representing the numerator, and one representing the denominator. (The order of fields matches the order that the caret would move through them in the editor when repeatedly pressing the Enter key.)

Nodes are read-only reflections of the underlying content: modifying them has no effect on the document. To modify the document, use the Walker to insert, delete, and apply commands.

Example: Print the type of node under the caret

editor.apply(micd.MathObject.absoluteValue);
editor.apply(micd.EditorCommand.moveLeft);
let w = new micd.Walker(editor);
w.moveTo.caret();
console.log(w.node?.type);

Hierarchy

  • Node

Index

Properties

Optional Readonly accent

accent: AccentType

For variables, the type of accent shown over the variable, if any. Note that while vector variables may have an arrow accent, this is generated automatically based on the data type. If a variable has no user-specified accent, this will be null.

Readonly baseType

baseType: string

A more general description of the node type. For example, the "plus" type has base type "operator".

Readonly category

category: string

A description of the mathematical category of the node type, such as "Arithmetic" or "Calculus". This generally matches the name of the section where the corresponding command would be found in a generated help table.

see

createHelpTable

Optional Readonly cellInParent

cellInParent: [number, number]

For nodes whose parent is a tabular node, this is an array of two numbers indicating the row and column of the table cell in the parent.

Optional Readonly dataType

dataType: DataType

For variables and identifiers, the data type.

Optional Readonly effectivePlacement

effectivePlacement: OperatorPlacement

For operators, the effective placement after context is considered. If an operator's placement is contextual, this property will specify its effective placement after taking context into account.

Optional Readonly heightGrows

heightGrows: boolean

If this node is a tabular node, returns whether it automatically inserts a new row when content is placed in the last row. The size of a tabular node does not include such rows.

Optional Readonly implicitOperatorThatFollows

implicitOperatorThatFollows: "plus" | "timesDot"

If there is an implicit operation between this node and the node after it, this describes the node type of that operator. For example, there is an implied multiplication between 2 and x in the expression 2x. In this case, in the node for the digit 2 would, this property would be equal to "timesDot".

Readonly numFields

numFields: number

Returns the number of fields in the node. This will be 0 if the node is a leaf that cannot contain child nodes.

see

field

Readonly parent

parent: Node

This node's parent node, or null if it does not have a parent. A child node occurs exactly once in one of the fields of its parent.

Optional Readonly placement

For operators, the operator's placement relative to its operand(s).

Optional Readonly relativePosition

relativePosition: [Node, number, number]

For nodes that have a parent, this is a description of the position of the node relative to its parent, consisting of the parent node, the field in which this node is found in the parent, and the offset from the start of that field at which the node is found.

Readonly root

root: Node

The ancestor of this node that has no parent. This is normally a node of type "documentRoot" unless the node is no longer in a document. If the node has no parent, then the root is the node itself.

Readonly size

size: [number, number]

If this node is a tabular node, returns the table size as an array giving the number of rows and columns respectively. Note that special columns or rows that expand the node's size are not counted. For example, a 2 × 4 matrix will return a size of [2,4] and not [3,5].

see

widthGrows

see

heightGrows

Optional Readonly symbol

symbol: string

For operators, variables, identifiers, or chars, the letter(s) and/or mathematical symbol(s) that represent the object.

Optional Readonly symbolAbove

symbolAbove: string

Some operators consist of a vertical stack of symbols. For such operators, this is the symbol that appears above the primary symbol.

Optional Readonly text

text: string

For text, identifiers, and string literals, returns the character nodes in the child field combined into a single string for convenience.

Readonly type

type: string

The specific node type. Where possible, this matches the relevant API name.

Optional Readonly widthGrows

widthGrows: boolean

If this node is a tabular node, returns whether it automatically inserts a new column when content is placed in the last column. The size of a tabular node does not include such columns.

Methods

cell

  • cell(row: number, col: number): Field
  • If this node is a tabular node, returns the field that represents the specified row and column of the table.

    Parameters

    • row: number

      The table row to get the field of.

    • col: number

      The table column to get the field of.

    Returns Field

    The field of the specified row and column, or null if the node is not tabular or no such cell exists.

childAt

  • childAt(fieldNum: number, index: number): Node
  • Returns the node at the specified index in the specified field. This is equivalent to field(fieldNum).nodeAt(index).

    Parameters

    • fieldNum: number

      The number of the field to retrieve.

    • index: number

      The index of the desired child node in the field.

    Returns Node

    The requested node, or null if no such node exists.

field

  • field(fieldNum: number): Field
  • Returns the specified field of the node. Fields are numbered from 0 to numFields-1. The order of fields in a node corresponds to the order in which they are visited by moving through the node with the forwardEnter command.

    Parameters

    • fieldNum: number

      The number of the field to retrieve.

    Returns Field

    The requested field, or null if no such field exists.

findChild

  • findChild(target: Node): [number, number]
  • If the target node is an immediate child of this node, returns a number array containing the field number containing the target, and the index of the target within that field. Otherwise, returns null if the node is not an immediate child.

    see

    relativePosition

    Parameters

    • target: Node

      The node to search for.

    Returns [number, number]

    The location of the target in this node's fields, or null.

This API is still under development and is subject to change. Copyright © Math I Can Do Solutions Incorporated and/or its licensors.