R帮助手册中可以包含乳胶数学吗? [英] Can R help manuals have latex math in them?

查看:91
本文介绍了R帮助手册中可以包含乳胶数学吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R程序包,并且正在使用Roxygen2程序包来编写有关R功能的帮助手册.我想知道的是,是否可以在手册页中将乳胶用于数学方程式?

I am working on an R package and I am using the package Roxygen2 to write the help manuals for my R functions. What I would like to know is if it is possible to use latex for math equations in the manual pages?

例如,如果我有一个名为add2的函数,它执行以下操作:

For example, if I had a function called add2 that did the following:

add2 = function(x,y){
       z = x+y
       return(z)
}

使用Roxygen2文档,我得到了以下内容:

And using Roxygen2 documentation I had the following:

##' @include add2.R
{}

##' Compute the sum of x_1 and x_2
##'
##' Computes the sum of x_1 and x_2
##'
##' @param x_1 number of guys
##' @param x_2 number of girls
##' @return The sum of the two values x_1 and x_2
##'
##' @example examples/adding.R
##' @export
##' @author Name

这对我有用,但是在帮助手册中将x1和x2显示为x_1和x_2,而我希望它看起来像乳胶数学并且实际上在x上有下标,即$ x_1 $和$ x_2乳胶中的$.

And this works for me, but this displays x1 and x2 as x_1 and x_2 in the help manual whereas I would like for it to look like latex math and actually have the subscripts on x, i.e., $x_1$ and $x_2$ in latex.

有没有办法做到这一点?或者R不适应吗?

Is there any way to do this or does R not accomodate this?

推荐答案

排序.如果要在纯文本输出中使用LaTeX标记的(未处理的)版本,请使用\eqn{x_1}之类的东西(或者,您可以说\eqn{x_1}{x1}之类的话). 排序"部分是我不确定LaTeX处理将针对哪种特定的输出格式进行处理-例如,我猜测您将在(例如) RStudio文档窗格将遵守该标记. (LaTeX标记肯定会在手册的PDF版本中使用 ,我几乎从没看过...)

Sort of. Use something like \eqn{x_1} if you want use the (unprocessed) version of the LaTeX markup in plain-text output (alternately you could say something like \eqn{x_1}{x1}). The "sort of" part is that I'm not sure offhand for which particular output formats the LaTeX processing will be done -- for example, I'm guessing that the HTML-formatted version of output you would see in (e.g.) an RStudio documentation pane would not respect this markup. (The LaTeX markup definitely will be used in the PDF versions of the manual, which I almost never look at ...)

我将继续引用

I'm going to go ahead and quote from the Mathematics section of Writing R Extensions ...

应该为印刷文档设置漂亮的数学公式,但是我们仍然希望对文本和HTML联机帮助有用.为此,使用了两个命令\ eqn {latex} {ascii}和\ deqn {latex} {ascii}. \ eqn用于内联"公式(对应于TeX的$…$),\ deqn给出显示方程式"(例如在LaTeX的displaymath环境或TeX的$$…$$中).这两个参数都被视为"verbatim"文本.

Mathematical formulae should be set beautifully for printed documentation yet we still want something useful for text and HTML online help. To this end, the two commands \eqn{latex}{ascii} and \deqn{latex}{ascii} are used. Whereas \eqn is used for "inline" formulae (corresponding to TeX’s $…$), \deqn gives "displayed equations" (as in LaTeX’s displaymath environment, or TeX’s $$…$$). Both arguments are treated as ‘verbatim’ text.

这两个命令也可以用作\ eqn {latexascii}(仅一个参数),然后用于乳胶和ascii.在命令和第一个参数之间,以及在第一和第二个参数之间,都不允许有空格.

Both commands can also be used as \eqn{latexascii} (only one argument) which then is used for both latex and ascii. No whitespace is allowed between command and the first argument, nor between the first and second arguments.

以下示例来自Poisson.Rd:

The following example is from Poisson.Rd:

\ deqn {p(x)= \ frac {\ lambda ^ x e ^ {-\ lambda}} {x!}} {%

\deqn{p(x) = \frac{\lambda^x e^{-\lambda}}{x!}}{%

p(x)= \ lambda ^ x exp(-\ lambda)/x!} 表示\ eqn {x = 0,1,2,\ ldots}.

p(x) = \lambda^x exp(-\lambda)/x!} for \eqn{x = 0, 1, 2, \ldots}.

这篇关于R帮助手册中可以包含乳胶数学吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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