在R笔记本中更改mathjax渲染器(“ self_contained:false”)

问题描述 投票:1回答:1

我正在创建包含方程式的R笔记本。我在Windows 10,R 3.5.1和rmarkdown 2.1上使用RStudio 1.2.5033。当我的R笔记本以HTML呈现时,MathJax(v2.7.2)使用“ HTML-CSS”输出处理器呈现方程式。但是我认为“ CommonHTML”输出处理器的输出看起来更好。因此,我想在我的R笔记本中包含一个指令,该指令强制MathJax使用CommonHTML输出处理器。我该怎么办?

如果我使用输出格式html_document渲染普通的R Markdown文档,则可以通过YAML标头中的mathjax选项解决该问题。例如,当以下文件呈现为HTML时,MathJax将使用CommonHTML输出处理器:

---
title: "Trouble with MathJax"
output: 
  html_document:
    mathjax: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML.js"
    self_contained: false    
---

\begin{equation}
  R_3 = \alpha
\end{equation}

但是当我将output格式从html_document更改为html_notebook时,此解决方案无法正常工作。在这种情况下,我得到的输出看起来像这样:screenshot showing problem with html_notebook rendering

等式是使用CommonHTML呈现的,但是页面顶部有很多问题(请注意四个要点,并且似乎没有实现默认的R Notebook CSS。

问题似乎是self_contained: FALSE中建议的用R notebooks don't render properly when "self_contained" is FALSE because the "files" directory is deleted after rendering渲染R笔记本的普遍问题。但我看不到解决该问题的好方法。

死角

MathJax documentation似乎表明我可以通过在对jax的调用中添加MathJax.Hub.Config()数组来指定输出处理器。但是,当我这样做时,我的方程式仍然通过HTML-CSS输出处理器显示。这是展示问题的R Markdown文档的最小示例:

---
title: 'Trouble with MathJax'
output: html_notebook
---

<script type="text/x-mathjax-config"> 
  MathJax.Hub.Config({ 
    jax: ["input/TeX", "output/CommonHTML"],
  });
</script>

\begin{equation}
  R_3 = \alpha
\end{equation}

MathJax.Hub.Config()的呼叫在这里似乎无济于事。在Chrome和Edge中,方程式都是通过HTML-CSS而不是CommonHTML呈现的。如何将渲染更改为通用HTML?

相关文章

latex rstudio r-markdown mathjax rnotebook
1个回答
0
投票

解决方案是简单地省略YAML标头中的self_contained行,或等效地将self_contained设置为true。这是用户选择了mathjax渲染器的R笔记本的最小示例:

---
title: "Self-contained notebook with non-default Mathjax config"
output:
  html_notebook:
    mathjax: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML.js"
---

$R_3 = 2$.

当文件呈现为HTML时,方程式用CommonHTML而不是HTML-CSS显示。 Mathjax脚本包含在生成的“ nb.html”文件中。

[这让我感到惊讶,因为rmarkdown::html_document()的文档说:“即使对于自包含文档,MathJax仍在外部加载(由于其大小,这是必要的”)。但是Section 3.1.8 of the R Markdown book表示该限制仅在从本地文件加载Mathjax时适用。因此,也许这并不奇怪。

旁注:rmarkdown软件包使用的默认Mathjax配置由rmarkdown:::mathjax_config()给出。从rmarkdown v2.1开始,该函数返回“ MathJax.js?config = TeX-AMS-MML_HTMLorMML”。

© www.soinside.com 2019 - 2024. All rights reserved.