According to the manual of minted
, a minipage
and an underlying \colorbox
is used if the bgcolor=...
option is applied.
Since \colorbox
uses the \fboxsep
length as separation between text and box 'frame', it's sufficient to change \fboxsep
.
Applying a patch to \minted@inputpyg@inline
this will succeed:
\xpatchcmd{\minted@inputpyg@inline}{%
\colorbox%
}{%
\fboxsep\mintedfboxsep%
\colorbox%
}{\typeout{Success}}{\typeout{Failure}}
\makeatother
Since this all happens in a group (see the detailed definition in minted.sty
, the outer \fboxsep
value isn't changed.
However: \fboxsep
is a common length for all four separations of a \fbox
or \colorbox
box, i.e. the top, bottom, left and right separations are changed all if \fboxsep
is modified!
This is a quick patch to change the underlying \fboxsep
length.
\documentclass[10pt]{article}
\usepackage[english]{babel}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{libertine}
\usepackage[semibold]{sourcecodepro}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{xpatch}
\definecolor{bg}{rgb}{0.9, 0.9, 0.9}
\newlength{\mintedfboxsep}
\setlength{\mintedfboxsep}{1.5pt}
\newmintinline{python}{python3, fontsize=\scriptsize, framesep=0.1pt,bgcolor=bg}
\xpatchcmd{\minted@inputpyg@inline}{%
\colorbox%
}{%
\fboxsep\mintedfboxsep%
\colorbox%
}{\typeout{Success}}{\typeout{Failure}}
\makeatother
\begin{document}
Of these, \pythoninline{generators} is one of the biggest culprits. I'm guessing this is the case for most novice Python programmers.
\end{document}
Edit
What I've stated above about \fboxsep
is true here, but I've changed the internal definition of \colorbox
for the minted inline code only, introducing four lenghts:
\fboxrsep
, \fboxlsep
, \fboxtsep
and \fboxbsep
, each responsible for right
, left
, top
and bottom
separation.
Use one of the various \setlength{...}{}
statements to change at will.
\documentclass[10pt]{article}
\usepackage[english]{babel}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{libertine}
\usepackage[semibold]{sourcecodepro}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{xpatch}
\definecolor{bg}{rgb}{0.9, 0.9, 0.9}
\newlength{\mintedfboxsep}
\setlength{\mintedfboxsep}{0.2pt}
\newmintinline{python}{python3, fontsize=\scriptsize, framesep=0.1pt,bgcolor=bg}
\makeatletter
\newlength{\fboxrsep}
\setlength{\fboxrsep}{\fboxsep}
\newlength{\fboxlsep}
\setlength{\fboxlsep}{\fboxsep}
\newlength{\fboxtsep}
\setlength{\fboxtsep}{\fboxsep}
\newlength{\fboxbsep}
\setlength{\fboxbsep}{\mintedfboxsep}
\xpatchcmd{\minted@inputpyg@inline}{%
\colorbox%
}{%
\long\def\color@b@x##1##2##3%
{\leavevmode
\setbox\z@\hbox{\kern\fboxlsep{\set@color##3}\kern\fboxrsep}%
\dimen@\ht\z@\advance\dimen@\fboxtsep\ht\z@\dimen@
\dimen@\dp\z@\advance\dimen@\fboxbsep\dp\z@\dimen@
{##1{##2\color@block{\wd\z@}{\ht\z@}{\dp\z@}\box\z@}}}%
\colorbox%
}{\typeout{Success}}{\typeout{Failure}}
\makeatother
\begin{document}
Of these, \pythoninline{generators} is one of the biggest culprits. I'm guessing this is the case for most novice Python programmers.
Compare:
\colorbox{bg}{generators}
\end{document}
There are various color schemas for minted, and several of them have gray comments. One example is the pastie
style:
\documentclass[11pt]{article}
\usepackage[cache=false]{minted}
\usemintedstyle{pastie}
\begin{document}
\begin{minted}[linenos]{c}
#include<Wire.h> //Wire library allow us to communicate with the I2C
\end{minted}
\end{document}
You can find examples of the different styles on https://help.farbox.com/pygments.html. These examples are for Python highlighting, but the color of the comments (starting with #
in Python) is the same for other languages such as C. You can also try out the styles on your own code easily on https://pygments.org/demo/. Note that not all of the styles may be available on your system (but probably they are).
Best Answer
The minted documentation has a way to highlight text, as shown here:
As far as I understand, it is achieved by escaping the minted environment and executing the
\colorbox
command. It is possible to use the\textcolor
command, as shown by user187803 instead of\colorbox
to make it work with minted.Example:
Result:
Applying it to your example, the underscore in
[UPLOAD_ID]
needs to be escaped with a backslash[UPLOAD\_ID]
. This is necessary because the underscore is normally used to index a character. But in this case the underscore should be printed as an underscore and not interpreted to make an index out ofID
. If we do not use the backslash here, it will result in an error.Provided Example:
Result: