Return an array of LaTeX syntax errors, if any.
If the Compute Engine library is available, return a boxed MathJSON expression representing the value of the mathfield.
To load the Compute Engine library, use:
import 'https://unpkg.com/@cortex-js/compute-engine?module';
The content of the mathfield as a LaTeX expression.
document.querySelector('mf').value = '\\frac{1}{\\pi}'
Update the style (color, bold, italic, etc...) of the selection or sets the style to be applied to future input.
If there is no selection and no range is specified, the style will apply to the next character typed.
If a range is specified, the style is applied to the range, otherwise, if there is a selection, the style is applied to the selection.
If the operation is "toggle" and the range already has this style,
remove it. If the range
has the style partially applied (i.e. only some sections), remove it from
those sections, and apply it to the entire range.
If the operation is "set", the style is applied to the range,
whether it already has the style or not.
The default operation is "set".
Return a textual representation of the content of the mathfield.
Optionalformat: OutputFormatThe format of the result. If using math-json
the Compute Engine library must be loaded, for example with:
import "https://unpkg.com/@cortex-js/compute-engine?module";
Default: "latex"
Return the value of the mathfield from start to end
Optionalformat: OutputFormatReturn the value of the mathfield in range
Optionalformat: OutputFormatInsert a block of text at the current insertion point.
This method can be called explicitly or invoked as a selector with
executeCommand("insert").
After the insertion, the selection will be set according to the
options.selectionMode.
Optionaloptions: InsertOptionsSet the content of the mathfield to the text interpreted as a LaTeX expression.
Optionalvalue: stringOptionaloptions: InsertOptionsMap a color name as used in commands such as \textcolor{}{} or
\colorbox{}{} to a CSS color value.
Use this option to override the standard mapping of colors such as "yellow" or "red".
If the name is not one you expected, return undefined and the default
color mapping will be applied.
If a backgroundColorMap() function is not provided, the colorMap()
function will be used instead.
If colorMap() is not provided, default color mappings are applied.
The following color names have been optimized for a legible foreground and background values, and are recommended:
red, orange, yellow, lime, green, teal, blue, indigo,
purple, magenta, black, dark-grey, grey, light-grey, whiteThe mode of the element when it is empty:
"math": equivalent to \displaystyle (display math mode)"inline-math": equivalent to \inlinestyle (inline math mode)"text": text modeIf "auto" a popover with commands to edit an environment (matrix)
is displayed when the virtual keyboard is displayed.
Default: "auto"
Control the letter shape style:
letterShapeStyle |
xyz | ABC | αβɣ | ΓΔΘ |
|---|---|---|---|---|
iso |
it | it | it | it |
tex |
it | it | it | up |
french |
it | up | up | up |
upright |
up | up | up | up |
(it) = italic (up) = upright
The default letter shape style is auto, which indicates that french
should be used if the locale is "french", and tex otherwise.
(Historical Note)
Where do the "french" rules come from? The TeX standard font, Computer Modern, is based on Monotype 155M, itself based on the Porson greek font which was one of the most widely used Greek fonts in english-speaking countries. This font had upright capitals, but slanted lowercase. In France, the traditional font for greek was Didot, which has both upright capitals and lowercase.
A dictionary of LaTeX macros to be used to interpret and render the content.
For example, to add a new macro to the default macro dictionary:
mf.macros = {
...mf.macros,
smallfrac: '^{#1}\\!\\!/\\!_{#2}',
};
Note that ...mf.macros is used to keep the existing macros and add to
them.
Otherwise, all the macros are replaced with the new definition.
The code above will support the following notation:
\smallfrac{5}{16}
The LaTeX string to insert when the spacebar is pressed (on the physical or virtual keyboard).
Use "\;" for a thick space, "\:" for a medium space, "\," for a
thin space.
Do not use " " (a regular space), as whitespace is skipped by LaTeX
so this will do nothing.
Default: "" (empty string)
Set the minimum relative font size for nested superscripts and fractions. The value
should be a number between 0 and 1. The size is in releative em units relative to the
font size of the math-field element. Specifying a value of 0 allows the math-field
to use its default sizing logic.
Default: 0
The symbol used to represent a placeholder in an expression.
Default: â–¢ U+25A2 WHITE SQUARE WITH ROUNDED CORNERS
If "auto" a popover with suggestions may be displayed when a LaTeX
command is input.
Default: "auto"
TeX registers represent "variables" and "constants".
Changing the values of some registers can modify the layout of math expressions.
The following registers might be of interest:
thinmuskip: space between items of math listsmedmuskip: space between binary operationsthickmuskip: space between relational operatorsnulldelimiterspace: minimum space to leave blank in delimiter constructions, for example around a fractiondelimitershortfall: maximum space to overlap adjacent elements when a delimiter is too shortjot: space between lines in an array, or between rows in a multiline constructarraycolsep: space between columns in an arrayarraystretch: factor by which to stretch the height of each row in an arrayTo modify a register, use:
mf.registers.arraystretch = 1.5;
mf.registers.thinmuskip = { dimension: 2, unit: "mu" };
mf.registers.medmuskip = "3mu";
If true, extra parentheses around a numerator or denominator are
removed automatically.
Default: true
This option controls how many levels of subscript/superscript can be entered. For
example, if scriptDepth is "1", there can be one level of superscript or
subscript. Attempting to enter a superscript while inside a superscript will
be rejected. Setting a value of 0 will prevent entry of any superscript or
subscript (but not limits for sum, integrals, etc...)
This can make it easier to enter equations that fit what's expected for the domain where the mathfield is used.
To control the depth of superscript and subscript independently, provide an
array: the first element indicate the maximum depth for subscript and the
second element the depth of superscript. Thus, a value of [0, 1] would
suppress the entry of subscripts, and allow one level of superscripts.
When true and an open fence is entered via typedText() it will
generate a contextually appropriate markup, for example using
\left...\right if applicable.
When false, the literal value of the character will be inserted instead.
When true, during text input the field will switch automatically between
'math' and 'text' mode depending on what is typed and the context of the
formula. If necessary, what was previously typed will be 'fixed' to
account for the new info.
For example, when typing "if x >0":
| Type | Interpretation |
|---|---|
i |
math mode, imaginary unit |
if |
text mode, english word "if" |
if x |
all in text mode, maybe the next word is xylophone? |
if x > |
"if" stays in text mode, but now "x >" is in math mode |
if x > 0 |
"if" in text mode, "x > 0" in math mode |
Default: false
Manually switching mode (by typing alt/option+=) will temporarily turn
off smart mode.
Examples
slope = rise/runIf x > 0, then f(x) = sin(x)x^2 + sin (x) when x > 0When x<0, x^{2n+1}<0Graph x^2 -x+3 =0 for 0<=x<=5Divide by x-3 and then add x^2-1 to both sidesGiven g(x) = 4x – 3, when does g(x)=0?Let D be the set {(x,y)|0<=x<=1 and 0<=y<=x}\int\_{the unit square} f(x,y) dx dyFor all n in NNWhen true and a digit is entered in an empty superscript, the cursor
leaps automatically out of the superscript. This makes entry of common
polynomials easier and faster. If entering other characters (for example
"n+1") the navigation out of the superscript must be done manually (by
using the cursor keys or the spacebar to leap to the next insertion
point).
When false, the navigation out of the superscript must always be done
manually.
Remove the focus from the mathfield (will no longer respond to keyboard input).
Sets the focus to the mathfield (will respond to keyboard input).
Return true if the mathfield is currently focused (responds to keyboard input).
This hooks is invoked when the user has requested to export the content of the mathfield, for example when pressing ctrl/command+C.
This hook should return as a string what should be exported.
The range argument indicates which portion of the mathfield should be
exported. It is not always equal to the current selection, but it can
be used to export a format other than LaTeX.
By default this is:
return `\\begin{equation*}${latex}\\end{equation*}`;
A hook invoked when a string of characters that could be interpreted as shortcut has been typed.
If not a special shortcut, return the empty string "".
Use this handler to detect multi character symbols, and return them wrapped appropriately,
for example \mathrm{${symbol}}.
A hook invoked when a scrolling the mathfield into view is necessary.
Use when scrolling the page would not solve the problem, e.g. when the mathfield is in another div that has scrollable content.
StaticfractionWhen using the keyboard to navigate a fraction, the order in which the numerator and navigator are traversed:
Default: "numerator-denominator"
StaticdecimalThe symbol used to separate the integer part from the fractional part of a number.
When "," is used, the corresponding LaTeX string is {,}, in order
to ensure proper spacing (otherwise an extra gap is displayed after the
comma).
This affects:
, key is pressed (if decimalSeparator is
",", the {,} LaTeX string is inserted when following some digits)Default: "."
StaticlocaleThe locale (language + region) to use for string localization.
If none is provided, the locale of the browser is used.
StaticstringsAn object whose keys are a locale string, and whose values are an object of string identifier to localized string.
Example
mf.strings = {
"fr-CA": {
"tooltip.undo": "Annuler",
"tooltip.redo": "Refaire",
}
}
If the locale is already supported, this will override the existing strings. If the locale is not supported, it will be added.
To create programmatically a new mathfield use:
let mfe = new MathfieldElement();
// Set initial value and options
mfe.value = "\\frac{\\sin(x)}{\\cos(x)}";
// Options can be set either as an attribute (for simple options)...
mfe.setAttribute("letter-shape-style", "french");
// ... or using properties
mfe.letterShapeStyle = "french";
// Attach the element to the DOM
document.body.appendChild(mfe);
Optionaloptions: Partial<MathfieldOptions>The HTMLElement.accessKey property sets the keystroke which a user can press to jump to a given element.
ReadonlyaccessThe HTMLElement.accessKeyLabel read-only property returns a string containing the element's browser-assigned access key (if any); otherwise it returns an empty string.
ReadonlyassignedReadonlyATTRIBUTE_ReadonlyattributesThe Element.attributes property returns a live collection of all attribute nodes registered to the specified node.
ReadonlyattributeThe autocapitalize property of the HTMLElement interface represents the element's capitalization behavior for user input.
The autocorrect property of the HTMLElement interface controls whether or not autocorrection of editable text is enabled for spelling and/or punctuation errors.
ReadonlybaseThe read-only baseURI property of the Node interface returns the absolute base URL of the document containing the node.
ReadonlyCDATA_node is a CDATASection node.
ReadonlychildReadonlychildThe read-only childNodes property of the Node interface returns a live the first child node is assigned index 0.
ReadonlychildrenReturns the child elements.
The className property of the of the specified element.
ReadonlyclientThe clientHeight read-only property of the Element interface is zero for elements with no CSS or inline layout boxes; otherwise, it's the inner height of an element in pixels.
ReadonlyclientThe clientLeft read-only property of the Element interface returns the width of the left border of an element in pixels.
ReadonlyclientThe clientTop read-only property of the Element interface returns the width of the top border of an element in pixels.
ReadonlyclientThe clientWidth read-only property of the Element interface is zero for inline elements and elements with no CSS; otherwise, it's the inner width of an element in pixels.
ReadonlyCOMMENT_node is a Comment node.
ReadonlycurrentThe currentCSSZoom read-only property of the Element interface provides the 'effective' CSS zoom of an element, taking into account the zoom applied to the element and all its parent elements.
ReadonlydatasetThe HTMLElement.dir property indicates the text writing directionality of the content of the current element.
ReadonlyDOCUMENT_node is a DocumentFragment node.
ReadonlyDOCUMENT_node is a document.
ReadonlyDOCUMENT_Set when other is a descendant of node.
ReadonlyDOCUMENT_Set when other is an ancestor of node.
ReadonlyDOCUMENT_Set when node and other are not in the same tree.
ReadonlyDOCUMENT_Set when other is following node.
ReadonlyDOCUMENT_ReadonlyDOCUMENT_Set when other is preceding node.
ReadonlyDOCUMENT_node is a doctype.
The draggable property of the HTMLElement interface gets and sets a Boolean primitive indicating if the element is draggable.
ReadonlyELEMENT_node is an element.
ReadonlyENTITY_ReadonlyENTITY_ReadonlyfirstThe read-only firstChild property of the Node interface returns the node's first child in the tree, or null if the node has no children.
ReadonlyfirstReturns the first child that is an element, and null otherwise.
The HTMLElement property hidden reflects the value of the element's hidden attribute.
The id property of the Element interface represents the element's identifier, reflecting the id global attribute.
The HTMLElement property inert reflects the value of the element's inert attribute.
The innerHTML property of the Element interface gets or sets the HTML or XML markup contained within the element.
The innerText property of the HTMLElement interface represents the rendered text content of a node and its descendants.
ReadonlyisThe read-only isConnected property of the Node interface returns a boolean indicating whether the node is connected (directly or indirectly) to a Document object.
ReadonlyisThe lang property of the HTMLElement interface indicates the base language of an element's attribute values and text content, in the form of a MISSING: RFC(5646, 'BCP 47 language identifier tag')].
ReadonlylastThe read-only lastChild property of the Node interface returns the last child of the node, or null if there are no child nodes.
ReadonlylastReturns the last child that is an element, and null otherwise.
ReadonlylocalThe Element.localName read-only property returns the local part of the qualified name of an element.
ReadonlynamespaceThe Element.namespaceURI read-only property returns the namespace URI of the element, or null if the element is not in a namespace.
ReadonlynextReturns the first following sibling that is an element, and null otherwise.
ReadonlynextThe read-only nextSibling property of the Node interface returns the node immediately following the specified one in their parent's Node.childNodes, or returns null if the specified node is the last child in the parent element.
ReadonlynodeThe read-only nodeName property of Node returns the name of the current node as a string.
ReadonlynodeThe read-only nodeType property of a Node interface is an integer that identifies what the node is.
The nodeValue property of the Node interface returns or sets the value of the current node.
OptionalnonceReadonlyNOTATION_ReadonlyoffsetThe offsetHeight read-only property of the HTMLElement interface returns the height of an element, including vertical padding and borders, as an integer.
ReadonlyoffsetThe offsetLeft read-only property of the HTMLElement interface returns the number of pixels that the upper left corner of the current element is offset to the left within the HTMLElement.offsetParent node.
ReadonlyoffsetThe HTMLElement.offsetParent read-only property returns a reference to the element which is the closest (nearest in the containment hierarchy) positioned ancestor element.
ReadonlyoffsetThe offsetTop read-only property of the HTMLElement interface returns the distance from the outer border of the current element (including its margin) to the top padding edge of the HTMLelement.offsetParent, the closest positioned ancestor element.
ReadonlyoffsetThe offsetWidth read-only property of the HTMLElement interface returns the layout width of an element as an integer.
Available only in secure contexts.
OptionalontouchcancelOptionalontouchendOptionalontouchmoveOptionalontouchstartThe outerHTML attribute of the Element DOM interface gets the serialized HTML fragment describing the element including its descendants.
The outerText property of the HTMLElement interface returns the same value as HTMLElement.innerText.
ReadonlyownerThe read-only ownerDocument property of the Node interface returns the top-level document object of the node.
ReadonlyparentThe read-only parentElement property of Node interface returns the DOM node's parent Element, or null if the node either has no parent, or its parent isn't a DOM Element.
ReadonlyparentThe read-only parentNode property of the Node interface returns the parent of the specified node in the DOM tree.
The popover property of the HTMLElement interface gets and sets an element's popover state via JavaScript ('auto', 'hint', or 'manual'), and can be used for feature detection.
ReadonlyprefixThe Element.prefix read-only property returns the namespace prefix of the specified element, or null if no prefix is specified.
ReadonlypreviousReturns the first preceding sibling that is an element, and null otherwise.
ReadonlypreviousThe read-only previousSibling property of the Node interface returns the node immediately preceding the specified one in its parent's or null if the specified node is the first in that list.
ReadonlyPROCESSING_node is a ProcessingInstruction node.
ReadonlyscrollThe scrollHeight read-only property of the Element interface is a measurement of the height of an element's content, including content not visible on the screen due to overflow.
The scrollLeft property of the Element interface gets or sets the number of pixels by which an element's content is scrolled from its left edge.
The scrollTop property of the Element interface gets or sets the number of pixels by which an element's content is scrolled from its top edge.
ReadonlyscrollThe scrollWidth read-only property of the Element interface is a measurement of the width of an element's content, including content not visible on the screen due to overflow.
ReadonlyshadowThe Element.shadowRoot read-only property represents the shadow root hosted by the element.
The slot property of the Element interface returns the name of the shadow DOM slot the element is inserted in.
The spellcheck property of the HTMLElement interface represents a boolean value that controls the spell-checking hint.
ReadonlytagThe tagName read-only property of the Element interface returns the tag name of the element on which it's called.
ReadonlyTEXT_node is a Text node.
The HTMLElement.title property represents the title of the element: the text usually displayed in a 'tooltip' popup when the mouse is over the node.
The translate property of the HTMLElement interface indicates whether an element's attribute values and the values of its Text node children are to be translated when the page is localized, or whether to leave them unchanged.
The writingSuggestions property of the HTMLElement interface is a string indicating if browser-provided writing suggestions should be enabled under the scope of the element or not.
StaticcreateSupport for Trusted Type.
This optional function will be called before a string of HTML is injected in the DOM, allowing that string to be sanitized according to a policy defined by the host.
StaticreadStaticspeakStaticversionThe Element.classList is a read-only property that returns a live DOMTokenList collection of the class attributes of the element.
InternalInternalInternalInternalInternalInternalInternalInternalInternalThe part property of the Element interface represents the part identifier(s) of the element (i.e., set using the part attribute), returned as a DOMTokenList.
InternalInternalInternalInternalThe textContent property of the Node interface represents the text content of the node and its descendants.
StaticcomputeA custom compute engine instance. If none is provided, a default one is
used. If null is specified, no compute engine is used.
StaticfontsA URL fragment pointing to the directory containing the fonts necessary to render a formula.
These fonts are available in the /dist/fonts directory of the SDK.
Customize this value to reflect where you have copied these fonts, or to use the CDN version.
The default value is "./fonts". Use null to prevent
any fonts from being loaded.
Changing this setting after the mathfield has been created will have no effect.
{
// Use the CDN version
fontsDirectory: ''
}
{
// Use a directory called "fonts", located next to the
// `mathlive.js` (or `mathlive.mjs`) file.
fontsDirectory: './fonts'
}
{
// Use a directory located at the root of your website
fontsDirectory: 'https://example.com/fonts'
}
StaticformStaticisStaticobservedInternalCustom elements lifecycle hooks
StaticoptionsStaticplonkSound played to provide feedback when a command has no effect, for example when pressing the spacebar at the root level.
The property is either:
soundsDirectory directoryStaticspeechIndicates which speech engine to use for speech output.
Use local to use the OS-specific TTS engine.
Use amazon for Amazon Text-to-Speech cloud API. You must include the
AWS API library and configure it with your API key before use.
See Guide: Speech
StaticspeechSets the speed of the selected voice.
One of x-slow, slow, medium, fast, x-fast or a value as a
percentage.
Range is 20% to 200% For example 200% to indicate a speaking rate
twice the default rate.
StaticspeechIndicates the voice to use with the speech engine.
This is dependent on the speech engine. For Amazon Polly, see here: https://docs.aws.amazon.com/polly/latest/dg/voicelist.html
StatictextThe markup syntax to use for the output of conversion to spoken text.
Possible values are ssml for the SSML markup or mac for the macOS
markup, i.e. [[ltr]].
StatictextSpecify which set of text to speech rules to use.
A value of mathlive indicates that the simple rules built into MathLive
should be used.
A value of sre indicates that the Speech Rule Engine from Volker Sorge
should be used.
(Caution) SRE is not included or loaded by MathLive. For this option to work SRE should be loaded separately.
See Guide: Speech
StatictextA set of key/value pairs that can be used to configure the speech rule engine.
Which options are available depends on the speech rule engine in use. There are no options available with MathLive's built-in engine. The options for the SRE engine are documented here
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Optionaloptions: boolean | AddEventListenerOptionsThe addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Optionaloptions: boolean | AddEventListenerOptionsInserts nodes just after node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
Optionaloptions: number | KeyframeAnimationOptionsInserts nodes after the last child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
The HTMLElement.attachInternals() method returns an ElementInternals object.
The Element.attachShadow() method attaches a shadow DOM tree to the specified element and returns a reference to its ShadowRoot.
Inserts nodes just before node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
The checkVisibility() method of the Element interface checks whether the element is visible.
Optionaloptions: CheckVisibilityOptionsThe HTMLElement.click() method simulates a mouse click on an element.
The cloneNode() method of the Node interface returns a duplicate of the node on which this method was called.
Optionalsubtree: booleanThe closest() method of the Element interface traverses the element and its parents (heading toward the document root) until it finds a node that matches the specified CSS selector.
The compareDocumentPosition() method of the Node interface reports the position of its argument node relative to the node on which it is called.
The computedStyleMap() method of the Element interface returns a StylePropertyMapReadOnly interface which provides a read-only representation of a CSS declaration block that is an alternative to CSSStyleDeclaration.
InternalCustom elements lifecycle hooks
The contains() method of the Node interface returns a boolean value indicating whether a node is a descendant of a given node, that is the node itself, one of its direct children (Node.childNodes), one of the children's direct children, and so on.
InternalCustom elements lifecycle hooks
The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.
Execute a [[Commands|command]] defined by a selector.
mfe.executeCommand('add-column-after');
mfe.executeCommand(['switch-mode', 'math']);
A selector, or an array whose first element is a selector, and whose subsequent elements are arguments to the selector.
Selectors can be passed either in camelCase or kebab-case.
// Both calls do the same thing
mfe.executeCommand('selectAll');
mfe.executeCommand('select-all');
The getAttribute() method of the element.
The getAttributeNames() method of the array.
Returns the specified attribute of the specified element, as an Attr node.
The getAttributeNodeNS() method of the Element interface returns the namespaced Attr node of an element.
The getAttributeNS() method of the Element interface returns the string value of the attribute with the specified namespace and name.
The Element.getBoundingClientRect() method returns a position relative to the viewport.
The getClientRects() method of the Element interface returns a collection of DOMRect objects that indicate the bounding rectangles for each CSS border box in a client.
The Element method getElementsByClassName() returns a live specified class name or names.
The Element.getElementsByTagName() method returns a live All descendants of the specified element are searched, but not the element itself.
The Element.getElementsByTagNameNS() method returns a live HTMLCollection of elements with the given tag name belonging to the given namespace.
The getHTML() method of the Element interface is used to serialize an element's DOM to an HTML string.
Optionaloptions: GetHTMLOptionsThe getRootNode() method of the Node interface returns the context object's root, which optionally includes the shadow root if it is available.
Optionaloptions: GetRootNodeOptionsThe Element.hasAttribute() method returns a Boolean value indicating whether the specified element has the specified attribute or not.
The hasAttributeNS() method of the Element interface returns a boolean value indicating whether the current element has the specified attribute with the specified namespace.
The hasAttributes() method of the Element interface returns a boolean value indicating whether the current element has any attributes or not.
The hasChildNodes() method of the Node interface returns a boolean value indicating whether the given Node has child nodes or not.
The hasPointerCapture() method of the pointer capture for the pointer identified by the given pointer ID.
The hidePopover() method of the HTMLElement interface hides a popover element (i.e., one that has a valid popover attribute) by removing it from the top layer and styling it with display: none.
The insertAdjacentElement() method of the relative to the element it is invoked upon.
The insertAdjacentHTML() method of the the resulting nodes into the DOM tree at a specified position.
The insertAdjacentText() method of the Element interface, given a relative position and a string, inserts a new text node at the given position relative to the element it is called from.
The isDefaultNamespace() method of the Node interface accepts a namespace URI as an argument.
The isEqualNode() method of the Node interface tests whether two nodes are equal.
The isSameNode() method of the Node interface is a legacy alias the for the === strict equality operator.
The lookupNamespaceURI() method of the Node interface takes a prefix as parameter and returns the namespace URI associated with it on the given node if found (and null if not).
The lookupPrefix() method of the Node interface returns a string containing the prefix for a given namespace URI, if present, and null if not.
The matches() method of the Element interface tests whether the element would be selected by the specified CSS selector.
The normalize() method of the Node interface puts the specified node and all of its sub-tree into a normalized form.
InternalInserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
Returns the first element that is a descendant of node that matches selectors.
Returns all element descendants of node that match selectors.
The releasePointerCapture() method of the previously set for a specific (PointerEvent) pointer.
Removes node.
The Element method removeAttribute() removes the attribute with the specified name from the element.
The removeAttributeNS() method of the If you are working with HTML and you don't need to specify the requested attribute as being part of a specific namespace, use the Element.removeAttribute() method instead.
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.
Optionaloptions: boolean | EventListenerOptionsThe removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.
Optionaloptions: boolean | EventListenerOptionsReplace all children of node with nodes, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
Replaces node with nodes, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
The Element.requestFullscreen() method issues an asynchronous request to make the element be displayed in fullscreen mode.
Optionaloptions: FullscreenOptionsThe requestPointerLock() method of the Element interface lets you asynchronously ask for the pointer to be locked on the given element.
Optionaloptions: PointerLockOptionsThe scroll() method of the Element interface scrolls the element to a particular set of coordinates inside a given element.
Optionaloptions: ScrollToOptionsThe scrollBy() method of the Element interface scrolls an element by the given amount.
Optionaloptions: ScrollToOptionsThe Element interface's scrollIntoView() method scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
Optionalarg: boolean | ScrollIntoViewOptionsThe scrollTo() method of the Element interface scrolls to a particular set of coordinates inside a given element.
Optionaloptions: ScrollToOptionsThe setAttribute() method of the Element interface sets the value of an attribute on the specified element.
The setHTMLUnsafe() method of the Element interface is used to parse a string of HTML into a DocumentFragment, optionally filtering out unwanted elements and attributes, and those that don't belong in the context, and then using it to replace the element's subtree in the DOM.
The setPointerCapture() method of the capture target of future pointer events.
The showPopover() method of the HTMLElement interface shows a Popover_API element (i.e., one that has a valid popover attribute) by adding it to the top layer.
The toggleAttribute() method of the present and adding it if it is not present) on the given element.
Optionalforce: booleanThe togglePopover() method of the HTMLElement interface toggles a Popover_API element (i.e., one that has a valid popover attribute) between the hidden and showing states.
Optionaloptions: booleanInternalPrivate lifecycle hooks
StaticloadStaticplayReturn the selection range for the specified prompt.
This can be used for example to select the content of the prompt.
mf.selection = mf.getPromptRange('my-prompt-id');
Return the id of the prompts matching the filter.
Optionalfilter: {Return the content of the \placeholder{} command with the placeholderId
Optionalformat: OutputFormatThe bottom location of the caret (insertion point) in viewport coordinates.
See also [[setCaretPoint]]
The last valid offset.
The position of the caret/insertion point, from 0 to lastOffset.
The depth of an offset represent the depth in the expression tree.
The offset closest to the location (x, y) in viewport coordinate.
bias: if 0, the vertical midline is considered to the left or
right sibling. If -1, the left sibling is favored, if +1, the right
sibling is favored.
Optionaloptions: { bias?: 0 | 1 | -1 }Select the content of the mathfield.
x and y are in viewport coordinates.
Return true if the location of the point is a valid caret location.
See also [[caretPoint]]
Return whether there are redoable items
Return whether there are undoable items
Reset the undo stack
StatickeypressWhen a key on the virtual keyboard is pressed, produce a short haptic feedback, if the device supports it.
StatickeypressWhen a key on the virtual keyboard is pressed, produce a short audio feedback.
If the property is set to a string, the same sound is played in all
cases. Otherwise, a distinct sound is played:
delete a sound played when the delete key is pressedreturn ... when the return/tab key is pressedspacebar ... when the spacebar is presseddefault ... when any other key is pressed. This property is required,
the others are optional. If they are missing, this sound is played as
well.The value of the properties should be either a string, the name of an
audio file in the soundsDirectory directory or null to suppress the sound.
StaticsoundsA URL fragment pointing to the directory containing the optional sounds used to provide feedback while typing.
Some default sounds are available in the /dist/sounds directory of the SDK.
Use null to prevent any sound from being loaded.
The
MathfieldElementclass represent a DOM element that displays math equations. It is a subclass of the standardHTMLElementclass and as such inherits all of its properties and methods.It inherits many useful properties and methods from [[
HTMLElement]] such asstyle,tabIndex,addEventListener(),getAttribute(), etc...It is the main entry point to the MathLive library.
It is typically used to render a single equation. To render multiple equations, use multiple instances of
MathfieldElement. TheMathfieldElementclass provides special properties and methods to control the display and behavior of<math-field>elements.To create a new
MathfieldElement:The
MathfieldElementconstructor has an optional argument of [[MathfieldOptions]] to configure the element. The options can also be modified later:MathfieldElement CSS Variables
To customize the appearance of the mathfield, declare the following CSS variables (custom properties) in a ruleset that applies to the mathfield.
Alternatively you can set these CSS variables programatically:
--hue--contains-highlight-background-color--primary-color--text-font-family--smart-fence-opacity--smart-fence-colorYou can customize the appearance and zindex of the virtual keyboard panel with some CSS variables associated with a selector that applies to the virtual keyboard panel container.
Read more about customizing the virtual keyboard appearance
MathfieldElement CSS Parts
To style the virtual keyboard toggle, use the
virtual-keyboard-toggleCSS part. To use it, define a CSS rule with a::part()selector for example:MathfieldElement Attributes
An attribute is a key-value pair set as part of the tag:
The supported attributes are listed in the table below with their corresponding property.
The property can also be changed directly on the
MathfieldElementobject:The values of attributes and properties are reflected, which means you can change one or the other, for example:
An exception is the
valueproperty, which is not reflected on thevalueattribute: for consistency with other DOM elements, thevalueattribute remains at its initial value.disabledmf.disableddefault-modemf.defaultModeletter-shape-stylemf.letterShapeStylemin-font-scalemf.minFontScalepopover-policymf.popoverPolicymath-mode-spacemf.mathModeSpaceread-onlymf.readOnlyremove-extraneous-parenthesesmf.removeExtraneousParenthesessmart-fencemf.smartFencesmart-modemf.smartModesmart-superscriptmf.smartSuperscriptinline-shortcut-timeoutmf.inlineShortcutTimeoutscript-depthmf.scriptDepthvaluevaluemath-virtual-keyboard-policymathVirtualKeyboardPolicySee [[
MathfieldOptions]] for more details about these options.In addition, the following global attributes can also be used:
classdata-*hiddeniditem*styletabindexMathfieldElement Events
Listen to these events by using
addEventListener(). For events with additional arguments, the arguments are available inevent.detail.beforeinputinputevt.dataproperty includes a copy ofevt.inputType. SeeInputEventchangeselection-changemode-changemath,text) of the mathfield has changedundo-state-changeevt.detail.typeindicate if a snapshot was taken or an undo performed.read-aloud-status-changebefore-virtual-keyboard-toggleevt.detail.visibleproperty indicate if the keyboard will be visible or not. Listen for this event onwindow.mathVirtualKeyboardvirtual-keyboard-togglewindow.mathVirtualKeyboardgeometrychangeevt.detail.boundingRectproperty is the new bounding rectangle of the virtual keyboard. Listen for this event onwindow.mathVirtualKeyboardblurfocusmove-out`detail: {direction: 'forward'
keypressmountunmountKeywords
zindex, events, attribute, attributes, property, properties, parts, variables, css, mathfield, mathfieldelement