使用 Jekyll 解析 Mathjax
Mathjax being parsed with Jekyll
我已经尝试了一段时间让 MathJax 使用 Jekyll 正确渲染。
我尝试了几种解析器(常规、kramdown
和 redcarpet
),但 none 似乎可以满足我的要求。我也尝试了这里提到的所有解决方案:Using MathJax with Jekyll
问题是我正在使用规则写下一些方程式。我使用简单的 html 创建了一个最小的工作示例,以确保我的代码实际上是有效的。你可以在这里看到:http://call-cc.be/files/example.html
我只想在我的 jekyll 生成的网站上显示确切的代码(好吧,我会在它工作后更改它)。
但是,解析器正在读取 mathjax 并抱怨未关闭 liquid 标签:
Configuration file: /Users/m1dnight/vcs/cdetroye.github.io/_config.yml
Source: /Users/m1dnight/vcs/cdetroye.github.io
Destination: /Users/m1dnight/vcs/cdetroye.github.io/_site
Incremental build: disabled. Enable with --incremental
Generating...
Liquid Exception: Liquid syntax error: Variable '{{#1}' was not properly terminated with regexp: /\}\}/ in /Users/m1dnight/vcs/cdetroye.github.io/_posts/2015-11-11-stlc.md
jekyll 3.0.1 | Error: Liquid syntax error: Variable '{{#1}' was not properly terminated with regexp: /\}\}/
除了上面提到的我尝试过的解决方案之外,我还尝试将代码放在 {%raw%}
标记中,并且只呈现实际的 mathjax 代码,包括一些 <p>
在这里和那里。
我尝试的另一个解决方案是我找到的这个插件,但同样无济于事。 https://gist.github.com/jessykate/834610
我尝试渲染的完整 post 如下所示。小心,有点长。
---
layout: post
title: Work goddamnit
---
Foo bar bar
<div>
$$
\newcommand{\lolli}{\multimap}
\newcommand{\tensor}{\otimes}
\newcommand{\with}{\&}
\newcommand{\all}[2]{\forall {#1}.\;{#2}}
\newcommand{\fix}[2]{\mu {#1}.\;{#2}}
\newcommand{\letv}[3]{\mathsf{let}\,{#1} = {#2}\;\mathsf{in}\;{#3}}
\newcommand{\Fun}[2]{\Lambda {#1}.\;{#2}}
\newcommand{\fun}[2]{\lambda {#1}.\;{#2}}
\newcommand{\unit}{\left(\right)}
\newcommand{\letunit}[2]{\letv{\unit}{#1}{#2}}
\newcommand{\pair}[2]{\left({#1},{#2}\right)}
\newcommand{\letpair}[4]{\letv{\pair{#1}{#2}}{#3}{#4}}
\newcommand{\unita}{\left[\right]}
\newcommand{\paira}[2]{\left[{#1}, {#2}\right]}
\newcommand{\fst}[1]{\mathsf{fst}\,{#1}}
\newcommand{\snd}[1]{\mathsf{snd}\,{#1}}
\newcommand{\inl}[1]{\mathsf{inl}\,{#1}}
\newcommand{\inr}[1]{\mathsf{inr}\,{#1}}
\newcommand{\case}[5]{\mathsf{case}({#1}, \inl{#2} \to {#3}, \inr{#4} \to {#5})}
\newcommand{\abort}[1]{\mathsf{abort}\,{#1}}
\newcommand{\fold}[1]{\mathsf{in}\,{#1}}
\newcommand{\unfold}[1]{\mathsf{out}\,{#1}}
\newcommand{\judge}[4]{{#1};{#2} \vdash {#3} : {#4}}
\newcommand{\judgetp}[2]{{#1} \vdash {#2} : \mathsf{type}}
\newcommand{\judgectx}[2]{{#1} \vdash {#2} : \mathsf{ctx}}
%% Rule names
\newcommand{\rulename}[3]{{#2}{\mathrm{#3}}_{\mathrm{#1}}}
\newcommand{\intro}[2][]{\rulename{#1}{#2}{I}}
\newcommand{\elim}[2][]{\rulename{#1}{#2}{E}}
\newcommand{\Var}{\rulename{}{}{Var}}
\newcommand{\AllI}{\intro{\forall}}
\newcommand{\AllE}{\elim{\forall}}
\newcommand{\LolliI}{\intro{\lolli}}
\newcommand{\LolliE}{\elim{\lolli}}
\newcommand{\UnitI}{\intro{1}}
\newcommand{\UnitE}{\elim{1}}
\newcommand{\TensorI}{\intro{\tensor}}
\newcommand{\TensorE}{\elim{\tensor}}
\newcommand{\TopI}{\intro{\top}}
\newcommand{\TopE}{\elim{\top}}
\newcommand{\WithI}{\intro{\with}}
\newcommand{\WithEFst}{\elim[fst]{\with}}
\newcommand{\WithESnd}{\elim[snd]{\with}}
\newcommand{\ZeroI}{\intro{0}}
\newcommand{\ZeroE}{\elim{0}}
\newcommand{\SumIInl}{\intro[inl]{\oplus}}
\newcommand{\SumIInr}{\intro[inr]{\oplus}}
\newcommand{\SumE}{\elim{\oplus}}
\newcommand{\MuI}{\intro{\mu}}
\newcommand{\MuE}{\elim{\mu}}
\newcommand{\size}[1]{\left|#1\right|}
\newcommand{\inferrule}[3][]{\frac{#2}{#3}\;{#1}}
$$
$$
\boxed{\judge{\Delta}{\Gamma}{e}{A}}
\
\inferrule[\Var]
{ }
{\judge{\Delta}{x:A}{x}{A}}
\
\begin{array}{cc}
\inferrule[\AllI]
{\judge{\Delta, \alpha}{\Gamma}{e}{A}}
{\judge{\Delta}{\Gamma}{\Fun{\alpha}{e}}{\all{\alpha}{A}}}
&
\inferrule[\AllE]
{\judge{\Delta}{\Gamma}{e}{\all{\alpha}{B}} \
\judgetp{\Delta}{A}}
{\judge{\Delta}{\Gamma}{e\;A}{[A/\alpha]B}}
\[2em]
\inferrule[\LolliI]
{\judge{\Delta}{\Gamma, x:A}{e}{B}}
{\judge{\Delta}{\Gamma}{\fun{x:A}{e}}{A \to B}}
&
\inferrule[\LolliE]
{\judge{\Delta}{\Gamma}{e}{A \to B} \
\judge{\Delta}{\Gamma'}{e'}{A}}
{\judge{\Delta}{\Gamma,\Gamma'}{e\;e'}{B}}
\[2em]
\inferrule[\UnitI]
{ }
{\judge{\Delta}{\cdot}{\unit}{1}}
&
\inferrule[\UnitE]
{\judge{\Delta}{\Gamma}{e}{1} \
\judge{\Delta}{\Gamma'}{e'}{C}}
{\judge{\Delta}{\Gamma,\Gamma'}{\letunit{e}{e'}}{C}}
\[2em]
\inferrule[\TensorI]
{\judge{\Delta}{\Gamma}{e}{A} \
\judge{\Delta}{\Gamma'}{e'}{B} }
{\judge{\Delta}{\Gamma,\Gamma'}{\pair{e}{e'}}{A \tensor B}}
&
\inferrule[\TensorE]
{\judge{\Delta}{\Gamma}{e}{A \tensor B} \\
\judge{\Delta}{\Gamma', x:A, y:B}{e'}{C}}
{\judge{\Delta}{\Gamma,\Gamma'}{\letpair{x}{y}{e}{e'}}{C}}
\[2em]
\inferrule[\TopI]
{ }
{\judge{\Delta}{\Gamma}{\unita}{\top}}
&
\[1em]
\inferrule[\WithI]
{\judge{\Delta}{\Gamma}{e}{A} \
\judge{\Delta}{\Gamma}{e'}{B} }
{\judge{\Delta}{\Gamma}{\paira{e}{e'}}{A \with B}}
&
\begin{array}{l}
\inferrule[\WithEFst]
{\judge{\Delta}{\Gamma}{e}{A \with B}}
{\judge{\Delta}{\Gamma}{\fst{e}}{A}}
\[1em]
\inferrule[\WithESnd]
{\judge{\Delta}{\Gamma}{e}{A \with B}}
{\judge{\Delta}{\Gamma}{\snd{e}}{B}}
\end{array}
\[3em]
\begin{array}{l}
\inferrule[\SumIInl]
{\judge{\Delta}{\Gamma}{e}{A }}
{\judge{\Delta}{\Gamma}{\inl{e}}{A \oplus B}}
\[1em]
\inferrule[\SumIInr]
{\judge{\Delta}{\Gamma}{e}{ B}}
{\judge{\Delta}{\Gamma}{\inr{e}}{A \oplus B}}
\end{array}
&
\begin{array}{l}
\inferrule[\SumE]
{\judge{\Delta}{\Gamma}{e}{A \oplus B} \\
\judge{\Delta}{\Gamma', x:A}{e'}{C} \\
\judge{\Delta}{\Gamma', y:B}{e''}{C} }
{\judge{\Delta}{\Gamma, \Gamma'}{\case{e}{x}{e'}{y}{e''}}{C}}
\end{array}
\[3em]
&
\inferrule[\ZeroE]
{\judge{\Delta}{\Gamma}{e}{0}}
{\judge{\Delta}{\Gamma}{\abort{e}}{C}}
\end{array}
$$
$$a^2 + b^2 = c^2$$
$$
\begin{array}{lcl}
(\Fun{\alpha}{e})\;A & \mapsto & [A/\alpha]e \
(\fun{x:A}{e})\;e' & \mapsto & [e'/x]e \
\letv{\unit}{\unit}{e'} & \mapsto & e' \
\letv{\pair{x}{y}}{\pair{e_1}{e_2}}{e'} & \mapsto & [e_1/x, e_2/y]e' \
\fst{\paira{e}{e'}} & \mapsto & e \
\snd{\paira{e}{e'}} & \mapsto & e' \
\case{\inl{e}}{x}{e'}{y}{e''} & \mapsto & [e/x]e' \
\case{\inr{e}}{x}{e'}{y}{e''} & \mapsto & [e/y]e'' \
\end{array}
$$</div>
The end.
我们这里有两个问题:
由于大括号,Liquid 正在解析您的代码。我们使用 {% raw %}{% endraw %}
标签。
Kramdown 还将您的 mathjax 解析为代码并将其嵌入
<div class="highlighter-rouge"><pre class="highlight"><code>
Your code here
</code></pre></div>
这是因为您的代码缩进了四个或更多空格。
为避免这种情况,您可以删除缩进或使用 {::nomarkdown}{:/}
标签。
这绝对可以解决这个问题:
{% raw %}{::nomarkdown}
<div>
$$
\newcommand{\lolli}{\multimap}
\newcommand{\tensor}{\otimes}
... More mathjax here
$$
</div>
{:/}{% endraw %}
我已经尝试了一段时间让 MathJax 使用 Jekyll 正确渲染。
我尝试了几种解析器(常规、kramdown
和 redcarpet
),但 none 似乎可以满足我的要求。我也尝试了这里提到的所有解决方案:Using MathJax with Jekyll
问题是我正在使用规则写下一些方程式。我使用简单的 html 创建了一个最小的工作示例,以确保我的代码实际上是有效的。你可以在这里看到:http://call-cc.be/files/example.html
我只想在我的 jekyll 生成的网站上显示确切的代码(好吧,我会在它工作后更改它)。
但是,解析器正在读取 mathjax 并抱怨未关闭 liquid 标签:
Configuration file: /Users/m1dnight/vcs/cdetroye.github.io/_config.yml
Source: /Users/m1dnight/vcs/cdetroye.github.io
Destination: /Users/m1dnight/vcs/cdetroye.github.io/_site
Incremental build: disabled. Enable with --incremental
Generating...
Liquid Exception: Liquid syntax error: Variable '{{#1}' was not properly terminated with regexp: /\}\}/ in /Users/m1dnight/vcs/cdetroye.github.io/_posts/2015-11-11-stlc.md
jekyll 3.0.1 | Error: Liquid syntax error: Variable '{{#1}' was not properly terminated with regexp: /\}\}/
除了上面提到的我尝试过的解决方案之外,我还尝试将代码放在 {%raw%}
标记中,并且只呈现实际的 mathjax 代码,包括一些 <p>
在这里和那里。
我尝试的另一个解决方案是我找到的这个插件,但同样无济于事。 https://gist.github.com/jessykate/834610
我尝试渲染的完整 post 如下所示。小心,有点长。
---
layout: post
title: Work goddamnit
---
Foo bar bar
<div>
$$
\newcommand{\lolli}{\multimap}
\newcommand{\tensor}{\otimes}
\newcommand{\with}{\&}
\newcommand{\all}[2]{\forall {#1}.\;{#2}}
\newcommand{\fix}[2]{\mu {#1}.\;{#2}}
\newcommand{\letv}[3]{\mathsf{let}\,{#1} = {#2}\;\mathsf{in}\;{#3}}
\newcommand{\Fun}[2]{\Lambda {#1}.\;{#2}}
\newcommand{\fun}[2]{\lambda {#1}.\;{#2}}
\newcommand{\unit}{\left(\right)}
\newcommand{\letunit}[2]{\letv{\unit}{#1}{#2}}
\newcommand{\pair}[2]{\left({#1},{#2}\right)}
\newcommand{\letpair}[4]{\letv{\pair{#1}{#2}}{#3}{#4}}
\newcommand{\unita}{\left[\right]}
\newcommand{\paira}[2]{\left[{#1}, {#2}\right]}
\newcommand{\fst}[1]{\mathsf{fst}\,{#1}}
\newcommand{\snd}[1]{\mathsf{snd}\,{#1}}
\newcommand{\inl}[1]{\mathsf{inl}\,{#1}}
\newcommand{\inr}[1]{\mathsf{inr}\,{#1}}
\newcommand{\case}[5]{\mathsf{case}({#1}, \inl{#2} \to {#3}, \inr{#4} \to {#5})}
\newcommand{\abort}[1]{\mathsf{abort}\,{#1}}
\newcommand{\fold}[1]{\mathsf{in}\,{#1}}
\newcommand{\unfold}[1]{\mathsf{out}\,{#1}}
\newcommand{\judge}[4]{{#1};{#2} \vdash {#3} : {#4}}
\newcommand{\judgetp}[2]{{#1} \vdash {#2} : \mathsf{type}}
\newcommand{\judgectx}[2]{{#1} \vdash {#2} : \mathsf{ctx}}
%% Rule names
\newcommand{\rulename}[3]{{#2}{\mathrm{#3}}_{\mathrm{#1}}}
\newcommand{\intro}[2][]{\rulename{#1}{#2}{I}}
\newcommand{\elim}[2][]{\rulename{#1}{#2}{E}}
\newcommand{\Var}{\rulename{}{}{Var}}
\newcommand{\AllI}{\intro{\forall}}
\newcommand{\AllE}{\elim{\forall}}
\newcommand{\LolliI}{\intro{\lolli}}
\newcommand{\LolliE}{\elim{\lolli}}
\newcommand{\UnitI}{\intro{1}}
\newcommand{\UnitE}{\elim{1}}
\newcommand{\TensorI}{\intro{\tensor}}
\newcommand{\TensorE}{\elim{\tensor}}
\newcommand{\TopI}{\intro{\top}}
\newcommand{\TopE}{\elim{\top}}
\newcommand{\WithI}{\intro{\with}}
\newcommand{\WithEFst}{\elim[fst]{\with}}
\newcommand{\WithESnd}{\elim[snd]{\with}}
\newcommand{\ZeroI}{\intro{0}}
\newcommand{\ZeroE}{\elim{0}}
\newcommand{\SumIInl}{\intro[inl]{\oplus}}
\newcommand{\SumIInr}{\intro[inr]{\oplus}}
\newcommand{\SumE}{\elim{\oplus}}
\newcommand{\MuI}{\intro{\mu}}
\newcommand{\MuE}{\elim{\mu}}
\newcommand{\size}[1]{\left|#1\right|}
\newcommand{\inferrule}[3][]{\frac{#2}{#3}\;{#1}}
$$
$$
\boxed{\judge{\Delta}{\Gamma}{e}{A}}
\
\inferrule[\Var]
{ }
{\judge{\Delta}{x:A}{x}{A}}
\
\begin{array}{cc}
\inferrule[\AllI]
{\judge{\Delta, \alpha}{\Gamma}{e}{A}}
{\judge{\Delta}{\Gamma}{\Fun{\alpha}{e}}{\all{\alpha}{A}}}
&
\inferrule[\AllE]
{\judge{\Delta}{\Gamma}{e}{\all{\alpha}{B}} \
\judgetp{\Delta}{A}}
{\judge{\Delta}{\Gamma}{e\;A}{[A/\alpha]B}}
\[2em]
\inferrule[\LolliI]
{\judge{\Delta}{\Gamma, x:A}{e}{B}}
{\judge{\Delta}{\Gamma}{\fun{x:A}{e}}{A \to B}}
&
\inferrule[\LolliE]
{\judge{\Delta}{\Gamma}{e}{A \to B} \
\judge{\Delta}{\Gamma'}{e'}{A}}
{\judge{\Delta}{\Gamma,\Gamma'}{e\;e'}{B}}
\[2em]
\inferrule[\UnitI]
{ }
{\judge{\Delta}{\cdot}{\unit}{1}}
&
\inferrule[\UnitE]
{\judge{\Delta}{\Gamma}{e}{1} \
\judge{\Delta}{\Gamma'}{e'}{C}}
{\judge{\Delta}{\Gamma,\Gamma'}{\letunit{e}{e'}}{C}}
\[2em]
\inferrule[\TensorI]
{\judge{\Delta}{\Gamma}{e}{A} \
\judge{\Delta}{\Gamma'}{e'}{B} }
{\judge{\Delta}{\Gamma,\Gamma'}{\pair{e}{e'}}{A \tensor B}}
&
\inferrule[\TensorE]
{\judge{\Delta}{\Gamma}{e}{A \tensor B} \\
\judge{\Delta}{\Gamma', x:A, y:B}{e'}{C}}
{\judge{\Delta}{\Gamma,\Gamma'}{\letpair{x}{y}{e}{e'}}{C}}
\[2em]
\inferrule[\TopI]
{ }
{\judge{\Delta}{\Gamma}{\unita}{\top}}
&
\[1em]
\inferrule[\WithI]
{\judge{\Delta}{\Gamma}{e}{A} \
\judge{\Delta}{\Gamma}{e'}{B} }
{\judge{\Delta}{\Gamma}{\paira{e}{e'}}{A \with B}}
&
\begin{array}{l}
\inferrule[\WithEFst]
{\judge{\Delta}{\Gamma}{e}{A \with B}}
{\judge{\Delta}{\Gamma}{\fst{e}}{A}}
\[1em]
\inferrule[\WithESnd]
{\judge{\Delta}{\Gamma}{e}{A \with B}}
{\judge{\Delta}{\Gamma}{\snd{e}}{B}}
\end{array}
\[3em]
\begin{array}{l}
\inferrule[\SumIInl]
{\judge{\Delta}{\Gamma}{e}{A }}
{\judge{\Delta}{\Gamma}{\inl{e}}{A \oplus B}}
\[1em]
\inferrule[\SumIInr]
{\judge{\Delta}{\Gamma}{e}{ B}}
{\judge{\Delta}{\Gamma}{\inr{e}}{A \oplus B}}
\end{array}
&
\begin{array}{l}
\inferrule[\SumE]
{\judge{\Delta}{\Gamma}{e}{A \oplus B} \\
\judge{\Delta}{\Gamma', x:A}{e'}{C} \\
\judge{\Delta}{\Gamma', y:B}{e''}{C} }
{\judge{\Delta}{\Gamma, \Gamma'}{\case{e}{x}{e'}{y}{e''}}{C}}
\end{array}
\[3em]
&
\inferrule[\ZeroE]
{\judge{\Delta}{\Gamma}{e}{0}}
{\judge{\Delta}{\Gamma}{\abort{e}}{C}}
\end{array}
$$
$$a^2 + b^2 = c^2$$
$$
\begin{array}{lcl}
(\Fun{\alpha}{e})\;A & \mapsto & [A/\alpha]e \
(\fun{x:A}{e})\;e' & \mapsto & [e'/x]e \
\letv{\unit}{\unit}{e'} & \mapsto & e' \
\letv{\pair{x}{y}}{\pair{e_1}{e_2}}{e'} & \mapsto & [e_1/x, e_2/y]e' \
\fst{\paira{e}{e'}} & \mapsto & e \
\snd{\paira{e}{e'}} & \mapsto & e' \
\case{\inl{e}}{x}{e'}{y}{e''} & \mapsto & [e/x]e' \
\case{\inr{e}}{x}{e'}{y}{e''} & \mapsto & [e/y]e'' \
\end{array}
$$</div>
The end.
我们这里有两个问题:
由于大括号,Liquid 正在解析您的代码。我们使用 {% raw %}{% endraw %}
标签。
Kramdown 还将您的 mathjax 解析为代码并将其嵌入
<div class="highlighter-rouge"><pre class="highlight"><code>
Your code here
</code></pre></div>
这是因为您的代码缩进了四个或更多空格。
为避免这种情况,您可以删除缩进或使用 {::nomarkdown}{:/}
标签。
这绝对可以解决这个问题:
{% raw %}{::nomarkdown}
<div>
$$
\newcommand{\lolli}{\multimap}
\newcommand{\tensor}{\otimes}
... More mathjax here
$$
</div>
{:/}{% endraw %}