I'm using TeXstudio for pretty much all my LaTeX needs.
I sometimes have to include small code snippets in a document where employing the listings
package would be overkill. Since I'd like for these to have a colored background (which is not supported by the standard verbatim
environment of course), I'm defining a new environment using the tcolorbox
and fancyvrb
packages, as suggested by @egreg in this excellent answer:
\usepackage{fancyvrb}
\usepackage{tcolorbox}
% ...
\newenvironment{BGVerbatim}
{\VerbatimEnvironment
\begin{tcolorbox}[breakable, colback = Dandelion!10!white, spartan, frame hidden, boxrule = 0pt, left = 1ex]%
\begin{Verbatim}}
{\end{Verbatim}\end{tcolorbox}}
This works fine, but if you include e.g. R code that includes $
characters, TeXstudio's syntax highlighting gets confused, which is especially problematic in large documents where thousands of subsequent lines may get wrongly highlighted as if in math mode.
knitr
. See for instance here, here or here.