[英]How can I use Latex' \newcommand in Rmd?
我想做以下工作
---
title: "Untitled"
author: "SQC"
date: "21 September 2018"
output: html_document
---
\newcommand{\short}{AreallylongwordIhavetotypefrequently}
# My Test
I would like to write \short which does not work, $\short$ however is close...
Snippets do not work in Rmd plain text (= Rstudio's "Shift", see link below).
但我找不到解决办法。 如果周围有东西就好了! 以下链接很有帮助,但没有提出解决方案: pandoc doc , Rmd 公式中的 \\newcommand和RStudio 片段。
改用 R 怎么样:
---
title: "Untitled"
author: "SQC"
date: "21 September 2018"
output: html_document
---
```{r, include = FALSE}
short <- "AreallylongwordIhavetotypefrequently"
```
# My Test
I would like to write `r short` instead ...
如果你仍然需要在\\newcommand
使用 LaTeX 定义一个\\newcommand
newcommand,你可以这样做,例如
Some text with the following equation:
\begin{equation} \newcommand{\matr}[1]{\mathbf{#1}}
\matr{Y} =
\begin{pmatrix}
\matr{y_1} \\
\matr{y_2} \\
\end{pmatrix}
\end{equation}
```{r}
y1 + y2
```
请注意,必须加载bm
包才能使其工作,例如,通过在 YAML 标头中使用它:
---
title: "My R Report"
author: "Me"
date: "2020-01-31"
header-includes:
- \usepackage{bm}
output:
pdf_document:
toc: true
number_sections: true
---
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.