Closed mirand863 closed 1 year ago
Edit: question also asked on stackexchange
Is the question obsolete now, because the stackexchange gives Page not found. This question was voluntarily removed by its author. ?
It was not getting views so I deleted. Undeleted now. :)
The options finalizecache
and cachedir
are package options according to the minted
documentation, i.e. you have to use these options when including the package.
You could do the following:
\PassOptionsToPackage{finalizecache,cachedir=.}{minted}
\documentclass{article}
\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{document}
\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}
\end{document}
@T-F-S,
That worked perfectly. Thank you very much!
I am using minted to display python code and I need to use
finalizecache
andcachedir
to be able to submit my code somewhere else and compile without using--shell-escape
, which is disabled for security reasons. However, when I create anewtcblisting
and pass these parameters I get a keyval error saying that these parameters are undefined. This is how I define anewtcblisting
:Then I create my code like this:
Which gives me the output below:
Am I doing something wrong when creating this tcblisting? Other parameters such as linenos work fine.
Edit: question also asked on stackexchange