0

In R markdown or R studio, for a line like this

library('tidyverse')

library is colored in blue and tidyverse in green. When I knit to html, they appear in dark red and red respectively. How can I knit my html keeping the original color for the whole document? In the R Markdown Cookbook, it says that I can use a span tag and set the color, but that seems to work for a specific code chunk. I found this post for the background color, not the text. Or this one, but for single code chunks again. I believe it comes from the fact that colours have different names in R and HTML? Is there a way to specify this in the <style type="text/css"> section just below the YAML header? I code in R but I am totally new to CSS or HTML.

Mata
  • 538
  • 3
  • 17

1 Answers1

5

Use highlight: textmate in the YAML header.

For instance,

---
title: "Test"
output: 
  html_document:
    highlight: textmate
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Test

```{r}
library("tidyverse")
```

knits to

result

Further reading

R Markdown: The Definitive Guide

ekoam
  • 8,744
  • 1
  • 9
  • 22