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 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型