I'm afraid the response will be: "Markdown is meant to be simple and it doesn't do that", but it (almost) never hurts to ask.
When writing an R Markdown document I can view the HTML file in a browser and it looks great. When I try to print it, either on paper or as PDF, the color in the figures is printed but not the syntax highlighting. Is there a way to maintain syntax highlighting when printing?
Example:
Minimal Example
=====
This text looks great in the file and the plot prints in color, but see commented code below.
```{r}
# this commented line will be green in the HTML file, but will be black when I print it
z <- cor(mtcars)
require(lattice) # 'require' will be blue in the HTML file, but will be black when I print it
levelplot(z)
```
I push the "Knit HTML" button in RStudio and open the HTML in Chrome or Safari and there are no problems. If I print from the HTML from the browser all the syntax highlighting is lost.
After doing your 'Knit' to your original example.Rmd you will have an example.md in your working path, then use pandoc...
# for pdf (you need to have latex installed)
system( "pandoc example.md -o example.pdf")
# for syntax-highlight persistant html
system("pandoc example.md -o example.html -s -S")
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