我知道关于这个问题已经有很多问题了,但是我还没有找到任何一个能具体回答我的问题的。
我正在使用Jekyll (AcademicPages)建立一个网站。我有好几页都是数学表达式,由于Markdown和Jekyll之间的相互作用,下划线表现不佳。
我知道这可以(部分地)通过转义下划线来解决,但我不能对整个页面都这样做。
在我的测试站点上可以看到一个例子。下面是该页面的降价文件:
---
title: "Testing"
collection: archive
type: "Type"
permalink: /testing
excerpt: ""
---
Main paragraph underscore $operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$.
<ol>
<li>Item underscores $operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$.</li>
</ol>
$$
operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)
$$
Main paragraph underscore $operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$.
<ol>
<li>Item underscores $operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$.</li>
</ol>
$$
operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)
$$
前半页使用_
,后半页使用_
。
- 在页面的前半部分,主段落中的下划线呈现得很糟糕。
- 在后半部分,列表元素和数学环境中的下划线渲染得很糟糕。
由于我的页面比我的测试页面长得多,我想知道是否有一种简单的方法来解决这个问题,而不必手动转义页面中呈现不佳的部分的下划线。
一些我尝试过但没有成功的事情:
将
{% raw %}
和{% endraw %}
分别置于主体的起始和末端。将
<span>
和</span>
放在所有形式为$...$
的表达式周围。它修复了文本周围的格式,但是下划线仍然从数学表达式中消失。将
<div>
和</div>
放在所有形式为$...$
的表达式周围。
我看到您正在使用MathJax v2.7.4,因此您可能希望更新到2.7.9版本,这是最高的v2版本(恐怕该版本的latest.js
不再正常工作,因此您将获得2.7.4版本)。如果可以的话,最好升级到版本3。
这里是一个配置,允许您使用`$...$`
和`$$...$$`
来分隔内联和显示的数学(注意美元符号周围的反勾号)。
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
skipTags: ["script","noscript","style","textarea"],
inlineMath: [['$', '$'], ['`$', '$`'], ['\(', '\)']],
displayMath: [['$$', '$$'], ['`$$', '$$`'], ['\[', '\]']]
}
});
MathJax.Hub.Register.LoadHook("[MathJax]/extensions/tex2jax.js", function () {
var TEX2JAX = MathJax.Extension.tex2jax;
TEX2JAX._createMathTag = TEX2JAX.createMathTag;
TEX2JAX.createMathTag = function (mode, tex) {
const math = this._createMathTag(mode, tex);
const code = math.parentNode;
if (code.nodeName === 'CODE' && code.childNodes.length <= 3) {
const span = document.createElement('mjx-span');
code.parentNode.replaceChild(span, code);
span.appendChild(math);
}
return math;
};
});
</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS_CHTML" defer></script>
它处理删除我提到的<code>
标签,并且还从不同的CDN获得MathJax,您可以更轻松地请求最高版本2版本。
我不确定您需要如何为此配置Jekyll,但是您应该能够提供自定义配置,并且可能能够替换要用于MathJax的实际URL,因此应该能够将其集成到您的站点中。
如果您想使用版本3,下面是相应的配置:
<script>
MathJax = {
removeCode(math, doc) {
const code = math.start.node.parentNode;
if (code.nodeName === 'CODE' && code.childNodes.length === 1) {
const span = document.createElement('mjx-span');
code.parentNode.replaceChild(span, code);
span.appendChild(code.firstChild);
}
},
options: {
skipHtmlTags: {'[-]': ['code', 'pre']},
renderActions: {
removeCode: [
11,
(doc) => {for (const math of MathJax.startup.document.math) MathJax.config.removeCode(math, doc)},
(math, doc) => MathJax.config.removeCode(math, doc),
false
]
}
},
tex: {
inlineMath: [['$', '$'], ['`$', '$`'], ['\(', '\)']],
displayMath: [['$$', '$$'], ['`$$', '$$`'], ['\[', '\]']]
}
};
</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" defer id="MathJax-script"></script>
因此,您的测试页面(使用这两种配置中的任何一种)将看起来像
Main paragraph underscore `$operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$`.
<ol>
<li>Item underscores `$operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$`.</li>
</ol>
我也在试图找到解决这个问题的方法,但不幸的是,直到现在还没有完美的解决方案。一种不太完美的方法是将{::nomarkdown}
和{:/}
放在所有数学表达式周围。但我不认为这是一个真正的解决方案的人整天处理数学像我,我期待一个完美的解决方案。
我设法通过将---
之后的所有内容放在<body>
元素中来解决这个问题。换句话说,下面的代码可以正确地呈现所有下划线:
---
title: "Testing"
collection: solutions
type: "Type"
permalink: /jech-solutions/testing
excerpt: ""
---
<body>
Main paragraph underscore $operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$.
<ol>
<li>Item underscores $operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)$.</li>
</ol>
$$
operatorname{ext}_in(X) = operatorname{ext}_in(emptyset)
$$
</body>
这些可能会导致一些问题-例如,## Heading
不再呈现为标题,并且所有换行必须伴随着<br/>
。但是,使用编程来解决这些问题要容易得多。