chr*_*iss 6 mathjax pandoc rstudio knitr r-markdown
使用Rmarkdownin Rstudio、 usingpandoc和knitr,我的目标是通过 LaTeX 输出 PDF 和使用 .html 输出 HTML MathJax。我想使用一些MathJax可用的扩展,以便为 PDF 目标提供更丰富的 LaTeX。siunitx具体来说,我现在正在尝试使用该扩展,尽管我也对其他扩展感兴趣(例如physics)。
使用siunitxLaTeX 进行 PDF 输出效果很好,但我很难让它与 HTML 输出一起工作。
这是一个 Rmarkdown 文件示例:
---
title: "siunitx test"
author: "chriss"
date: "June 13, 2017"
output:
html_document:
mathjax: https://cdn.rawgit.com/mathjax/MathJax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML
number_sections: yes
pdf_document:
keep_tex: yes
latex_engine: xelatex
number_sections: yes
header-includes: \usepackage{siunitx}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# The Problem
I would like to be able to use `siunitx` latex macros from `Rmarkdown`,
targetting PDF output via latex and html with MathJax. It should get me proper
formatting of things like $\SI{120}{\W\per\square\m}$ and $\SI{0.8}{\A\per\W}$,
as long as I put them in a latex math environment, so that MathJax picks them
up.
The PDF output is OK when I add the `header-includes: \usepackage{siunitx}` to
the `YAML` header, but how can I access the MathJax `siunitx` extension via the
knitr -> pandoc -> mathjax/html route?
Check: is MathJax working in general: $\frac{1}{r^2}$
Run Code Online (Sandbox Code Playgroud)
这与 PDF 结合得很好,但$\SI{}{}$在 HTML 输出和RStudio. 我正在pandocget MathJaxfrom rawgit.org,因为默认的cdn.mathjax.org即将失效,而且似乎不再有Contrib带有扩展名的路径。
我尝试在扩展路径上添加带有变体的MathJax's ,但无济于事。这会导致 HTML 查找扩展名,但显然是在错误的位置:,这是一个.$\require{siunitx}$siunitxsiunitxhttps://cdn.rawgit.com/mathjax/MathJax/2.7.1/extensions/TeX/siunitx.js?V=2.7.1404
如果我删除\require{}并删除动态加载的输出 HTML 文件的部分MathJax(标记为<!-- dynamically load mathjax for compatibility with self-contained -->),然后手动添加:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]},
errorSettings: {message: undefined},
TeX: { extensions: ["[burnpanck]/siunitx/unpacked/siunitx.js"] }
};
MathJax.Ajax.config.path['burnpanck'] =
'https://rawgit.com/burnpanck/MathJax-third-party-extensions/master';
</script>
<script type="text/javascript"
src="https://cdn.rawgit.com/mathjax/MathJax/2.7.1/latest.js?config=TeX-AMS-
MML_HTMLorMML"></script>
Run Code Online (Sandbox Code Playgroud)
对于 HTML 文件的标头,它会短暂弹出有关某些问题的投诉,siunitx.js但会生成正确的输出(这是 MathJax 扩展示例中标头的修改版本siunitx,来自此处)
这表明我可以修改 HTML 模板以pandoc反映这些更改,并且基本上可以正常工作。
然而,仍然存在以下问题:
cdn.mathjax.org,还是应该使用更好的 URL?siunitx.js?Rstudio理解siunitx预览中的内容?是否已经有一种方法可以启用此功能(例如,说服它使用siunitx扩展,假设它是基于 构建的MathJax),或者这将是一个功能请求..?事实上,如果有一种简单的方法来访问MathJax开箱即用的扩展,而不必费心编辑模板等,并在 GUI 中进行适当的处理,那就太好了Rstudio。我可以想象,可能有些Rstudio用户会从额外的功能中受益,但不想/无法跳过这些障碍来访问它。
更新由于 MathJax CDN 的更改,我在加载“工作”HTML 时看到的警告消息siunitx.js似乎是当前版本的普遍问题,请参阅此处提出的问题:https: //github.com/burnpanck/MathJax -第三方扩展/问题/5siunitx.js
小智 2
I'm using includes in_header to solve the problem.
---
title: "doku1"
output:
html_document:
includes:
in_header: header.html
pdf_document:
keep_tex: yes
latex_engine: pdflatex
number_sections: no
header-includes: \usepackage{mhchem, siunitx}
---
Run Code Online (Sandbox Code Playgroud)
header.html looks like this
<script type="text/x-mathjax-config">
MathJax.Ajax.config.path["mhchem"] = "https://cdnjs.cloudflare.com/ajax/libs/mathjax-mhchem/3.3.2";
MathJax.Ajax.config.path['myExt'] = 'https://rawgit.com/burnpanck/MathJax-third-party-extensions/master';
MathJax.Hub.Config({
TeX: { extensions: ["AMSmath.js","AMSsymbols.js","[myExt]/siunitx/unpacked/siunitx.js","[mhchem]/mhchem.js", "color.js"] }
});
</script>
Run Code Online (Sandbox Code Playgroud)
It works, but is rather slow.
John
| 归档时间: |
|
| 查看次数: |
2067 次 |
| 最近记录: |