Fork me on GitHub

MathField

MathField

new MathField(element: Element, config: Object)

Note

  • Method names that begin with an underbar _ are private and meant to be used only by the implementation of the class.
  • Method names that end with an underbar _ are selectors. They can be invoked by calling the perform() function of a MathField object. Note that the selector name does not include the underbar.

For example:

   mf.perform('selectAll');
element Element
config Object

See MathLive.makeMathField() for details

Properties
element Element

The DOM element this mathfield is attached to.

config Object

A key/value/pair object that includes options customizing the behavior of the mathfield

id string

A unique ID identifying this mathfield

keystrokeCaptionVisible boolean

True if the keystroke caption panel is visible

Source

Methods

_getCaretPosition()private

Return the (x,y) client coordinates of the caret

Source

_onKeystroke(keystroke: string, evt: Event)private

keystroke string
evt Event

optional, an Event corresponding to the keystroke

Source

complete_()private

Completes an operation in progress, for example when in command mode, interpret the command

Source

el() → Element

Return the DOM element associated with this mathfield.

Element   
Source

enterCommandMode_()private

Source

insert(s: string)

This function can be invoked as a selector with perform() or called explicitly. It will insert the specified block of text at the current selection point, according to the insertion mode specified. After the insertion, the selection will be set according to the selectionMode.

s string

The text to be inserted

options.selectionMode string

Describes where the selection will be after the insertion:

  • 'placeholder': the selection will be the first available placeholder in the item that has been inserted) (default)
  • 'after': the selection will be an insertion point after the item that has been inserted),
  • 'before': the selection will be an insertion point before the item that has been inserted) or 'item' (the item that was inserted will be selected).

options.format string

The format of the string s:

  • 'auto': the string is interpreted as a latex fragment or command) (default)
  • 'latex': the string is interpreted strictly as a latex fragment

options.focus boolean

If true, the mathfield will be focused

options.feedback boolean

If true, provide audio and haptic feedback

Source

keystroke(keys: string, evt: Event)

keys string

A string representation of a key combination. For example 'Alt-KeyU'. See https://www.w3.org/TR/2012/WD-DOM-Level-3-Events-20120614/#fixed-virtual-key-codes

evt Event
Source

latex(text: string) → string

If text is not empty, sets the content of the mathfield to the text interpreted as a LaTeX expression. If text is empty (or omitted), return the content of the mahtfield as a LaTeX expression.

text string
string   
Source

perform(command: string)

command string

A selector

Source

perform(command: string,Array.<string>)

command string | Array.<string>

A selector and its parameters

Source

render()private

Lay-out the math field and generate the DOM.

This is usually done automatically, but if the font-size, or other geometric attributes are modified, outside of MathLive, this function may need to be called explicitly.

Source

revertToOriginalContent()

Revert this math field to its original content. After this method has been called, no other methods can be called on the MathField object. To turn the element back into a MathField, call MathLive.makeMathField() on the element again to get a new math field object.

Source

selectedText(formatopt: string) → string

Return a textual representation of the selection in the mathfield.

format string optional = 'latex'

One of

  • 'latex'
  • 'latex-expanded' : all macros are recursively expanded to their definition
  • 'spoken'
  • 'mathML'

string   
Source

selectionAtEnd() → boolean

Return true if the selection extends to the end of the selection group.

boolean   
Source

selectionAtStart() → boolean

Return true if the selection starts at the beginning of the selection group.

boolean   
Source

selectionDepth() → integer

Return the depth of the selection group. If the selection is at the root level, returns 0. If the selection is a portion of the numerator of a fraction which is at the root level, return 1. Note that in that case, the numerator would be the "selection group".

integer   
Source

selectionIsCollapsed() → boolean

Return true if the length of the selection is 0, that is, if it is a single insertion point.

boolean   
Source

setConfig(confopt: Object)

conf Object optional

See MathLive.config() for details

Source

text(formatopt: string) → string

Return a textual representation of the mathfield.

format string optional = 'latex'

One of

  • 'latex'
  • 'latex-expanded' : all macros are recursively expanded to their definition
  • 'spoken'
  • 'mathML' or 'mathML'.

string   
Source

typedText(text: string)

Simulate a user typing the keys indicated by text.

text string

A sequence of one or more characters.

Source