4

I am working within RStudio 1.1.383 using rmarkdown. I am trying to render to Latex a string that is created within a knitr chunk so that it appears as latex code within the document.

So far I have experimented with the 'results=' options in the chunk header and find that results='asis' enables it to be rendered once the document is knitted, but I have not been able to find a way to enable the result to be rendered using the preview feature that allows you to run a single chunk and see the results within the .Rmd editor.

Any help on this matter would be appreciated.

A minimal example is included below that should be copied into a .Rmd file before rendering.

Thanks in advance,

Michael

---
title: "Minimal Example"
output: html_document
---

```{r}
str <- "$$\\alpha \\cdot \\beta = \\delta$$"

# this doesn't show in the preview 'run chunk feature'
cat(str, "\n")

# neither does this
writeLines(str)
```
  • shouldn't you set `str` with `cat(str,"\n")`? I mean `str<-cat(str,"\n")` – Zeinab Ghaffarnasab Nov 25 '17 at 19:05
  • 2
    `results='asis' ` – Martin Schmelzer Nov 25 '17 at 19:44
  • Thank you both results='asis' works when the document is rendered. In RStudio 1.1.383, , Latex can be inputted in .Rmd documents between dollars i.e $$ \LaTeX code $$ and it will render immediately as a preview. The preview still does not work with this method, however the final result works so I am happy with that. Anyone know if there is a way to get the rendered text to show in the notebook preview feature of .Rmd documents in RStudio 1.1.383? – CivilEngineerUK Nov 25 '17 at 20:42

0 Answers0