更新(2012 年 6 月 13 日): RStudio 现在支持一系列 mathjax 分隔符,包括不带latex
.
在 0.96中, RStudio 将其 Mathjax 语法从$<equation>$
to更改为$latex <equation>$
用于内联方程,从$$<equation>$$
to 更改$$latex <equation>$$
为用于显示方程。
因此,总而言之:
修改后的语法将
latex
限定符添加到 $ 或 $$ 等式开始分隔符。
我有一些使用原始$
分隔符的现有脚本,我想更新它们以使用新的$latex
分隔符。我在想 sed 或 awk 可能是合适的。
像这样出现在 r 代码块中的美元也不应该被更改。
```{r ...}
x <- Data$asdf
```
问题
- 什么是一个好的简单命令行程序,可能使用 sed 或 awk 来更新我的 R Markdown 代码以使用 R Studio 中较新的 mathjax 分隔符?
工作示例 1
原文:
$y = a + b x$ is the formula.
This is some text, and here is a displayed formula
$$y = a+ bx\\
x = 23$$
```{r random_block}
y <- Data$asdf
```
and some more text
$$y = a+ bx\\
x = 23$$
变身后变成
$latex y = a + b x$ is the formula.
This is some text, and here is a displayed formula
$$latex y = a+ bx\\
x = 23$$
```{r random_block}
y <- Data$asdf
```
and some more text
$$latex y = a+ bx\\
x = 23$$
工作示例 2
`r opts_chunk$set(cache=TRUE)`
<!-- some comment -->
Some text
<!-- more -->
Observed data are $y_i$ where $i=1, \ldots, I$.
$$y_i \sim N(\mu, \sigma^2)$$
Some text $\sigma^2$ blah blah $\tau$.
$$\tau = \frac{1}{\sigma^2}$$
blah blah $\mu$ and $\tau$
$$\mu \sim N(0, 0.001)$$
$$\tau \sim \Gamma(0.001, 0.001)$$
应该成为
`r opts_chunk$set(cache=TRUE)`
<!-- some comment -->
Some text
<!-- more -->
Observed data are $latex y_i$ where $latex i=1, \ldots, I$.
$$latex y_i \sim N(\mu, \sigma^2)$$
Some text $latex \sigma^2$ blah blah $latex \tau$.
$$latex \tau = \frac{1}{\sigma^2}$$
blah blah $latex \mu$ and $latex \tau$
$$latex \mu \sim N(0, 0.001)$$
$$latex \tau \sim \Gamma(0.001, 0.001)$$