我正在使用 Python 代码编写文档,我想使其类似于 IDLE 风格。使用minted
,我们可以自定义环境,以便每行代码都以 >>> 开头,但是,我希望 >>> 仅出现在命令中,而不出现在结果中。
这是我的 MWE:
%\usepackage{geometry}
%\geometry{width = 16cm, height =24cm}
\usepackage{tgpagella}
\usepackage[utf8]{vietnam}
\usepackage{tcolorbox}
\usepackage{parskip}
\usepackage{tabularx}
\tcbuselibrary{minted,breakable,xparse,skins}
\renewcommand{\FancyVerbFormatLine}[1]{>\/>\/> #1}
\usepackage{xcolor}
\definecolor{bg}{gray}{0.98}
\definecolor{bl}{rgb}{0.1,0.5,1}
\DeclareTCBListing{mintedbox}{O{}m!O{}}{breakable=true, listing engine=minted,
listing only, minted language=#2, minted style=default,
minted options={gobble=0, breaklines=true, breakafter=,, fontsize=\small, numbersep=8pt, #1},
boxsep=0pt, left skip=0pt, right skip=0pt, left=0pt, right=0pt, top=3pt, bottom=3pt, arc=0pt, leftrule=0pt,
rightrule=0pt, bottomrule=1pt, toprule=1pt, colback=bg, colframe=bl!10, enhanced}
%\renewcommand{\FancyVerbFormatLine}[1]{#1}
\begin{document}
\begin{mintedbox}{python}
sentence = "Python is powerful and easy to learn"
sentence.split()
['Python', 'is', 'powerful', 'and', 'easy', 'to', 'learn']
\end{mintedbox}
\end{document}
在此 MWE 中,\renewcommand{\FancyVerbFormatLine}[1]{>\/>\/> #1}
有助于将 >>> 放在每行的第一个位置。
我们如何定制才能让它像下面这样像IDLE呢?
谢谢阅读。