Typesetting and Converting Mathematics - errors in the code() example
Hi,
In "Typesetting and Converting Mathematics" , there are two errors in the code() example
- the function is named "typeset" instead of "code"
- the code function must returns an iterable
So :
typeset(() => {
const math = document.querySelector('#math');
math.innerHTML = '$$\\frac{a}{1-a^2}$$';
return math;
});
must be replaced by :
code(() => {
const math = document.querySelector('#math');
math.innerHTML = '$$\\frac{a}{1-a^2}$$';
return [math];
});
br,
Thanks for reporting the issue. You are correct about replacing math by [math], but not about renaming typeset(). The typeset() function is defined earlier as
let promise = Promise.resolve(); // Used to hold chain of typesetting calls
function typeset(code) {
promise = promise.then(() => MathJax.typesetPromise(code()))
.catch((err) => console.log('Typeset failed: ' + err.message));
return promise;
}
and so
typeset(() => {
const math = document.querySelector('#math');
math.innerHTML = '$$\\frac{a}{1-a^2}$$';
return [math];
});
is calling that function. Note that code is the argument being passed to typeset(), and in this case is an arrow function, not a named function. There is no (global) definition of a function called code(), it is just the name of parameter to the typeset() function.
So the only correction needed is the missing brackets. Thanks for pointing that out.
It will be fixed with the next release of the documentation.
yes, you are right no need to change typeset function . thkx for your reply !