我正在尝试设置jekyll以正确显示数学。
如果我不在div标签中嵌套方程式,问题就不会呈现保护他们免受降价分析器的侵害:(
---
layout: default
math: true
---
# Using Mathjax
along markdown parsers is a real pain...
$$ a + b = c $$
doesn't show, though the following does:
<div>
$$ x + y + c $$
</div>
布局测试通过包含{% if page.math %}
包含以下mathjax脚本:
<script async src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_CHTML"></script>
我很困惑,因为:
关于此主题已经有很多东西,但是已经过时了!对于平滑和简单配置的任何帮助将不胜感激。
问题是kramdown的输出不再与mathjax v3兼容。
您可以在建议的脚本标记内嵌套$$ a + b = c$$
时检查kramdown是否起作用:
<script type="tex/math"> a = b + c </script>
但是mathjax不再使用这些脚本标签,如here所述(最后一项)。
因此,使kramdown与mathjax一起工作需要:
MathJax = {
options: {
renderActions: {
find: [10, function (doc) {
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
const display = !!node.type.match(/; *mode=display/);
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
const text = document.createTextNode('');
node.parentNode.replaceChild(text, node);
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
}
}, '']
}
}
};
虽然不知道为什么这种向后的战斗力而不是简单的选项切换...