3

MWE:

\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}
\definecolor{bg}{rgb}{0.9, 0.9, 0.9}

\makeatother

\begin{document}

\newmintinline{python}{python3, fontsize=\scriptsize, bgcolor=bg}

Of these, \pythoninline{generators} is one of the biggest culprits. I'm guessing this is the case for most novice Python programmers.

\end{document}

producesenter image description here

Is it possible to make the bottom part of the painted area shorter?

  • 1
    minted uses a minipage with \colorbox to display coloured stuff with background. This means, that \fboxsep=0.1pt should do the trick`, but this will change all spaces (top, bottom, left, right) of the displayed coloured box – user31729 Nov 5 '15 at 10:03
  • @ChristianHupfer: There is certainly a tcolorbox alternative isn't it? – user11232 Nov 5 '15 at 10:47
  • @HarishKumar: Yes, I think so: A \DeclareTColorBox stuff which does the minted stuff internally? – user31729 Nov 5 '15 at 10:49
  • @Christian. Thanks. \fboxsep=1.5pt did it for me. – blackened Nov 5 '15 at 10:54
  • 1
    @ChristianHupfer I think very simple: extrude bottom by key. – user11232 Nov 5 '15 at 10:55
2

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}

enter image description here

  • Thank you. How do I control the bottom vertical length in your macro? Say I want it a bit taller at the bottom. – blackened Nov 5 '15 at 14:05
  • 1
    @blackened: Use the newer version at bottom of my answer and say \setlength{\fboxbsep}{your value} – user31729 Nov 5 '15 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.