ReferencemathInput

<mathInput/>

An interactive math input

<mathInput/> is an Input component that renders a user-input field that stores mathematical content. When referenced, a named <mathInput/> can be used in computations in the same manner as a <math> component.

Attributes and Properties

Attributes for <mathInput>

Number display (5)
avoidScientificNotation

boolean. Default value: false. Whether to render numbers in full decimal form rather than scientific notation.

displayDecimals

integer. Default value: 2. Number of decimal places to display when rendering this number.

displayDigits

integer. Default value: 10. Number of significant digits to display when rendering this number.

displaySmallAsZero

number. Default value: 0. Threshold below which numbers are displayed as zero.

padZeros

boolean. Default value: false. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Labels (1)
labelIsName

boolean. Default value: false. Whether to use this component's name as its rendered label.

Other (17)
additionalFunctionNames

textList. Extra identifiers to auto-format as function names in the editor (e.g., 'erf'). Entries that also appear in removedFunctionNames are dropped.

math. Two-way binding target for the input's value.

reference. References to <answer> elements that this input should submit to.

keyword. Input format.

ValueDescription
text (default)Plain-text math notation (e.g., x^2 + 1).
latexLaTeX-formatted math (e.g., x^{2} + 1).

textList. Default value: ["f","g"]. Symbols treated as function names when parsing.

boolean. Default value: true. Whether to hide NaN values when displaying the input.

labelPosition

keyword. Position of the label relative to the input.

ValueDescription
left (default)Place the label to the left of the input.
rightPlace the label to the right of the input.

integer. Default value: 50. Minimum rendered width of the input.

parseScientificNotation

boolean. Default value: false. Whether to parse expressions like 1e3 as scientific notation.

math. Default value: \(_\). Initial value displayed in the input.

latex. Initial value as a LaTeX string.

removedFunctionNames

textList. Built-in function names to stop auto-formatting in the editor (e.g., 'min' so 'kg/min' can be typed as a unit).

textList. Substrings to strip from the input before parsing.

resetFunctionNames

textList. When set, replaces the entire auto-formatted function name list (defaults, additionalFunctionNames, and removedFunctionNames are all ignored). Set to an empty value to disable auto-formatting entirely.

showPreview

boolean. Default value: false. Whether to display a preview of the parsed math.

boolean. Default value: true. Whether multi-character symbols are split into a product of single-character variables.

boolean. Default value: false. Whether "U" between sets is parsed as union.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <mathInput name="m">

Number display (5)
$m.avoidScientificNotation

boolean. Whether to render numbers in full decimal form rather than scientific notation.

$m.displayDecimals

integer. Number of decimal places to display when rendering this number.

$m.displayDigits

integer. Number of significant digits to display when rendering this number.

$m.displaySmallAsZero

number. Threshold below which numbers are displayed as zero.

$m.padZeros

boolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Labels (2)
$m.label

label. The label rendered with this component.

$m.labelIsName

boolean. Whether to use this component's name as its rendered label.

Other (39)
$m.additionalFunctionNames

textList. Extra identifiers to auto-format as function names in the editor (e.g., 'erf'). Entries that also appear in removedFunctionNames are dropped.

$m.columns

[ math ]. The matrix's entries grouped by column.

$m.disabled

boolean. Whether this component is disabled and cannot be interacted with.

$m.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$m.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$m.focused

boolean. Whether this input currently has keyboard focus.

$m.format

text. Input format.

$m.functionSymbols

textList. Symbols treated as function names when parsing.

$m.hidden

boolean. Whether this component is hidden from the rendered output.

$m.hideNaN

boolean. Whether to hide NaN values when displaying the input.

math. The current math value being entered (live, before saving).

$m.immediateValueChanged

boolean. Whether the live value differs from its initial state.

$m.labelPosition

text. Position of the label relative to the input.

$m.list

[ math ]. The math expression interpreted as a list (its elements).

$m.matrix

[ math ]. The math expression interpreted as a matrix (its entries by row and column).

$m.matrixSize

numberList. The size of the math expression as a matrix, as a [numRows, numColumns] list.

$m.minWidth

integer. Minimum rendered width of the input.

$m.numColumns

integer. The number of columns when the math expression is interpreted as a matrix.

$m.numDimensions

integer. The number of dimensions if the math expression is interpreted as a vector or matrix.

$m.numListItems

integer. The number of items when the math expression is interpreted as a list.

$m.numRows

integer. The number of rows when the math expression is interpreted as a matrix.

$m.parseScientificNotation

boolean. Whether to parse expressions like 1e3 as scientific notation.

$m.prefill

math. Initial value displayed in the input.

$m.prefillLatex

latex. Initial value as a LaTeX string.

latex. The raw value used by the renderer (e.g. LaTeX string).

$m.removedFunctionNames

textList. Built-in function names to stop auto-formatting in the editor (e.g., 'min' so 'kg/min' can be typed as a unit).

$m.resetFunctionNames

textList. When set, replaces the entire auto-formatted function name list (defaults, additionalFunctionNames, and removedFunctionNames are all ignored). Set to an empty value to disable auto-formatting entirely.

$m.rows

[ math ]. The matrix's entries grouped by row.

$m.shortDescription

text. A short accessibility description of this input; it is visible to screen readers but not rendered visually.

$m.showPreview

boolean. Whether to display a preview of the parsed math.

$m.splitSymbols

boolean. Whether multi-character symbols are split into a product of single-character variables.

$m.text

text. The current input as a text string.

$m.unionFromU

boolean. Whether "U" between sets is parsed as union.

math. The most recently saved math value.

$m.valueChanged

boolean. Whether the saved value has been changed from its initial state.

$m.vector

[ math ]. The math expression interpreted as a vector (its components).

$m.x

math. The first component of the math expression when interpreted as a vector.

$m.y

math. The second component of the math expression when interpreted as a vector.

$m.z

math. The third component of the math expression when interpreted as a vector.

Common to all components (4)
$m.doenetML

text. The DoenetML source code that produced this component.

$m.hide

boolean. Whether to hide this component from the rendered output.

$m.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$m.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: Assign a name to user-input math expression

A <mathInput/> renders an input field for storing and naming user-provided math expressions.


Example: Do some math with user-input

A named <mathInput/> can be referenced within a <math> for computations.


Example: <mathInput/> with structured prefill

A <mathInput/> can incorporate a prefill with shaded blanks.

Attribute Examples

Attribute Example: prefill

The prefill attribute can be used to specify an initial value of the <mathInput/>, or a template for anticipated responses. Blank spaces, if used, are rendered as grey input boxes.


Attribute Example: prefillLatex

The most common way to enter LaTex in a prefill is to use the format = "latex" attribute. However, the prefillLatex attribute is a means of preserving non-standard formatting which is typically removed when LaTeX is parsed as a math component.


Attribute Example: format

The format attribute gives the option for prefilled <mathInput/> components to contain content formatted in LaTex. If supported, expressions entered in the prefill of the <mathInput/> will be parsed by Doenet as math components and may be used in further computations.


Attribute Example: functionSymbols

The functionSymbols attribute is used to specify when a character is formatted as a function that takes an argument in parentheses. The default values that are automatically considered functions symbols are f and g.


Attribute Example: splitSymbols

The splitSymbols attribute is used to modify the default mathematical simplification of multicharacter values in a <mathInput/>. By default, Doenet assumes adjacent characters are single variables multiplied together, and “splits” them during parsing. So, for example, multicharacter values such as xyz are interpreted as the product xyzx \cdot y \cdot z. However, if you wish to treat a grouping of symbols as a single variable, you can turn off this behavior by specifying splitSymbols="false".


Attribute Example: forAnswer

Specifying the attribute forAnswer of a <mathInput> does two things:

  1. It colors the border of the math input based on the correctness of the response (assuming colorCorrectness is not set to false).
  2. It includes the value of the math input as a response of the answer.

Attribute Example: bindValueTo

The bindValueTo attribute is used to create a bidirectional link between the value of a <mathInput/> and that of another component. This attribute accepts a reference to a named math component or the property of a named component as input.

An alternative way to create the same bidirectional link is to simply put the reference to the component as a child of the <mathInput>.


Attribute Example: unionFromU

By default, an uppercase “U” entered in a <mathInput/> will be interpreted as the letter U. To enter a union, one can use the virtual keyboard (by clicking button at the bottom of the screen), and finding the \cup symbol in the keyboard’s Set menu.
(Or, if one knows LaTeX, one could type \cup for union.)


Attribute Example: hideNaN

By default, the text NaN is suppressed within the <mathInput/> box. To override this behavior, the hideNaN attribute may be set to false.


Attribute Example: removeStrings

The removeStrings attribute allows Doenet to ignore elements of a user’s input which cannot be parsed into a math.


Attribute Example: minWidth

The minWidth attribute is set to 50 by default. Adjust this value for a longer or shorter input box.

Property Examples

Property Example: Attributes as properties

The above-listed attributes of <mathInput/> are also accessible as properties.


Property Example: value

The value property renders the value stored in the <mathInput> after the user has clicked Enter (or mouse-clicked on another part of the screen).


Property Example: immediateValue

The immediateValue property contains the value the user enters into the input as they are typing.


Property Example: text

The text property of a <mathInput/> stores its content as a string.


Property Example: rawRendererValue

The rawRendererValue property stores/renders the LaTeX code required for rendering the math expression, updated as the user types.