Interface WalkerInsertionMethods

Methods used to insert content into a document via a Walker. As with apply, the position of the walker will be updated to match the caret position after an insertion so that it is ready to insert more material.

Hierarchy

  • WalkerInsertionMethods

Index

Methods

clip

  • clip(clip: Clip): boolean
  • Inserts the contents of a clip.

    Parameters

    • clip: Clip

      The clip to be pasted.

    Returns boolean

    True if the insertion was possible.

element

  • element(symbol: string, asIsotope?: boolean): boolean
  • Inserts a new chemical element by symbol. This is an alternative to inserting them by their full name as objects.

    Example: Insert the symbol for gold.

    let walker = new micd.Walker(editor);
    walker.insert.element("Au");
    

    Parameters

    • symbol: string

      The symbol of an element in ChemistryObject.

    • Optional asIsotope: boolean

      If true, the element is inserted as an isotope object instead of a simple element.

    Returns boolean

identifier

  • identifier(symbol: string, dataType?: "string" | "boolean" | "matrix" | DataType | "scalar" | "set" | "point" | "vector" | "tensor" | "unit_name" | "constant_boolean" | "constant_scalar" | "constant_set" | "constant_vector"): boolean
  • Inserts an identifier at the current position. Unlike a variable, an identifier can consist of multiple letters (like a variable name in a computer program). The result is an identifier parent node with a single field containing a character node for each letter in the name.

    Parameters

    • symbol: string

      The identifier name.

    • Optional dataType: "string" | "boolean" | "matrix" | DataType | "scalar" | "set" | "point" | "vector" | "tensor" | "unit_name" | "constant_boolean" | "constant_scalar" | "constant_set" | "constant_vector"

      The data type of the identifier (default is scalar).

    Returns boolean

    True if the insertion was possible.

number

  • number(digits: string | number | bigint): boolean
  • Inserts a number at the current position. As the editor does not represent numbers as a single object, this will result in the insertion of one or more digit nodes (a radix point is considered a type of digit).

    This method will accept a string representation of a number, as well as JavaScript number or bigint values. To simplify working with external values, this method also handles some non-digit characters:

    • the +, -, ±, and characters will be inserted as operators;
    • the string Infinity will become an infinity symbol (∞);
    • scientific notation (marked by an e or E) will become ×10 followed by the relevant exponent;
    • space characters are ignored;
    • both . and , will be interpreted as radix points.

    Example: Insert a number using scientific notation

    let walker = new micd.Walker(editor);
    walker.insert.number("1.4e7");
    

    Parameters

    • digits: string | number | bigint

      The number to insert.

    Returns boolean

    True if the insertion was possible. This will return false if passed NaN or an invalid number (such as one with multiple radix points).

object

  • Inserts an editor object by name. This is similar to apply, except that it rejects general editing commands.

    Parameters

    • apiName: MathObject

      The name of the command that inserts the object.

    Returns boolean

    True if the insertion was possible.

  • Inserts an editor object by name. This is similar to apply, except that it rejects general editing commands.

    Parameters

    • apiName: ChemistryObject

      The name of the command that inserts the object.

    Returns boolean

    True if the insertion was possible.

operator

  • operator(symbol: string, placement?: OperatorPlacement | "infix" | "prefix" | "postfix" | "contextual"): boolean
  • Inserts a new operator. This can insert custom operators for which no command exists. If the operator has an existing command, it is recommended that it be inserted by command name as this ensures that the recommended Unicode character is used for its symbol.

    Example: Insert an asterisk operator

    let walker = new micd.Walker(editor);
    walker.insert.operator("\u2217", micd.OperatorPlacement.infix);
    

    Notes:

    1. Using custom operators may have unexpected results as the editor will not know how the operator is used and may not have suitable font glyphs for the requested symbol(s).
    2. Converting content with custom operator(s) to other formats may have unexpected results as the target format may not be able to represent the intended concept(s).
    3. Operators with the same symbol but different placements are considered to be distinct by the editor.

    Parameters

    • symbol: string

      A string, 1 to 24 code points in length, to be used as the operator's symbol.

    • Optional placement: OperatorPlacement | "infix" | "prefix" | "postfix" | "contextual"

      The operator's placement relative to its operand(s). If none is specified, a default is chosen based on the symbol.

    Returns boolean

    True if the insertion was possible.

style

  • style(color?: Color): boolean
  • Inserts a style object whose children will be rendered with the specified style.

    Example:

    let walker = new micd.Walker(editor);
    walker.insert.style(micd.Color.fromCss("powderblue"));
    walker.insert.variable("Φ", "constant_scalar");
    walker.insert.object(micd.EditorCommand.approximatelyEqualTo);
    walker.insert.number(1.61803398874)
    

    Parameters

    • Optional color: Color

      The color to apply to styled content.

    Returns boolean

    True if the insertion was possible.

text

  • text(text: string): boolean
  • Inserts a text annotation at the current position. If the current position is inside of an existing text annotation, the text is inserted into the existing annotation.

    Parameters

    • text: string

      The text content to insert.

    Returns boolean

    True if the insertion was possible.

variable

  • variable(symbol: string, dataType?: "string" | "boolean" | "matrix" | DataType | "scalar" | "set" | "point" | "vector" | "tensor" | "unit_name" | "constant_boolean" | "constant_scalar" | "constant_set" | "constant_vector", accent?: AccentType | "acute" | "bar" | "breve" | "check" | "dot" | "ddot" | "grave" | "hat" | "tilde"): boolean
  • Inserts a variable at the current position. A variable name (symbol) must consist of exactly one Unicode code point. Only certain code points are allowed, typically letters. Using standard unaccented letters from the Latin or Greek alphabet is strongly recommended as other letters may not render correctly, especially when exported. Combinations not typically seen in mathematical writing, such as a constant set named with a lower case Latin letter, may not render as expected.

    Unit names are composed of “variables” with the special data type "unit_name". If the current position is inside of a unit node, variables inserted with the default scalar variable data type will be silently converted to this type. Other data types will be rejected, returning false.

    Parameters

    • symbol: string

      The variable name, which must be exactly one letter.

    • Optional dataType: "string" | "boolean" | "matrix" | DataType | "scalar" | "set" | "point" | "vector" | "tensor" | "unit_name" | "constant_boolean" | "constant_scalar" | "constant_set" | "constant_vector"

      The data type of the variable (default is scalar).

    • Optional accent: AccentType | "acute" | "bar" | "breve" | "check" | "dot" | "ddot" | "grave" | "hat" | "tilde"

      The accent to place on the variable (default is none).

    Returns boolean

    True if the insertion was possible.

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