This question is similar to consistent code html inline and in chunks with knitr. Instead of .Rhtml documents, I want to highlight inline R code in R Markdown documents, e.g., after `r "plot(cars, main = 'A scatterplot.')"`
is compiled through rmarkdown, the tokens like plot
should be highlighted. By default, R code chunks are syntax highlighted, but there is no way to highlight inline R code.
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
Here is one solution using the development version of the highr package (
devtools::install_github('yihui/highr')
). Basically you just define your custom LaTeX commands to highlight the tokens.highr:::cmd_pandoc_latex
is a data frame of LaTeX commands that Pandoc uses to do syntax highlighting.Then you can redefine the
inline
hook of knitr:I used
I()
as a convenient marker to tell the character strings to be syntax highlighted from normal character strings. It is just an arbitrary choice. PDF output:This is not a perfect solution, though. You will need to tweak it in some cases. For example, most special LaTeX characters are not escaped, such as
~
. You may need to process the LaTeX code returned byhi_pandoc()
bygsub()
.Personally I find multiple colors in inline output distracting, so I would not syntax highlighting it, but this is entirely personal taste.