tcblisting box 不支持 minted 评论

tcblisting box 不支持 minted 评论

我注意到对于一些 tcblisting 框,代码无法正确显示。

在此处输入图片描述

起初,我以为是前言出了问题,因为另一个文件也出现过这种情况,但经过一些测试,我发现这似乎与多行注释有关("""comment"""在 Python 中)——单行注释似乎工作正常,没有注释的常规代码片段在框中工作正常。以下是 tcblisting 框的代码以及输出。

tcbdefinition和 的代码tcbexample

    % code def
    \newtcblisting[auto counter, number within=section, list inside=definitionlist]{tcbdefinition}[2][]{%
        colback=red!5, colbacktitle=red!20, coltitle=black,
        frame hidden, arc=2pt, titlerule=0pt, toptitle=2pt, bottomtitle=2pt,
        fonttitle=\bfseries, breakable, enhanced, parbox=false,
        segmentation style={solid, draw=red!20, line width=1pt},
        comment and listing,
        title=Definition~\thetcbcounter,
        comment={#2},#1
    }
    % code example
    \newtcblisting[auto counter, number within=section, list inside=examplelist]{tcbexample}[2][]{%
    colback=gray!5, colbacktitle=gray!40, coltitle=black,
    frame hidden, arc=2pt, titlerule=0pt, toptitle=2pt, bottomtitle=2pt,
    fonttitle=\bfseries, breakable, enhanced, parbox=false,
    segmentation style={solid, draw=gray!20, line width=1pt},
    comment and listing,
    title=Example~\thetcbcounter,
    comment={#2},#1
    }

% generate Name
    \pgfkeysifdefined{/tcb/name}{\fail}{
    \tcbset{
    name/.style={after title={: #1}}}
    }

输入代码:

Here is a cool Python function:
\begin{minted}{python}
def a_function(n):
    """A test function"""
    while n > 0:
        print("Test") # prints Test
    return "Done"
\end{minted}

\begin{tcbdefinition}[name = Defining a Cool Python Function, minted language = python]{Here is a cool Python function: \mintinline{text}{code}
}
def a_function(n):
    """a comment"""
    while n > 0:
        print("Test")
    return "Done"
\end{tcbdefinition}

\begin{tcbexample}[name = Defining a Cool Python Function, minted language = python]{
Here is a cool Python function: \mintinline{text}{code}
}
def a_function(n):
    # a comment
    while n > 0:
        print("Test")
    return "Done"
\end{tcbexample}

在此处输入图片描述

如果有人知道如何使用 minted/tcblisting 来避免对我的多行注释感到恼火,那就太好了。谢谢!

相关内容