Autoload MathJax - for noobs (v7)
VERSION 7: Here, we're assuming the user is new to JSXGraph, new to MathJax, and new to programming generally.
We want them to be able to:
- Create a graph, and
- Add a
textelement to the graph containing LaTeX, with single backslashes (as they are used to from the LaTeX environment); OR - Use ASCIIMath, with its back tick delimiters,
`...`
In this example, the initial setting is JXG.Options.text.parse = false; and finding math and loading MathJax is done automatically.
We'll autoload MathJax if the script finds any math (e.g. $$ ... $$ or \( ... \), etc via regex matching.
You can test various scenarios in this script (by commenting out or not the following in the source code):
- User provides a MathJax configuration (or doesn't). If they haven't, the fourth expression won't be typeset because it's in single
$...$delimiters. - MathJax is already loaded before JSXGraph scripts run, so no need to autoload (or not)
- The user is using ASCIIMath or not
- There is a window "load" eventListener (or not)
- User specifies
useMathJax: trueandparse: false(or not)
Potential JSXGraph instructions
(1) If you want to include LaTeX math in your graph, enter it with the following syntax, starting with rawMath and then surrounding it in back ticks, like this:
rawMath ` \sin(x) = \sqrt(a^2 + b^2)`
Using the above syntax, you don't have to use double slashes throughout for your math expressions.
(2) If you want to include ASCIIMath in your graph, enter it with the usual back ticks, like this:
` sin(x) = (sqrt(a^2 + b^2)) / (x^3) `
The script will take care of formatting the math and loading MathJax.