Minted with fancyvrb label

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?

-
For the record, this wasn’t included “on purpose” – I didn’t think it was really all that useful, considering that you can provide float captions, and the name “label” clashes with a distinct concept in TeX (i.e. references) which I find awkward. Anyway, I’ve now added the option (but heaven only knows when I’ll find time to push the next release). –  Konrad Rudolph Jan 4 '11 at 20:49
@Konrad: how should there be a confict? And it is useful when all those verbatim listings are not of a float type. And if you have a problem then call it title, which doesn't really make a difference. And why do you not pass all options simply to fancyvrb, then you do not have to define them in the package? –  Herbert Jan 5 '11 at 13:17
@Herbert: there’s a conflict of meanings when talking about this (e.g. in the documentation: it’s not enough to say that “this option adds a label” since that would be confusing). –  Konrad Rudolph Jan 5 '11 at 13:20
@Konrad: understood, then call it a title –  Herbert Jan 5 '11 at 13:24
@Konrad: why not: "All available optional arguments of fancyvrb are possible". Then you do not have to say anything about a label or title or ... –  Herbert Jan 5 '11 at 13:26

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}


-
(+1) Huh, that's really more elegant! –  chl Jan 4 '11 at 19:30
Excellent solution –  YuppieNetworking Jan 5 '11 at 13:14

I didn't see anything about that in the reference manual. However, I do think you can get a pretty output with tikz. Here is an example,

% that should go into your preamble
% -%<------------------------------
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}

\definecolor{myblue}{cmyk}{0.94,0.54,0,0}

\tikzstyle{snippet}=[draw=myblue,fill=none,thick,
text width=0.85\textwidth,rectangle,
rounded corners=0pt,inner sep=0pt,inner ysep=10pt]
\tikzstyle{title}=[fill=white,text=myblue,rectangle]
% ------------------------------>%-

% and here is a framed snippet
\begin{tikzpicture}
\node[snippet](box){
\begin{minted}[fontsize=\footnotesize,frame=none,linenos=none]{c++}
int main() { return 0; }
\end{minted}
};;
\node[title] at (box.north) {Useless function};
\end{tikzpicture}


The output is shown below:

-
Thanks chl (+1), that's a nice solution. I only have one problem: sometimes the code that I want to show is longer than a page. Normally fancyvrb and minted handle this gracefully by cutting it (when not using a float). However, with tikzpicture I imagine that it becomes a float and hence, it is not breakable in two pages. This is a supposition, of course, since I have never used tikz before. –  YuppieNetworking Jan 4 '11 at 15:56
I used such construction for very short snippet of code, or text advertising. Actually, @Herbert's solution looks better! –  chl Jan 4 '11 at 19:31