This function requires three arguments:
- The latex string you want to work on
- The variable you want to substitute
- The string you want to substitute it with
When applied to the example above, the code looks something like this:
substituteLatexVariable(`3x^{2}+5x-2`,`x`,`(3)`)
where the string we’re working with is `3x^{2}+5x-2`, the variable we’re looking for is `x`, and the numeric value we’re replacing it with is `(3)`.
This function opens up possibilities for replacing not only standard English letters, but also a selection of special characters and functions, with virtually any string. This allows us to do all sorts of things, like:
- Erasing characters.
- Recoloring/reformatting.
- Substituting in mathematical expressions.
We can even nest this function to convert words to numbers.