mathjax / MathJax-docs

MathJax documentation. Beautiful math in all browsers. Beautifully documented.
Apache License 2.0
546 stars 231 forks source link

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

Open raph-of-burgondy opened 2 years ago

raph-of-burgondy commented 2 years ago

Hi,

In "Typesetting and Converting Mathematics" , there are two errors in the code() example

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,

dpvc commented 2 years ago

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 commented 2 years ago

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

raph-of-burgondy commented 2 years ago

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