在一个包中,我有几个使用数学符号的小插图,例如:
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
当我使用 R Studio (Ctrl+Shift+K) 编译小插图时,无论是在 R Studio 查看器还是浏览器中查看,它都会在 HTML 文件中正确呈现。
然而,当包被提交给 CRAN 并构建小插图时 那里从源包中,数学未正确呈现,但显示为标记,
是否需要在 YAML header 中添加一些内容,以便在 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}
---
生成的
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
也许我需要添加一个对应于
--self-contained
的 YAML 选项或 --standalone
?
最佳答案
多年后发布,以防其他用户有同样的问题。我注意到在我的小插图中渲染方程的问题相同——不是在 CRAN 上,只是在本地托管的包中。 Ctrl + Shift + K 呈现良好,但查看 vignette()
RStudio 帮助面板中的公式渲染效果不佳。
我认为这只是帮助面板没有完全呈现 HTML 的问题。如果我在浏览器中查看打包的小插图,例如使用 RShowDoc()
,那么方程没问题。所以也许用户应该被定向到 RShowDoc()
比 vignette()
更频繁.
关于rstudio - 针织/ Markdown : how to render math equations in vignettes built by CRAN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39837816/