[Tex/LaTex] Minted with fancyvrb label

labelsminted

I am using minted for the first time and after reading the docs, I could not find a way to put a label in the code listing. Just to be clear, I am not speaking of the \label of a listing environment. I am trying to reproduce a listing like

\begin{Verbatim}[fontsize=\footnotesize,frame=single,%
  label={This is the label},numbers=left]
  int main() { return 0; }
\end{Verbatim}

which creates a nice frame with a label "This is the label" in the middle.

Since minted uses fancyvrb, I though it would be easy to do it, but I did not succeed. The closer approach so far is

\begin{minted}[fontsize=\footnotesize,frame=single,linenos]{c++}
 int main() { return 0; }
\end{minted}

Does anyone know a way or a hack to achieve this?

Best Answer

I suppose, it is only missing in minted.sty

\documentclass{article}
\usepackage{minted}
\makeatletter
\minted@define@extra{label}
\makeatother
\begin{document}

foo
\begin{minted}[frame=single,label=foobar]{c++}
int main() { return 0; }
int foo() {return 1; }
\end{minted}
bar
\end{document}

alt text

Related Question