我正在使用 minted 来显示 python 代码,我需要使用finalizecache
和cachedir
才能将我的代码提交到其他地方并在不使用的情况下进行编译--shell-escape
,出于安全原因,此功能已被禁用。但是,当我创建newtcblisting
并传递这些参数时,我收到一个 keyval 错误,提示这些参数未定义。这是我定义 的方式newtcblisting
:
\usepackage[many]{tcolorbox}
\tcbuselibrary{minted,skins}
\usepackage{caption}
\definecolor{Gray}{gray}{0.9}
\newtcblisting{sourcecode}[1][python]{
colback=Gray,
listing engine=minted,
minted language=#1,
% minted options={finalizecache,cachedir=.}, % Package keyval Error: finalizecache and cachedir are undefined.
listing only,
skin=tile,
width=0.8\textwidth
}
\captionsetup[table]{name=Code}
然后我像这样创建我的代码:
\begin{table}[!htb]
\centering
\begin{sourcecode}
from hiclass import LocalClassifierPerNode
from hiclass.metrics import f1
from sklearn.ensemble import RandomForestClassifier
# define mock data
X_train = X_test = [[1, 2], [3, 4]]
Y_train = Y_test = [
["Animal", "Mammal", "Cat"],
["Animal", "Reptile", "Turtle"],
]
# Use random forest classifiers for every node
rf = RandomForestClassifier()
lcpn = LocalClassifierPerNode(local_classifier=rf)
lcpn.fit(X_train, Y_train) # Train model
predictions = lcpn.predict(X_test) # Predict test data
# Print hierarchical F-score
print(f"f1: {f1(y_true=Y_test, y_pred=predictions)}")
\end{sourcecode}
\caption{Example on how to use \texttt{HiClass} to train and evaluate a hierarchical classifier.}
\label{code}
\end{table}
这给了我下面的输出:
我在创建这个 tcblisting 时做错了什么吗?其他参数(例如 linenos)都可以正常工作。
编辑:问题也问问题 #208。