I have the following mwe:
% arara: pdflatex: { shell: true }
% arara: pdflatex: { shell: true }
\documentclass{article}
\usepackage{minted}
\usepackage{listings}
\usepackage{caption}
\captionsetup[lstlisting]{font=sf,labelfont=bf,skip=\smallskipamount}
\usepackage{xparse}
\NewDocumentEnvironment {example} { mm }
{\VerbatimEnvironment
\captionof{lstlisting}{#2}\ifx\relax#1\relax\else\label{#1}\fi%
\begin{minted}[linenos=true]{latex}}
{\end{minted}}
\NewDocumentEnvironment {xexample} { o o }
{\VerbatimEnvironment
\IfNoValueF { #1 }%
{\captionof{lstlisting}{#1}%
\IfNoValueF {#2} { \label{#2} }%
}%
\begin{minted}[linenos=true]{latex}}%
{\end{minted}}
\begin{document}
\begin{example}{TheLabel}{The caption}
\usepackage{minted}
\usepackage{caption,floatrow}
\end{example}
%\begin{xexample}[Another caption]
%\usepackage{minted}
%\usepackage{caption,floatrow}
%\end{xexample}
See Example~\ref{TheLabel}
\end{document}
The environment example
works like expected. However this environment has two mandatory arguments. I am a friend of optional arguments/keys. With the environment xexample
I tried this implementation but it fails.
What's going on here?
Bonus: Is it possible to pass options to minted
as well? (of course with an optional argument ;-))
\begin{minted}[caption=...,label=...]
?? – user2478 May 2 '13 at 18:31minted
doesn't provide the optionscaption
norlabel
. egreg found a nice way: chat.stackexchange.com/transcript/message/9247614#9247614 – Marco Daniel May 2 '13 at 18:38fancyvrb
available for minted. – user2478 May 2 '13 at 18:42\fvset
? I have no idea? – Marco Daniel May 2 '13 at 18:44fancyvrb
are imported byminted
with\minted@define@extra{...}
Replace...
withlabel
and it is known. But I suppose thatfancyvrb
did not know thecaption
option. – user2478 May 2 '13 at 18:52