在 minted 套件中,formatcom 選項 ocure 底部邊距

在 minted 套件中,formatcom 選項 ocure 底部邊距

具有以下 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}

呈現為在此輸入影像描述

相關內容