How to customize code chunks ouputs ?
cderv opened this issue · 3 comments
cderv commented
We could have some recipes on how to customize code chunk output.
The idea is to talk about
- Replacing all the higlighting: using
highlight: null
and provide a custome css with the tags used for highligting (https://github.com/jeffbr13/benjeffrey.com/blob/master/posts/pandoc-syntax-highlighting-css.md)
code > span.kw { color: #555; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal (decimal values) */
code > span.bn { color: #d14; } /* BaseN */
code > span.fl { color: #d14; } /* Float */
code > span.ch { color: #d14; } /* Char */
code > span.st { color: #d14; } /* String */
code > span.co { color: #888888; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* OtherToken */
code > span.al { color: #ff0000; font-weight: bold; } /* AlertToken */
code > span.fu { color: #900; font-weight: bold; } /* Function calls */
code > span.er { color: #a61717; background-color: #e3d2d2; } /* ErrorTok */
- Apply custom formatting on a chunk basis using knitr
class.source
orclass.output
options and a CSS - deactivate highlighting with
highlight=FALSE
chunk option - Do not touch the highlighting but other style of the code chunk using by modifying with css html tag
pre
,code
and/or class.r
or others languages.
Also
- Background color in latex through
background
chunk option
I would find it useful to have all this in a cookbook to go from time to time as it is not well known I think.
Related SO questions
- https://stackoverflow.com/questions/41030477/changing-chunk-background-color-in-rmarkdown
- https://stackoverflow.com/questions/37944197/add-a-css-class-to-single-code-chunks-in-rmarkdown
- https://stackoverflow.com/questions/29291633/adding-custom-css-tags-to-an-rmarkdown-html-document
- https://stackoverflow.com/questions/14695892/change-code-block-color-in-knitr-markdown
cderv commented
Change font size through css: https://stackoverflow.com/questions/30446905/rmarkdown-font-size-and-header
cderv commented
There is also now the class.warning
, class.message
and class.error
.
Give examples about this
yihui commented
I think these two sections have covered most of the SO posts above: