有人能告诉我如何同时将一个选项传递给minted options
和另一个传递给tcolorbox 列表吗?我的意思是,我希望将一些选项传递给,如下面的 MWE所示,将一些选项传递给,如 所示。tcolorbox
pythoncode
minted options
#1
tcolorbox
#2
\documentclass{book}
\usepackage[left=1.00in, right=1.00in, top=1.00in, bottom=1.00in]{geometry}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{minted,skins,breakable}
\usepackage{hyperref}
\hypersetup{ %
pdfborder = {0 0 0},
colorlinks=true,
}
\newtcblisting{pythoncode}[2][]{
listing engine=minted,
breakable,
colback=bg,
colframe=black!70,
listing only,
minted style=colorful,
minted language=python,
minted options={linenos=true,numbersep=3mm,texcl=true,#1},
left=5mm,enhanced,
overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
rectangle ([xshift=5mm]frame.north west);\end{tcbclipinterior}},
#2,
}
\begin{document}
\section{Python example}
\begin{pythoncode}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
# indent your Python code to put into an email
import glob
# glob supports Unix style pathname extensions
python_files = glob.glob('*.py')
for file_name in sorted(python_files):
print ' ------' + file_name
with open(file_name) as f:
for line in f:
print ' ' + line.rstrip()
print
\end{pythoncode}
\end{document}
答案1
你所做的只需要进行一些小的修改就可以了。你必须pythoncode
像这样将选项传递给环境
\begin{pythoncode}[linenos=true,]{colback=red!5!white,colframe=red!75!black,title=My nice heading}
您已将选项设为tcolorbox
(即pythoncode
)必填项,因此它们必须用括号括起来,而minted
选项则放在 里面brakets
。
\documentclass{book}
\usepackage[left=1.00in, right=1.00in, top=1.00in, bottom=1.00in]{geometry}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{minted,skins,breakable}
\usepackage{hyperref}
\hypersetup{ %
pdfborder = {0 0 0},
colorlinks=true,
}
\newtcblisting{pythoncode}[2][]{
listing engine=minted,
breakable,
colback=bg,
colframe=black!70,
listing only,
minted style=colorful,
minted language=python,
minted options={numbersep=3mm,texcl=true,#1},
left=5mm,enhanced,
overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
rectangle ([xshift=5mm]frame.north west);\end{tcbclipinterior}},
#2,
}
\begin{document}
\section{Python example}
\begin{pythoncode}[linenos=true,]{colback=red!5!white,colframe=red!75!black,title=My nice heading}
# indent your Python code to put into an email
import glob
# glob supports Unix style pathname extensions
python_files = glob.glob('*.py')
for file_name in sorted(python_files):
print ' ------' + file_name
with open(file_name) as f:
for line in f:
print ' ' + line.rstrip()
print
\end{pythoncode}
\end{document}
一些详细说明:
当你定义
\newtcblisting{pythoncode}[2][]{
您说的是环境将有两个参数pythoncode
。如果为空[]
,则将第一个参数作为optional
默认值为 none 的参数。可选参数将在 内使用brackets
,或者可以简单地省略,在这种情况下将使用默认值(此处为 none)。第二个参数是必需的,放在括号内。如果您不想给它赋值,只需使用{}
(与第一个参数不同,您不需要使用任何值)。因此,没有选项,您必须使用
\begin{pythoncode}{}
底线[2][]
意味着有两个参数,第一个参数是可选的并且有默认值none
。