knitr / markdown:如何在CRAN建立的小插图中渲染数学方程式?

use*_*089 5 mathjax pandoc rstudio knitr r-markdown

在一个包中,我有几个使用数学符号的小插曲,例如:

This vignette illustrates the ideas behind solving systems of linear equations of the form $\mathbf{A x = b}$
where 

- $\mathbf{A}$ is an $m \times n$ matrix of coefficients for $m$ equations in $n$ unknowns
- $\mathbf{x}$ is an $n \times 1$ vector unknowns, $x_1, x_2, \dots x_n$
- $\mathbf{b}$ is an $m \times 1$ vector of constants, the "right-hand sides" of the equations
Run Code Online (Sandbox Code Playgroud)

当我使用R Studio(Ctrl+ Shift+ K)编译小插图时,无论在R Studio查看器中还是在浏览器中查看,小插图都可以在HTML文件中正确呈现。

在此处输入图片说明

然而,当包被提交给CRAN和插图都建从源码包,数学没有正确渲染,但显示为标记,

在此处输入图片说明

我需要在YAML标头中添加一些内容,以便在R Studio外部构建的小插图能够正确呈现数学吗?当前,我只使用一个标准头文件:

---
title: "Solving Linear Equations"
author: "Me"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Solving Linear Equations}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---
Run Code Online (Sandbox Code Playgroud)

pandoc从R Studio 生成的命令是

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS linear-equations.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc8141d044063.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\R\R-3.2.5\library\rmarkdown\rmd\h\default.html" --css "C:\R\R-3.2.5\library\rmarkdown\rmarkdown\templates\html_vignette\resources\vignette.css" --mathjax --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --highlight-style pygments 
Run Code Online (Sandbox Code Playgroud)

也许我需要添加一个对应于--self-contained或的YAML选项--standalone

小智 1

几年后发布,以防其他用户有同样的问题。我注意到在我的小插图中渲染方程时存在同样的问题——不是在 CRAN 上,而是在本地托管的包上。Ctrl + Shift + K 渲染得很好,但vignette()在 RStudio 帮助面板中查看时,方程的渲染效果很差。

我认为这只是帮助面板没有完全呈现 HTML 的问题。如果我在浏览器中查看打包的小插图,例如使用RShowDoc(),那么方程式就很好。因此,也许用户应该被引导到RShowDoc()vignette().