<mathInput/>
<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)
avoidScientificNotationboolean. Default value: false. Whether to render numbers in full decimal form rather than scientific notation.
displayDecimalsinteger. Default value: 2. Number of decimal places to display when rendering this number.
displayDigitsinteger. Default value: 10. Number of significant digits to display when rendering this number.
displaySmallAsZeronumber. Default value: 0. Threshold below which numbers are displayed as zero.
padZerosboolean. Default value: false. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Labels (1)
labelIsNameboolean. Default value: false. Whether to use this component's name as its rendered label.
Other (17)
additionalFunctionNamestextList. 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.
| Value | Description |
|---|---|
text (default) | Plain-text math notation (e.g., x^2 + 1). |
latex | LaTeX-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.
labelPositionkeyword. Position of the label relative to the input.
| Value | Description |
|---|---|
left (default) | Place the label to the left of the input. |
right | Place the label to the right of the input. |
integer. Default value: 50. Minimum rendered width of the input.
parseScientificNotationboolean. 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.
removedFunctionNamestextList. 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.
resetFunctionNamestextList. 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.
showPreviewboolean. 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)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. 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.avoidScientificNotationboolean. Whether to render numbers in full decimal form rather than scientific notation.
$m.displayDecimalsinteger. Number of decimal places to display when rendering this number.
$m.displayDigitsinteger. Number of significant digits to display when rendering this number.
$m.displaySmallAsZeronumber. Threshold below which numbers are displayed as zero.
$m.padZerosboolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Labels (2)
$m.labellabel. The label rendered with this component.
$m.labelIsNameboolean. Whether to use this component's name as its rendered label.
Other (39)
$m.additionalFunctionNamestextList. 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.disabledboolean. Whether this component is disabled and cannot be interacted with.
$m.fixedboolean. Whether this component's value is fixed and cannot be modified.
$m.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$m.focusedboolean. Whether this input currently has keyboard focus.
$m.formattext. Input format.
$m.functionSymbolstextList. Symbols treated as function names when parsing.
$m.hideNaNboolean. Whether to hide NaN values when displaying the input.
math. The current math value being entered (live, before saving).
$m.immediateValueChangedboolean. Whether the live value differs from its initial state.
$m.labelPositiontext. 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.matrixSizenumberList. The size of the math expression as a matrix, as a [numRows, numColumns] list.
$m.minWidthinteger. Minimum rendered width of the input.
$m.numColumnsinteger. The number of columns when the math expression is interpreted as a matrix.
$m.numDimensionsinteger. The number of dimensions if the math expression is interpreted as a vector or matrix.
$m.numListItemsinteger. The number of items when the math expression is interpreted as a list.
$m.numRowsinteger. The number of rows when the math expression is interpreted as a matrix.
$m.parseScientificNotationboolean. Whether to parse expressions like 1e3 as scientific notation.
$m.prefillmath. Initial value displayed in the input.
$m.prefillLatexlatex. Initial value as a LaTeX string.
latex. The raw value used by the renderer (e.g. LaTeX string).
$m.removedFunctionNamestextList. Built-in function names to stop auto-formatting in the editor (e.g., 'min' so 'kg/min' can be typed as a unit).
$m.resetFunctionNamestextList. 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.shortDescriptiontext. A short accessibility description of this input; it is visible to screen readers but not rendered visually.
$m.showPreviewboolean. Whether to display a preview of the parsed math.
$m.splitSymbolsboolean. Whether multi-character symbols are split into a product of single-character variables.
$m.texttext. The current input as a text string.
$m.unionFromUboolean. Whether "U" between sets is parsed as union.
$m.valuemath. The most recently saved math value.
$m.valueChangedboolean. Whether the saved value has been changed from its initial state.
$m.vector[ math ]. The math expression interpreted as a vector (its components).
$m.xmath. The first component of the math expression when interpreted as a vector.
$m.ymath. The second component of the math expression when interpreted as a vector.
$m.zmath. The third component of the math expression when interpreted as a vector.
Common to all components (4)
$m.doenetMLtext. The DoenetML source code that produced this component.
$m.hideboolean. Whether to hide this component from the rendered output.
$m.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$m.styleNumberinteger. 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 . 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:
- It colors the border of the math input based on the correctness of the response (assuming
colorCorrectnessis not set tofalse). - 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 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.