doujianzhi3358 2010-09-28 20:21
浏览 643
已采纳

如何动态加载MathJax?

I'm trying to use MathJax to convert text into mathematics while typing, using a textarea field. However when I send the typed text to a database to retrieve the text through a php file back to the original file, I can't get MathJax to convert the text into LaTeX-like symbols.

This is the main part (using jQuery):

$(document).ready(function(){
$('textarea').keydown(function(){ 
    dynamic(); \\ A function described in MathJax documentation to load dynamically
    var text = $('textarea').val();
    $.post('process.php',{ input: text } );
    $("#unload").load('fetch.php');
    });
});

where dynamic() is defined as (taken from Loading MathJax Dynamically):

function dynamic(){var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://miql.zxq.net/MathJax/MathJax.js"; 
var config = 'MathJax.Hub.Config({ config: "MathJax.js" }); ' +
'MathJax.Hub.Startup.onload();';
if (window.opera) {script.innerHTML = config}
else {script.text = config}
document.getElementsByTagName("head")[0].appendChild(script);
};

Furthermore, I have the regular script to MathJax which works alright but uses an onload event.

I think I'm getting wrong the instructions to load MathJax dynamically. What is the correct way to do it? Any help will be greatly appreciate it.

  • 写回答

1条回答 默认 最新

  • dtio35880438 2010-09-29 11:46
    关注

    It sounds like you want to modify math on the page. See http://www.mathjax.org/resources/docs/?typeset.html

    Also see the demo page at http://mathjax.org/mathjax/test/sample-dynamic.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog