This object can be used to set or get themes in knitr for syntax highlighting.

knit_theme

Format

An object of class list of length 2.

Details

We can use knit_theme$set(theme) to set the theme, and knit_theme$get(theme) to get a theme. The theme is a character string for both methods (either the name of the theme, or the path to the CSS file of a theme), and for the set() method, it can also be a list returned by the get() method. See examples below.

Note

The syntax highlighting here only applies to .Rnw (LaTeX) and .Rhtml (HTML) documents, and it does not work for other types of documents, such as .Rmd (R Markdown, which has its own syntax highlighting themes; see https://rmarkdown.rstudio.com).

References

For a preview of all themes, see https://gist.github.com/yihui/3422133.

Author

Ramnath Vaidyanathan and Yihui Xie

Examples

opts_knit$set(out.format = "latex")
knit_theme$set("edit-vim")

knit_theme$get()  # names of all available themes
#>  [1] "acid"              "aiseered"          "andes"             "anotherdark"      
#>  [5] "autumn"            "baycomb"           "bclear"            "biogoo"           
#>  [9] "bipolar"           "blacknblue"        "bluegreen"         "breeze"           
#> [13] "bright"            "camo"              "candy"             "clarity"          
#> [17] "dante"             "darkblue"          "darkbone"          "darkness"         
#> [21] "darkslategray"     "darkspectrum"      "default"           "denim"            
#> [25] "dusk"              "earendel"          "easter"            "edit-anjuta"      
#> [29] "edit-eclipse"      "edit-emacs"        "edit-flashdevelop" "edit-gedit"       
#> [33] "edit-jedit"        "edit-kwrite"       "edit-matlab"       "edit-msvs2008"    
#> [37] "edit-nedit"        "edit-vim-dark"     "edit-vim"          "edit-xcode"       
#> [41] "ekvoli"            "fine_blue"         "freya"             "fruit"            
#> [45] "golden"            "greenlcd"          "greyscale0"        "greyscale1"       
#> [49] "greyscale2"        "kellys"            "leo"               "lucretia"         
#> [53] "manxome"           "maroloccio"        "matrix"            "moe"              
#> [57] "molokai"           "moria"             "navajo-night"      "navy"             
#> [61] "neon"              "night"             "nightshimmer"      "nuvola"           
#> [65] "olive"             "orion"             "oxygenated"        "pablo"            
#> [69] "peaksea"           "print"             "rand01"            "rdark"            
#> [73] "relaxedgreen"      "rootwater"         "seashell"          "solarized-dark"   
#> [77] "solarized-light"   "tabula"            "tcsoft"            "vampire"          
#> [81] "whitengrey"        "xoria256"          "zellner"           "zenburn"          
#> [85] "zmrok"            

thm = knit_theme$get("acid")  # parse the theme to a list
knit_theme$set(thm)

opts_knit$set(out.format = NULL)  # restore option