Como passar duas opções para o tcolorbox

Como passar duas opções para o tcolorbox

Alguém poderia me informar como posso passar uma opção minted optionse outra tcolorboxao mesmo tempo para uma pythoncodelistagem tcolorbox? Quer dizer, quero que algumas opções sejam passadas para minted options, como mostrado #1no MWE abaixo e algumas sejam passadas para tcolorbox, como mostrado por #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}    

Responder1

O que você fez funciona com pequenas mudanças. Você tem que passar opções para pythoncodeambientes como este

\begin{pythoncode}[linenos=true,]{colback=red!5!white,colframe=red!75!black,title=My nice heading}

Você tornou as opções tcolorbox(ou seja, pythoncode) obrigatórias, portanto, elas devem ser envolvidas por colchetes onde as mintedopções vão para dentro de 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}

insira a descrição da imagem aqui

Algumas elaborações:

Quando você define

\newtcblisting{pythoncode}[2][]{

Você está dizendo que haverá dois argumentos para o pythoncodemeio ambiente. Com um vazio [], você está criando o primeiro argumento optionalcujo valor padrão é nenhum. O argumento opcional deve ser usado dentro bracketsou pode ser simplesmente omitido, caso em que o valor padrão (aqui nenhum) será usado. O segundo argumento é obrigatório e colocado entre colchetes. Se você não quiser atribuir nenhum valor, simplesmente use {}(ao contrário do primeiro, onde você não precisa usar nenhum). Portanto, sem opções, você precisa usar

\begin{pythoncode}{}

O resultado final [2][]significa que há dois argumentos, o primeiro argumento é opcional e tem default none.

informação relacionada