File: highr-custom.Rmd

package info (click to toggle)
r-cran-highr 0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 172 kB
  • sloc: sh: 10; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!--
%\VignetteEngine{knitr::docco_classic}
%\VignetteIndexEntry{Customization of the highr package}
-->

# 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`:

```{r}
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<*>`:

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

Then

```{r}
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**.