【问题标题】:How to Avoid MathJAX Typeset Queue Error when loading new data into DOM将新数据加载到 DOM 时如何避免 MathJAX 排版队列错误
【发布时间】:2018-10-26 06:03:26
【问题描述】:

我的网站使用 javascript 函数将数学标记加载(通过 AJAX)到 DOM 中,然后使用 MathJAX 渲染它。

如果该函数被第二次调用(即,将一些新的数学标记加载到 DOM 元素中):

  • 如果 MathJAX 在第二次函数调用之前完成了其排版队列的处理,则一切正常。

  • 如果 MathJAX 在第二次函数调用之前尚未完成其排版队列的处理,则会出现错误。

    MathJax.js?config=TeX-MML-AM_CHTML&latest:19 Uncaught TypeError: Cannot read property 'contains' of null

一旦发生错误,MathJAX 就会处于错误状态,并且在完全重新加载(例如,通过页面重新加载)之前无法运行。

似乎最简单的解决方案是在通过 AJAX 加载新数学之前清除 MathJAX 排版队列,但我在 MathJAX API 中找不到清除排版队列的方法。

这是我正在使用的函数的精简版本(使用 jQuery 语法):

window.loadNewMath = function() {
    // I want to clear the MathJAX Typeset queue before making the AJAX call

    $.ajax({
        dataType: "json",
        type: "POST",
        url: "/getNewMath",
        data: [],
        success: function(data) {
            if (data['success']) {
                // load math into DOM
                $("#math-panel").html(data.new_math);
                MathJax.Hub.Queue(["Typeset", MathJax.Hub, 'math-panel']);
            } else {
                $("#math-panel").html('oops. there was a database error');
            }
        },
        error: function(data) {
            $("#math-panel").html('oops. there was an ajax error');
        }
    })
}

这种情况似乎是一个常见的用例,所以我希望有人能推荐一种避免这个错误的方法。

【问题讨论】:

    标签: javascript mathjax


    【解决方案1】:

    从 MathJax 开发者处收到的答案:

    https://github.com/mathjax/MathJax/issues/2071

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      相关资源
      最近更新 更多