在 minted 包中 formatcom 选项 ocure bottom marging

在 minted 包中 formatcom 选项 ocure bottom marging

具有以下 MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{minted}

\begin{document}


\begin{minted}[bgcolor=black,formatcom=\color{white}]{bash}
#! /bin/bash
# script to turn the screen blue
setterm -background blue
echo It is a blue day
\end{minted}

\end{document}

我得到了这个渲染:

使用 formatcom 选项进行控制台渲染

如您所见,该formatcom选项在源代码底部添加了一个空白行。

那么,如何删除它呢?

答案1

Minted 在底层使用了 fancyvrb。要使用该formatcom选项更改文本颜色,您必须定义一个重新定义的函数\FancyVerbFormatLine,如下所示

\newcommand{\shellfgcolor}{%
  \def\FancyVerbFormatLine##1{\textcolor{white}{##1}}%
}

并将其传递给formatcomminted 选项,如下所示formatcom=\shellfgcolor

因此你的 MWE 变成:

\documentclass{article}
\usepackage{xcolor}
\usepackage{minted}

\newcommand{\shellfgcolor}{%
  \def\FancyVerbFormatLine##1{\textcolor{white}{##1}}%
}

\begin{document}

\begin{minted}[bgcolor=black,formatcom=\shellfgcolor]{bash}
#! /bin/bash
# script to turn the screen blue
setterm -background blue
echo It is a blue day
\end{minted}

\end{document}

渲染为在此处输入图片描述

相关内容