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

MathJax can not works correctly after any modification for current file #67

Closed
databill opened this issue Apr 14, 2015 · 5 comments
Closed

Comments

@databill
Copy link

When I open the markdown(.md) file to edit, the initial part in the web browser including MathJax equation works correctly. After I do any changes to the file, the MaxthJax equation will just show the original format, such as $$....$$.

Environments:

  • OS: OS X Yosemite 10.10.3
  • Browser: Firefox 37.0.1
  • VIM: 7.4
@FrankDMartinez
Copy link

Seeing a similar problem. Environment is the same, except I use Firefox 38.0.1.

@ZhengRui
Copy link

ZhengRui commented Jul 9, 2015

For those who are interested to enable MathJax so you can preview Math Symbols and Equations, here is a simple way to do it:

In my OSX, the vim-instant-preview is installed in /usr/local/lib/node_modules/instant-markdown-d/ folder, only need to change index.html file

  • Add MathJax javascript library:
    add
  <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>                                                                         
  <script type="text/x-mathjax-config">                                         
    MathJax.Hub.Config({                                                        
      tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}                            
    });                                                                            
  </script>

inside <head></head>, then you should be able to see Math symbols rendered the first time you preview a .md file. However when you change the file and update the preview you will find Math symbols not be rendered anymore as mentioned here, by looking at instant-markdown-d file, you will find it actually creates aMarkdownIt instance (dependency: markdown-it) named md, then in the

input.on('end', function(){
    output.emit('newContent', md.render(body));
});

it sends the md.render(body) as the injected html back to the clients, because markdown-it doesn't support rendering Math yet, that's why the math symbols are gone after updating the preview. So you
need to render the math again after the client side receives the html rendered by markdown-it.

  • To do this, change relevant part in your index.html to be like this
socket.on('newContent', function(newHTML) {                                  
        document.querySelector(".markdown-body").innerHTML = newHTML;              
        MathJax.Hub.Queue(["Typeset", MathJax.Hub]);                                                
      });

After these two steps, it should be able to display math.

@databill
Copy link
Author

Thanks ZhengRui very much! It works perfectly now!
Anyone can merge this fix?

I close this issue!

@HaleTom
Copy link

HaleTom commented Nov 24, 2016

@databill @ZhengRui I raised the issue (above). Feel free to comment :)

@sqwlly
Copy link

sqwlly commented Sep 12, 2018

MathJax.Hub.Queue(["Typeset", MathJax.Hub]);

thank you very much!

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

No branches or pull requests

5 participants