
具有以下 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
選項會在原始程式碼的底部建立一個額外的空白行。
那麼,要如何刪除呢?
答案1
Minted 在底層使用 fancyvrb。若要使用選項變更文字顏色,formatcom
您必須定義一個重新定義的函數\FancyVerbFormatLine
,如下所示
\newcommand{\shellfgcolor}{%
\def\FancyVerbFormatLine##1{\textcolor{white}{##1}}%
}
並將其傳遞給formatcom
minted 選項,如下所示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}