MathJax-docs icon indicating copy to clipboard operation
MathJax-docs copied to clipboard

Typesetting and Converting Mathematics - errors in the code() example

Open raph-of-burgondy opened this issue 4 years ago • 3 comments

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,

raph-of-burgondy avatar Oct 03 '21 10:10 raph-of-burgondy

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.

dpvc avatar Oct 09 '21 12:10 dpvc

It will be fixed with the next release of the documentation.

dpvc avatar Oct 09 '21 12:10 dpvc

yes, you are right no need to change typeset function . thkx for your reply !

raph-of-burgondy avatar Oct 09 '21 19:10 raph-of-burgondy