Referencesubstitute

<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>
AttributeTypeValues
assignNames = "…"
assignNamesSkip = "…"
displayDecimals = "…"integer
displayDigits = "…"integer
displaySmallAsZero = "…"number
match = "…"
matchCase = "…"boolean"true" "false"
matchWholeWord = "…"boolean"true" "false"
padZeros = "…"boolean"true" "false"
preserveCase = "…"boolean"true" "false"
replacement = "…"
simplify = "…"text"none" "full" "numbers" "numberspreserveorder"
type = "…"text"math" "text"
Props for <substitute name="s">
PropertyType
$s.displayDecimalsinteger
$s.displayDigitsinteger
$s.displaySmallAsZeronumber
$s.matchCaseboolean
$s.matchWholeWordboolean
$s.padZerosboolean
$s.preserveCaseboolean
$s.simplifytext
$s.typetext

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 replace
  • replacement, which defines the new content

The default type for substitution is math.

The substititution is performed in a <setup> block, which does not render on the page. The modified expression is later rendered by referencing the name of the <substitute> component in line 1010 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 substititution is performed in a <setup> block, which does not render on the page. The modified text is later rendered by referencing the name of the <substitute> component in line 1010 with $sub.


Example: substitute a user-provided value in a math

In this example, the user provides the substituted value in the math expression.


Example: type

The default substitution type is math. Use type="text" to switch the type of substitution to text.


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.


Example: simplify

The <substitution> component accepts the standard simplify attribute for math components.


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


Example: matchCase

By default, matching is case-insensitive with the <substitution> component. Use matchCase to change this default behavior.


Example: preserveCase

To preserve the case of the letter in the original text string, use the preserveCase attribute.