我正在构建一个bookdown项目,并将其呈现为一个带有大量数学页面的gitbook,并且呈现缓慢。我想使用KaTeX而不是mathJax来渲染我的数学,但我不确定如何使它工作。有一个gitbook plugin所以它应该是可能的,但我不太清楚如何将其与bookdown集成。
在我的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渲染的一些部分)。
我有什么方法可以预订与KaTeX合作吗?
答案 0 :(得分:1)
您似乎没有阅读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,您需要在YAML中设置math: false
,例如
---
site: bookdown::bookdown_site
output:
bookdown::gitbook:
pandoc_args: [--katex]
mathjax: NULL
includes:
in_header: katex.html
documentclass: book
math: false
---
答案 1 :(得分:1)
我无法获得Yihui的建议,但是从<SalesQuoteCollection>
<SalesQuote>
<CurrencyCode>GBP</CurrencyCode>
<TaxAmount>0.000000</TaxAmount>
<PriceDateTime>2020-03-17T14:52:55.439</PriceDateTime>
<DocumentLanguageCode>EN</DocumentLanguageCode>
<SalesQuoteParty>
<SalesQuoteParty>
<PartyName>Porter LLC</PartyName>
<PartyID>1001</PartyID>
<RoleCode>1001</RoleCode>
<RoleCodeText>Account</RoleCodeText>
<FirstLineName>Porter LLC</FirstLineName>
</SalesQuoteParty>
<SalesQuoteParty>
<PartyName>Manish Admin</PartyName>
<PartyID>8000000705</PartyID>
<RoleCode>39</RoleCode>
<RoleCodeText>Owner</RoleCodeText>
<FirstLineName>Mr. Manish Admin</FirstLineName>
</SalesQuoteParty>
<SalesQuoteParty>
<PartyName>Manish Admin</PartyName>
<PartyID>8000000705</PartyID>
<RoleCode>40</RoleCode>
<RoleCodeText>Owner</RoleCodeText>
<FirstLineName>Mr. Manish Admin</FirstLineName>
</SalesQuoteParty>
</SalesQuoteParty>
<ProcessingTypeCode>AG</ProcessingTypeCode>
</SalesQuote>
回购中检查了链接的README
,我在KaTeX
中使用了以下内容
katex.html
然后在我使用的YAML中:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
<!-- To automatically render math in text elements, include the auto-render extension: -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
值得注意的是,我发现有必要使用---
site: bookdown::bookdown_site
output:
bookdown::gitbook:
pandoc_args: [--katex]
mathjax: NULL
includes:
in_header: katex.html
documentclass: book
math: true
---
而不是math: true
。