如何使用jQuery.load加载后使用MathJax格式化html? [英] How do I format html with MathJax after loading it using jQuery.load?

查看:418
本文介绍了如何使用jQuery.load加载后使用MathJax格式化html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用jQuery.load加载一个新页面。然而,内容正在被怪异地对待。在原始页面上,我有一些代码可以用MathJax格式化乳胶命令:

I am loading a new page with jQuery.load. However, the contents are being treated weirdly somehow. On the original page, I have some code to format latex commands with MathJax:

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

这对原始文件很有效。但是,当我点击我的链接并在页面中插入更多HTML时:

And this works fine for the original file. However, when I click on my link and insert more HTML into the page:

<script>
  $(document).ready(function(){
    $("#link").click(function(){
      $("#myDiv").load("test.html");
    });
  });
</script>

现在特殊字符没有被MathJax格式化,只是按原样显示。

Now the special characters are not formatted by MathJax and are just displayed as-is.

推荐答案

Carols 10cents已关闭,但您需要执行 MathJax.Hub.Queue()调用jQuery load()中的回调函数,以便在文件加载后直到完成排版。 (就目前而言,即使该文件可能还不可用,它会在请求文件加载后立即发生)。类似于

Carols 10cents is close, but you need to do the MathJax.Hub.Queue() call in a callback from the jQuery load() so that the typesetting isn't performed until after the file is loaded. (As it stands, it happens immediately after the file load is requested, even though the file may not be available yet). Something like

<script>
  $(document).ready(function(){
    $("#link").click(function(){
      $("#myDiv").load("test.html", function () {
        MathJax.Hub.Queue(["Typeset", MathJax.Hub, "myDiv"]);
      });
    });
  });
</script>

请参阅范例,这是我在2013年1月在JMM上发表的一次演讲,以获取更多详情和解决其他情况。

See the examples from a talk I gave at the JMM in January 2013 for more details and the solution to other situations.

这篇关于如何使用jQuery.load加载后使用MathJax格式化html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆