Minted Package,内联背景颜色

Minted Package,内联背景颜色

梅威瑟:

\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}

生产在此处输入图片描述

是否可以将涂漆区域的底部缩短一些?

答案1

根据的手册minted,如果应用该期权,则使用minipage和一个标的。\colorboxbgcolor=...

由于\colorbox使用\fboxsep长度作为文本和框“框架”之间的分隔,因此改变就足够了\fboxsep

对此应用补丁\minted@inputpyg@inline将会成功:

\xpatchcmd{\minted@inputpyg@inline}{%
  \colorbox%
}{%
  \fboxsep\mintedfboxsep%
  \colorbox%
}{\typeout{Success}}{\typeout{Failure}}
\makeatother

由于这一切都发生在一个组中(参见中的详细定义)minted.sty,外部\fboxsep值不会改变。

但是:对于或框\fboxsep的所有四个分隔线来说,长度都是相同的,即顶部、底部、左侧和右侧分隔线都会发生变化\fbox\colorbox全部如果\fboxsep被修改了!

这是一个快速修补以改变底层\fboxsep长度。

\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}

编辑

我上面所述的内容在这里是正确的,但我仅改变了铸造内联代码\fboxsep的内部定义,引入了四种长度:\colorbox

\fboxrsep、、\fboxlsep和分别负责、、和\fboxtsep的分离。\fboxbseprightlefttopbottom

使用各种\setlength{...}{}语句之一随意改变。

\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}

在此处输入图片描述

相关内容