2017-03-29 53 views
1

我正在构建一个bookdown项目,并将它作为一个有大量数学页面的gitbook,并且呈现缓慢。我想用KaTeX代替mathJax来渲染我的数学,但我不知道如何让它工作。有一个gitbook plugin所以它应该是可能的,但我不知道如何将其与bookdown整合。KaTeX with bookdown + gitbook

在我index.Rmd文件我已经试过如下:

--- 
site: bookdown::bookdown_site 
output: 
    bookdown::gitbook: 
    pandoc_args: [--katex] 
    mathjax: NULL 
    includes: 
     in_header: katex.html 
documentclass: book 
--- 

其中katex.html由样式和主题Katex公司的。

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous"> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.js" integrity="sha384-/y1Nn9+QQAipbNQWU65krzJralCnuOasHncUFXGkdwntGeSvQicrYkiUBwsgUqc1" crossorigin="anonymous"></script> 

然而,数学不是渲染(除仍在通过MathJax呈现几部分组成)。

enter image description here

有什么办法,我得到得到bookdown与Katex公司工作?

回答

0

看来你没有读过KaTeX文档。 KaTeX不会自动渲染你的数学表达式。请参阅Github的README部分中的Automatic rendering of math on a page部分。总之,你必须加载auto-render.min.js并添加一个事件来渲染数学,例如在你katex.html,您需要:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous"> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.js" integrity="sha384-/y1Nn9+QQAipbNQWU65krzJralCnuOasHncUFXGkdwntGeSvQicrYkiUBwsgUqc1" crossorigin="anonymous"></script> 

<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/contrib/auto-render.min.js" integrity="sha384-dq1/gEHSxPZQ7DdrM82ID4YVol9BYyU7GbWlIwnwyPzotpoc57wDw/guX8EaYGPx" crossorigin="anonymous"></script> 
<script> 
    document.addEventListener("DOMContentLoaded", function() { 
    renderMathInElement(document.body); 
    }); 
</script> 

要bookdown gitbook输出禁止MathJax,你需要设置math: false在YAML,例如

--- 
site: bookdown::bookdown_site 
output: 
    bookdown::gitbook: 
    pandoc_args: [--katex] 
    mathjax: NULL 
    includes: 
     in_header: katex.html 
documentclass: book 
math: false 
--- 
+0

谢谢! KaTeX可能会在任何地方被正式支持下来? –

+0

您是第一个请求此功能的用户,我还没有考虑过支持它,但是您可以在Github上提交功能请求,所以我可能会在将来考虑它。谢谢! –