<substitute>
<substitute> is a General Operator
component that replaces one character or string from a math or a text with another specified string.
Note that substitution is used for variables in math expressions, not numerical values. Doenet ignores requests for substitution of strict numerical values in math expressions.
Attributes and Properties
Attributes for <substitute>
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: 3. Number of significant digits to display when rendering this number.
displaySmallAsZeronumber. Default value: 1e-14. 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.
Other (7)
_componentWithSelectableType. Pattern to match in the source value.
boolean. Default value: false. Whether matching is case-sensitive (text mode).
boolean. Default value: false. Whether matching is restricted to whole words (text mode).
boolean. Default value: false. Whether the case of the original is preserved when substituting.
_componentWithSelectableType. Value to substitute in place of each match.
keyword. Level of simplification applied after substitution.
| Value | Description |
|---|---|
none (default) | No simplification is applied. |
full | Fully simplify the resulting expression. |
numbers | Simplify numeric subexpressions only, leaving symbolic structure intact. |
numbersPreserveOrder | Like numbers, but does not reorder commutative operands. |
normalizeOrder | Reorder commutative operands into a canonical form without simplifying values. |
keyword. Type of values being substituted.
| Value | Description |
|---|---|
math | Substitute within math expressions. |
text | Substitute within text values. |
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 <substitute name="s">
Number display (5)
$s.avoidScientificNotationboolean. Whether to render numbers in full decimal form rather than scientific notation.
$s.displayDecimalsinteger. Number of decimal places to display when rendering this number.
$s.displayDigitsinteger. Number of significant digits to display when rendering this number.
$s.displaySmallAsZeronumber. Threshold below which numbers are displayed as zero.
$s.padZerosboolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Other (5)
$s.matchCaseboolean. Whether matching is case-sensitive (text mode).
$s.matchWholeWordboolean. Whether matching is restricted to whole words (text mode).
$s.preserveCaseboolean. Whether the case of the original is preserved when substituting.
$s.simplifytext. Level of simplification applied after substitution.
$s.typetext. Type of values being substituted.
Common to all components (4)
$s.doenetMLtext. The DoenetML source code that produced this component.
$s.hideboolean. Whether to hide this component from the rendered output.
$s.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$s.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: substitute a different variable in a math
In this example, the <substitute> component is used to swap out one variable from a user-input expression for another. Two attributes are required:
match, which defines the content to replacereplacement, which defines the new content
The default type for substitution is math.
The modified expression is rendered by referencing the name of the <substitute> component with $sub.
Example: Replace one word with another in a text string
In this example, the <substitute> component is used to swap out one word from a user’s <textInput> for another. The type = "text" specification is made for the <substitute> component; this is required as the default type is math.
The modified text is rendered by referencing the name of the <substitute> component with $sub.
Example: substitute a user-provided value in a math
In this example, the user provides the substituted value in the math expression.
Attribute Examples
Attribute Example: type
The default substitution type is math. Use type="text" to switch the type of substitution to text.
Attribute Example: match, replacement
The match attribute specifies content to be replaced with the <substitution> component.
The replacement attribute specifies new content to be inserted with the <substitution> component.
Attribute Example: simplify
The <substitution> component accepts the standard simplify attribute for math components.
Attribute Example: matchWholeWord
By default, Doenet separates strings into individual, case-insensitive characters when finding matches for substitution. If a strict match of the entire word is desired, use the the matchWholeWord attribute
Attribute Example: matchCase
By default, matching is case-insensitive with the <substitution> component. Use matchCase to change this default behavior.
Attribute Example: preserveCase
To preserve the case of the letter in the original text string, use the preserveCase attribute.