classeur / markdown-it-mathjax

Markdown-it plugin to bypass LaTeX math for mathjax processing.
MIT License
68 stars 20 forks source link

How to use it in browser? #6

Closed tamlok closed 7 years ago

tamlok commented 7 years ago

Hi, can I just download the markdown-it-mathjax.js file and reference it directly from browser side? Otherwise, could you help to build it and share it in a dist folder like other plugins do? Thanks!

mcmcclur commented 7 years ago

It's been two months since this was asked but it took me a bit to figure this out too. Here's the approach that worked for me.

In your HTML code, load first load both markdown-it and markdown-it-mathjax. Then, when you call markdownit(), append the use method with markdownitMathjax(). Thus your code might look something like so:

<script src="your/path/markdown-it.js"></script>
<script src="your/path/markdown-it-mathjax.js"></script>
<script>
  var md = markdownit().use(markdownitMathjax());
  var result = md.render(input_text);
</script>
Ciantic commented 7 years ago

This does not seem to work, there is some extra trick here needed.

Ciantic commented 7 years ago

It seems like it requires this also of course:

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML"></script>

mcmcclur commented 7 years ago

@Ciantic I'm not quite sure from your second comment if you've got it resolved or not. Either way, you can view my complete working example here: https://marksmath.org/temp/markdown-it-test/

HTH!