I would like to make the following work
---
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).
But I could not find a solution. It would be great if there is something around! The following links are helpful, but didn't suggest a solution: pandoc doc, \newcommand in Rmd formula and RStudio snippets.
By default, Pandoc will preserve raw LaTeX code in Markdown documents when converting the document to LaTeX, so you can use LaTeX commands or environments in Markdown.
We indicate a square root using the \sqrt operator.
If you want to add anything to the preamble, you have to use the includes option of pdf_document . This option has three sub-options: in_header , before_body , and after_body . Each of them takes one or multiple file paths. The file(s) specified in in_header will be added to the preamble.
How about using R instead:
---
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 ...
If you still need to define a \newcommand
using LaTeX in Rmarkdown, you can do so by e.g.
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
```
Note, the bm
package must be loaded for this to work, e.g., by using this in the YAML header:
---
title: "My R Report"
author: "Me"
date: "2020-01-31"
header-includes:
- \usepackage{bm}
output:
pdf_document:
toc: true
number_sections: true
---
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With