Stata syntax highlighting in Rmarkdown
Asked Answered
C

1

7

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.

Crazyweed answered 8/5, 2019 at 21:59 Comment(2)
Did you ever get a good answer for this one?Karie
Unfortunately, not yet.Crazyweed
D
2

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
```
Discoloration answered 11/8, 2021 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.