Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stata syntax highlighting in Rmarkdown

I am using Bookdown and Rmarkdown to compose a technical book for Stata users. I would like to include Stata highlighting syntax in the chunks of code, but I am not interested in actually executing Stata from Rstudio. I just want the syntax highlighting.

I learned here that it is possible to use highlightjs but I have no idea how to include it in my .Rmd files.

I would like to be able to include something like the following and get it syntax highlighted.

```stata
sysuse auto, clear
reg mpg length
```

I highly appreciate your help. Thanks.

like image 388
R.Andres Castaneda Avatar asked May 08 '19 21:05

R.Andres Castaneda


1 Answers

Now you can highlight your stata code, by using the latest R packages related to knitting.

  • rmarkdown Ver. 2.10
  • knitr: Ver. 1.33
  • bookdown: Ver. 0.22

You may also have to [u]se a Pandoc version not bundled with the RStudio IDE. I use a Pandoc Ver. 2.14.0.3.

enter image description here

---
title: "Untitled"
author: "author"
output:
  bookdown::pdf_document2: default
---

- `rmarkdown`: Ver. `r packageVersion("rmarkdown")`
- `knitr`: Ver. `r packageVersion("knitr")`
- `bookdown`: Ver. `r packageVersion("bookdown")`
- (`pandoc`: Ver. `r rmarkdown::pandoc_version()`)


```stata
sysuse auto, clear
reg mpg length
```
like image 73
Carlos Luis Rivera Avatar answered Oct 07 '22 15:10

Carlos Luis Rivera