2017-03-29 30 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上提交功能請求,所以我可能會在將來考慮它。謝謝! –