0
votes

I'm trying to use an inline expression in a .Rmd markdown file. I'm converting the .Rmd file to a PDF using Pandoc. The contents of my file is like this:

Report 
========================================================

This is my text and this is my expression 100km^2

```{r}
summary(cars)
```

I expected 100km^s to render normally, but it renders literally as '100km^2'. How can I get the expression to render?

2
your expression itself is incorrect; knit(text="This is my text and this is my expression r expression(100 * km^2)") would be better, but knitr doesn't know what to do with an expression to display inline, which it sees as a list with multiple elements.baptiste
also, why do you need expression()?baptiste
Post edited: 100km^2 renders if converting to html with knitr, but is literal when converting to PDF with Pandocluciano

2 Answers

7
votes

You can use latex math mode for this,

knit(text="$100 km^2$",output="test.md")
pandoc("test.md", format="latex")

gives me:

enter image description here

3
votes

Simply wrap the expression in $ characters -- that is, $100km^2$ instead of 100km^2.