在github页面上以乳胶格式显示jekyll博客中的等式

时间:2016-06-18 16:27:44

标签: jekyll github-pages mathjax github-flavored-markdown

我正在尝试在github页面上托管的jekyll强力博客上编写方程式。我正在尝试按照here说明使用MathJax javascript库。基本上,我在_layouts\page.html_layouts\post.html

中添加了以下代码
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>

(从here复制)。问题是方程仍然没有在帖子上正确显示,例如,我在帖子中写了以下内容(上面和下面有一个空行):

[\\ a^2 + b^2 = c^2 \\]

而不是在页面上以latex格式显示公式,它只会转义\并向我显示以下内容

[\ a^{2} + b^{2} = c^{2} \]

其他详细信息(在_config.yml中有关突出显示的内容)如下

# Build settings
markdown: kramdown
highlighter: rouge
paginate: 5

kramdown:
   input: GFM
   hard_wrap: false
   # syntax_highlighter: rouge

另外,粘贴在_layouts\page.html

下面的代码中
---
layout: default
---
<article class="post">

  <header class="post-header">
    <h1 class="post-title">{{ page.title }}</h1>
  </header>

  <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>

  <div class="post-content">
    {{ content }}
  </div>

</article>

以及_layouts\post.html

中的代码
---
layout: default
---
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">

  <header class="post-header">
    <h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
    <p class="post-meta"><time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">{{ page.date | date: "%b %-d, %Y" }}</time>{% if page.author %} • <span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">{{ page.author }}</span></span>{% endif %}</p>
  </header>

  <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>

  <div class="post-content" itemprop="articleBody">
    {{ content }}
  </div>

</article>

任何帮助解决这个正确显示方程式的问题都将非常感谢!

谢谢!

SN248

1 个答案:

答案 0 :(得分:3)

一方面,数学分隔符应为\[...\](如果需要转义它们,则需要双反斜杠。)

另一方面,kramdown(Jekyll的默认降价解析器)有一些独特的数学块语法,它使用$$...$$作为内联和显示样式,参见http://kramdown.gettalong.org/syntax.html#math-blocks

相关问题