Debian Codegraph @

vignettes/highr-custom.Rmd

raw
1 <!--
2 %\VignetteEngine{knitr::docco_classic}
3 %\VignetteIndexEntry{Customization of the highr package}
4 -->
5
6 # Customization of the `highr` package
7
8 If you are not satisfied with the default syntax highlighting commands in
9 the **highr** package, you can just use your own tags/commands. In this
10 vignette, we show a brief example.
11
12 The default highlighting commands are stored in two internal data frames
13 `cmd_latex` and `cmd_html`:
14
15 ```{r}
16 library(highr)
17 highr:::cmd_latex
18 ```
19
20 This data frame is passed to the `markup` argument in `hilight()`, so we are
21 free to pass a modified version there. Suppose I want to use the command
22 `\my<*>` instead of `\hl<*>`:
23
24 ```{r}
25 m = highr:::cmd_latex
26 m[, 1] = sub('\\hl', '\\my', m[, 1], fixed = TRUE)
27 head(m)
28 ```
29
30 Then
31
32 ```{r}
33 hilight("x = 1+1 # a comment") # default markup
34 hilight("x = 1+1 # a comment", markup = m) # custom markup
35 ```
36
37 This allows one to use arbitrary commands around the text symbols in the R
38 code. See <https://github.com/yihui/highr/blob/master/R/highlight.R> for how
39 `cmd_latex` and `cmd_html` were generated in **highr**.