Customization of the highr package

If you are not satisfied with the default syntax highlighting commands in the highr package, you can just use your own tags/commands. In this vignette, we show a brief example.

The default highlighting commands are stored in two internal data frames cmd_latex and cmd_html:

library(highr)
highr:::cmd_latex

This data frame is passed to the markup argument in hilight(), so we are free to pass a modified version there. Suppose I want to use the command \my<*> instead of \hl<*>:

m = highr:::cmd_latex
m[, 1] = sub('\\hl', '\\my', m[, 1], fixed = TRUE)
head(m)

Then

hilight("x = 1+1  # a comment")  # default markup
hilight("x = 1+1  # a comment", markup = m)  # custom markup

This allows one to use arbitrary commands around the text symbols in the R code. See https://github.com/yihui/highr/blob/master/R/highlight.R for how cmd_latex and cmd_html were generated in highr.



Try the highr package in your browser

Any scripts or data that you put into this service are public.

highr documentation built on Dec. 28, 2022, 2:33 a.m.