2012-11-23 12 views
1

我在快速集成Mathjax和Jade时遇到了问题。我需要在'pre'中显示公式,所以我正在尝试通过脚本配置Mathjax。 这是我的代码:Mathjax和JadeJS的集成

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

    }); 

我的问题是,当我尝试看看的页面,它抛出这个错误:

语法错误:意外标记{

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) 

有谁知道可能会发生什么?

谢谢。

回答

4

这个问题似乎与type='text/x-mathjax-config'。如果我删除它,视图呈现很好。如果我保持原样,玉将脚本内容解释为玉标签。我不认为这是玉的错误,因为文本模板也应该能够用玉来写。

在任何情况下,它看起来像mathjax需要的类型才能正确执行配置,所以我们需要解决该问题。最简单的解决方案就是将所有内容保持原样,但在脚本标记末尾添加.。这将使得它下面的所有内容成为文本文字。

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

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

+0

非常感谢!我把这个。它的工作。 – andresmechali