在 github 页面上使用 Jekyll 在 MathJax 中呈现一些乳胶语法时遇到问题
Trouble rendering some latex syntax in MathJax with Jekyll on github pages
我发现在我的 git 页面中,一些 Latex 语法无法使用 MathJax 和 Jekyll 呈现。
例如 this post
这一行:
$z = \overbrace{\underbrace{x}\text{实数} +\underbrace{iy}\text{虚数}}^\text{复数}$
应该是这样的
其他一些 Latex 语法效果很好,比如 this
我应该添加什么来解决这个问题?我猜 MathJax 没有加载所需的库(例如 \usepackage{amsmath} 在上述情况下)。
页面代码为here。
以下代码显示了我的matjax配置。
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ TeX: { equationNumbers: { autoNumber: "all" } } }); </script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\(","\)"] ],
processEscapes: true
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
请注意,在 Jekyll 的 Markdown 语法中,下划线用于指示斜体文本,因此 Jekyll 在下划线所在的 \text{real} +\underbrace{iy}
周围插入 <em>
标记(注意输出中缺少下划线并且文本是斜体)。 MathJax 无法处理包含 HTML 标签的数学,所以这个数学等式被跳过。
您需要确保 Markdown 不会干扰您的 TeX 符号。这可以通过多种方式完成。您可以使用 \_
而不是 _
以防止将下划线解释为斜体。或者,您可以根据建议 here.
围绕内联数学使用 <span>...</span>
并围绕显示数学使用 <div>...</div>
只是一个 hunch 但是看看你问题中发布的代码,我认为最好保留所有与 MathJax 相关的 stuff 在 <script>
标签内。我写这篇文章是因为我还没有发现需要将任何东西包装在 <span>
.
中
这是我的 _includes/mathjax.html
文件的样子,将 docs...
的两个块拼凑在一起
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\(','\)']],
processEscapes: true
}
});
</script>
...这就是我包含它的方式...
---
layout: post
title: Some of Thing
---
{%- include mathjax.html -%}
Notes about $ \sum_{Thing} $
Note how the configs are within the same <script>
tag as what is doing the sourcing (src
="<url-or-path>"
),
为了完整性 post source to go with rendered post,它使用 $$
方式在源代码的前 30 行内进行多行格式化,然后是 $
行方式在呈现版本的第一个 code
格式化块(在注释中)之后执行操作。
并且(我想是为了加分),我认为更正后的代码可能看起来像问题。
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
MathJax.Hub.Config({ TeX: { equationNumbers: { autoNumber: "all" } } });
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\(","\)"] ],
processEscapes: true
}
});
</script>
我在测试中发现的另一件值得注意的事情是 \(
... \sum_{Thing}
... \)
,内联语法 not 触发 Jekyll 用来向这些东西添加 html 标签的任何预解析器;换句话说,我不得不使用 $
... \sum_{Thing}
... $
语法,甚至在为 MathJax 的 src
ing.
添加任何配置之前
对于那些走到这一步但出于某种原因想要减少 CDN 使用的人,你可能会对 other answer 感兴趣,我已经发布了关于让 MathJax 和 Jekyll 到 好好玩耍.
对于那些想要一些 Liquid 到 JavaScript 配置翻译的人,现在可以使用 liquid-utilities/includes-mathjax
;允许通过 _config.yml
和个人 post/page FrontMatter 配置 MathJax。
我发现在我的 git 页面中,一些 Latex 语法无法使用 MathJax 和 Jekyll 呈现。
例如 this post
这一行: $z = \overbrace{\underbrace{x}\text{实数} +\underbrace{iy}\text{虚数}}^\text{复数}$
应该是这样的
其他一些 Latex 语法效果很好,比如 this
我应该添加什么来解决这个问题?我猜 MathJax 没有加载所需的库(例如 \usepackage{amsmath} 在上述情况下)。
页面代码为here。
以下代码显示了我的matjax配置。
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ TeX: { equationNumbers: { autoNumber: "all" } } }); </script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\(","\)"] ],
processEscapes: true
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
请注意,在 Jekyll 的 Markdown 语法中,下划线用于指示斜体文本,因此 Jekyll 在下划线所在的 \text{real} +\underbrace{iy}
周围插入 <em>
标记(注意输出中缺少下划线并且文本是斜体)。 MathJax 无法处理包含 HTML 标签的数学,所以这个数学等式被跳过。
您需要确保 Markdown 不会干扰您的 TeX 符号。这可以通过多种方式完成。您可以使用 \_
而不是 _
以防止将下划线解释为斜体。或者,您可以根据建议 here.
<span>...</span>
并围绕显示数学使用 <div>...</div>
只是一个 hunch 但是看看你问题中发布的代码,我认为最好保留所有与 MathJax 相关的 stuff 在 <script>
标签内。我写这篇文章是因为我还没有发现需要将任何东西包装在 <span>
.
这是我的 _includes/mathjax.html
文件的样子,将 docs...
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\(','\)']],
processEscapes: true
}
});
</script>
...这就是我包含它的方式...
---
layout: post
title: Some of Thing
---
{%- include mathjax.html -%}
Notes about $ \sum_{Thing} $
Note how the configs are within the same
<script>
tag as what is doing the sourcing (src
="<url-or-path>"
),
为了完整性 post source to go with rendered post,它使用 $$
方式在源代码的前 30 行内进行多行格式化,然后是 $
行方式在呈现版本的第一个 code
格式化块(在注释中)之后执行操作。
并且(我想是为了加分),我认为更正后的代码可能看起来像问题。
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
MathJax.Hub.Config({ TeX: { equationNumbers: { autoNumber: "all" } } });
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\(","\)"] ],
processEscapes: true
}
});
</script>
我在测试中发现的另一件值得注意的事情是 \(
... \sum_{Thing}
... \)
,内联语法 not 触发 Jekyll 用来向这些东西添加 html 标签的任何预解析器;换句话说,我不得不使用 $
... \sum_{Thing}
... $
语法,甚至在为 MathJax 的 src
ing.
对于那些走到这一步但出于某种原因想要减少 CDN 使用的人,你可能会对 other answer 感兴趣,我已经发布了关于让 MathJax 和 Jekyll 到 好好玩耍.
对于那些想要一些 Liquid 到 JavaScript 配置翻译的人,现在可以使用 liquid-utilities/includes-mathjax
;允许通过 _config.yml
和个人 post/page FrontMatter 配置 MathJax。