knitr/markdown:如何在CRAN建立的小插图中渲染数学方程式? [英] knitr/markdown: how to render math equations in vignettes built by CRAN?

查看:92
本文介绍了knitr/markdown:如何在CRAN建立的小插图中渲染数学方程式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In a package, I have several vignettes that use mathematical notation, like:

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 )编译小插图时,无论是否查看,该小插图都能正确显示在HTML文件中在R Studio查看器或浏览器中.

When I compile the vignette using R Studio (Ctrl+Shift+K), it renders properly in the HTML file, whether viewed in the R Studio viewer or the browser.

但是,当将包提交到CRAN并从源包中在那里构建小插图时,数学无法正确呈现,但会显示为标记,

Yet, when the package is submitted to CRAN, and the vignettes are built there from the source package, the math is not rendered properly, but appears as markup,

是否需要添加一些内容到YAML标头中,以便在R Studio外部构建的小插图可以正确呈现数学?目前,我仅使用标准标头:

Is there something I need to add to my YAML header so that vignettes built outside of R Studio will render mathematics properly? Currently, I use just a standard header:

---
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}
---

从R Studio生成的pandoc命令是

The generated pandoc command from R Studio is

"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--standalone相对应的YAML选项?

Perhaps I need to add a YAML option corresponding to --self-contained or --standalone ?

推荐答案

数年后发布,以防其他用户有相同的问题.我注意到在我的小插曲中呈现方程式时遇到了同样的问题-不在CRAN上,只是在本地托管的程序包上. Ctrl + Shift + K可以很好地显示,但是在RStudio帮助面板中使用vignette()查看时,方程式将变得很糟糕.

Posting years later in case another user has the same question. I noticed the same issues rendering equations in my vignettes---not on CRAN, just locally hosted packages. Ctrl + Shift + K rendered fine, but viewing with vignette() in the RStudio Help panel renders the equations badly.

我认为这只是帮助"面板不能完全呈现HTML的问题.如果我在浏览器中查看打包的小插图,例如使用RShowDoc(),则方程式很好.因此,也许应该比vignette()更频繁地将用户定向到RShowDoc().

I think this is just an issue that the Help panel doesn't render the HTML completely. If I view the packaged vignette in a browser, e.g. using RShowDoc(), then the equations are fine. So maybe users should be directed to RShowDoc() more often than vignette().

这篇关于knitr/markdown:如何在CRAN建立的小插图中渲染数学方程式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆