Was pygments highlight style in HTML output changed in RStudio 1.4?

Was the pygments highlight style in HTML output of Rmd documents changed in RStudio 1.4? Or is it a bug? What is this discrepancy caused by? (Find the details below.)

System details

RStudio Edition :  Desktop
RStudio Version : 1.4.1075
OS Version      : Windows 10
R Version       : 4.0.3

Steps to reproduce the problem

  1. Create any Rmd document with R code included and highlight style pygments enabled.
  2. Push "Knit" button and inspect the HTML output.

YALM header of the Rmd file I used:

title: "Highlight style: pygments"
    highlight: pygments

Describe the problem in detail

In Rstudio 1.4, the wrong highlight style is used when pygments is chosen:

Describe the behavior you expected

In RStudio 1.3 the correct pygments style is used:

So I expect this style in RStudio 1.4 too.

The only thing I changed is the version of RStudio. I reinstalled different versions several times and I still can reproduce the issue in 1.4. I did not check the other styles. This source also demonstrates the pygments style that is used in RStudio 1.3.

You encounter this behavior because the syntax highlighter in Pandoc has updated its syntax definition for the R language in Pandoc 2.11. That means the R code is not parsed the same by the highlighter - usually an update of the engine means better parsing - and even if the underlying color have not changed, they do not apply the same as the parsing was different. For example, set is now see as a function so it has correctly a different color than TRUE which is a logical condition token.

I won't go more into details about how syntax highlighing engine works here. But that is the reason.

You get this by switching RStudio version because RStudio 1.4 now ship with Pandoc 2.11+ and RStudio 1.3 ships with Pandoc 2.7.3.

Rmarkdown and RStudio are just using the Pandoc version associated with it, they do not do anything regarding syntax highlighting on this one. It is all Pandoc.

If for some reason you would like to have the previous colors (which where applied with a less good parser), you'll need to export the theme file from Panod 2.7.3, and use it with Pandoc 2.11

See more there: https://pandoc.org/MANUAL.html#syntax-highlighting

1 Like

Thank you. I just wanted to make sure that the changes are due to Pandoc and not RStudio.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.