Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
raph-of-burgondy opened this issue Oct 3, 2021 · 3 comments
Labels

Comments

@raph-of-burgondy
Copy link

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,

@dpvc
Copy link
Member

dpvc commented Oct 9, 2021

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
Copy link
Member

dpvc commented Oct 9, 2021

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

@dpvc dpvc added the bug label Oct 9, 2021
@raph-of-burgondy
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants