问题描述
我在Express中集成Mathjax和Jade时遇到问题。我需要在'pre'中显示公式,所以我试图通过脚本配置Mathjax。 这是我的代码:
I have a problem integrating Mathjax and Jade in Express. I need to show formulas inside a 'pre', so I am trying to configure Mathjax through a script. This is my code:
script(type="text/x-mathjax-config")
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
skipTags: ["script","noscript","style","textarea","code"]
}
});
我的问题是当我尝试查看页面时会抛出此错误:
SyntaxError:Object.Function上的意外标记{
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)
有谁知道可能会发生什么?
Does anyone know what might be happening?
谢谢。
推荐答案
问题似乎是 type ='text / x-mathjax-config'
。如果我删除它,视图呈现正常。如果我保持原样,jade将脚本内容解释为jade标签。我不认为这是玉的错误,因为文本模板也应该能够用玉写。
The issue appears to be with the type='text/x-mathjax-config'
. If I remove that, the view renders fine. If I leave it as it is, jade interprets the script contents as jade tags. I don't think this is a bug in jade, since text templates should be able to be able to be written in jade as well.
无论如何,它看起来像mathjax需要类型才能正确执行配置,所以我们需要解决这个问题。最简单的解决方案就是保持原样,但在脚本标记的末尾添加。
。这将使其下的所有内容成为文本文字。
In any case, it looks like mathjax requires the type in order to execute the configuration properly, so we need to work around that issue. The easiest solution is simply to keep everything as it is but add a .
at the end of the script tag. This will make everything under it a text literal.
script(type="text/x-mathjax-config").
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
skipTags: ["script","noscript","style","textarea","code"]
}
});
或者,也许你可以在页面加载后配置mathjax,如图所示。请注意,我对mathjax一无所知,我只是看了一下文档。
Alternatively, maybe you could configure mathjax after the page is loaded, as seen here. Note that I know nothing about mathjax, I just glanced at the documentation.
这篇关于Mathjax和JadeJS的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!