【问题标题】:Integration of Mathjax and JadeJSMathjax 和 JadeJS 的集成
【发布时间】:2012-11-12 04:54:35
【问题描述】:

我在 Express 中集成 Mathjax 和 Jade 时遇到问题。我需要在“pre”中显示公式,所以我试图通过脚本配置 Mathjax。 这是我的代码:

script(type="text/x-mathjax-config")
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [['$','$'], ['\\(','\\)']],
            skipTags: ["script","noscript","style","textarea","code"]   
            }

    });

我的问题是,当我尝试查看该页面时,它会抛出此错误:

SyntaxError: Unexpected token {

at Object.Function (unknown source)
at Object.exports.compile (/home/andres/web/node-login/node_modules/jade/lib/jade.js:176:8)
at Function.exports.compile (/home/andres/web/node-login/node_modules/express/lib/view.js:68:33)
at ServerResponse.res._render (/home/andres/web/node-login/node_modules/express/lib/view.js:417:18)
at ServerResponse.res.render (/home/andres/web/node-login/node_modules/express/lib/view.js:318:17)
at Promise.module.exports.app.get.Pregunta.find.exec.questions (/home/andres/web/node-login/app/server/router.js:240:16)
at Promise.addBack (/home/andres/web/node-login/node_modules/mongoose/lib/promise.js:128:8)
at Promise.EventEmitter.emit (events.js:88:17)
at Promise.emit (/home/andres/web/node-login/node_modules/mongoose/lib/promise.js:66:38)
at Promise.complete (/home/andres/web/node-login/node_modules/mongoose/lib/promise.js:77:20)

有人知道会发生什么吗?

谢谢。

【问题讨论】:

    标签: javascript node.js express pug mathjax


    【解决方案1】:

    问题似乎与type='text/x-mathjax-config' 有关。如果我删除它,视图会很好地呈现。如果我保持原样,翡翠会将脚本内容解释为翡翠标签。我不认为这是jade中的错误,因为文本模板应该也可以用jade编写。

    无论如何,看起来 mathjax 需要类型才能正确执行配置,所以我们需要解决这个问题。最简单的解决方案是简单地保持一切原样,但在脚本标签的末尾添加.。这将使它下面的所有内容成为文本文字。

    script(type="text/x-mathjax-config").
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [['$','$'], ['\\(','\\)']],
          skipTags: ["script","noscript","style","textarea","code"]
        }
      });
    

    或者,也许您可​​以在页面加载后配置 mathjax,如 here 所示。请注意,我对 mathjax 一无所知,我只是看了一眼文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      • 2012-11-15
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      • 2015-03-09
      • 2017-08-04
      相关资源
      最近更新 更多