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

Updated rendered HTML after changing input equation #2413

Closed
amjha opened this issue Mar 20, 2020 · 2 comments
Closed

Updated rendered HTML after changing input equation #2413

amjha opened this issue Mar 20, 2020 · 2 comments

Comments

@amjha
Copy link

amjha commented Mar 20, 2020

I have been using this code to render Latex. However when I update my equation the rendered HTML doesn't refresh. I tried finding documentation for typeset() but could not find much to help with the code example here:

import { mathjax } from 'mathjax-full/js/mathjax';
import { TeX } from 'mathjax-full/js/input/tex';
import { CHTML } from 'mathjax-full/js/output/chtml'
import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
import { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';
import { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';

RegisterHTMLHandler(browserAdaptor());

const html = mathjax.document(document, {
  InputJax: new TeX({
    inlineMath: [['$', '$'], ['\\(', '\\)']],
    packages: AllPackages
  }),
  OutputJax: new CHTML()
});

html.findMath()
  .compile()
  .getMetrics()
  .typeset()
  .updateDocument();

Is there way to get updated rendering?

@dpvc
Copy link
Member

dpvc commented Mar 20, 2020

MathJax keeps track of the steps that have already been performed so that it doesn't have to redo them if the process is interrupted (for dynamic loading of an extension, for example). But this also means that the steps won't be performed a second time unless you tell MathJax that you want them to be. You do that via html.reset(). So

html.findMath()
    .compile()
    .getMetrics()
    .typeset()
    .updateDocument()
    .reset();

would allow you to repeat the process.

This example is an old one, and there is a newer API that does the first fix steps for you (plus any additional steps that are registered as renderActions such as adding the MahJax contextual menu, and so on). It is

html.render()
    .reset();

though you can still do the individual steps as you have done, if you wish.

@dpvc
Copy link
Member

dpvc commented Apr 18, 2020

I'm moving this issue to the main MathJax issue tracker.

@dpvc dpvc transferred this issue from mathjax/MathJax-src Apr 18, 2020
@dpvc dpvc closed this as completed Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants