\@primitives{fancyvrb}
\usepackage{keyval}
%%%%%%%% Helper
\def\verb@table#1{\@open{table}{#1}\@open{tr}{}\@open{td}{}}
\def\verb@elbat{\@close{td}\@close{tr}\@close{table}}
%%%%%%%%% Font size
\define@key{fancyvrb}{fontsize}{\def\verb@size{#1}}
\def\verb@size{}
\define@key{fancyvrb}{fontshape}{\def\verb@shape{\csname #1shape\endcsname}}
\def\verb@shape{}
%%%%%%% Labels
\def\verb@label@
  #1{\@open{tr}{}\@open{th}{style="text-align:center" colspan=3}#1\@close{th}\@close{tr}}
\def\verb@toplabel{}\def\verb@bottomlabel{}
\def\verb@deftop#1{\def\verb@toplabel{\ifverb@top\verb@horiz@line\verb@label@{#1}\fi}}
\def\verb@defbottom#1{\def\verb@bottomlabel{\ifverb@bottom\verb@label@{#1}\verb@horiz@line\fi}}
\newcommand{\verb@labelkey}[2][]
  {\def\verb@test{#1}%
  \ifx\verb@test\@empty\def\verb@label{#2}\else
  \def\verb@label{#1}\def\verb@labelbis{#2}\fi}
\newcommand{\verb@labels}[2][]
  {\def\verb@test{#1}%
  \ifx\verb@test\@empty\verb@deftop{#2}\else
  \verb@deftop{#1}\verb@defbottom{#2}\fi}
\define@key{fancyvrb}{label}{\@callopt{\verb@labelkey}{#1}}
\def\verb@labelpos{default}
\define@key{fancyvrb}{labelposition}{\def\verb@labelpos{#1}}
%%%%%%% Framing
\def\verb@framesize{2}
\define@key{fancyvrb}{framerule}{\def\verb@framesize{\@getlength{#1}}}
\def\verb@framesep{1}
\define@key{fancyvrb}{framesep}{\def\verb@framesep{\@getlength{#1}}}
\def\verb@rulecolor{black}
\def\verb@rulecolor@key
#1{\def\verb@rulecolor{{\let\color\@getcolor#1}}}
\define@key{fancyvrb}{rulecolor}{\verb@rulecolor@key{#1}}
\def\verb@fillcolor@key
#1{\def\verb@fillcolor{{\let\color\@getcolor{}BGCOLOR=#1{}}}}
\define@key{fancyvrb}{fillcolor}{\verb@fillcolor@key{#1}}
\def\verb@fillcolor{}
\def\verb@horiz@line
  {\@open{tr}{}\verb@vert@line[3]\@close{tr}}
\newcommand{\verb@vert@line}[1][1]
  {\@open{td}{style="background-color:\verb@rulecolor{}" colspan="\@getprint{#1}"}%
   \verb@table{style="border-spacing:\verb@framesize;border:0;border-collapse:separate" class="cellpadding0"}
   \verb@elbat\@close{td}}
\define@key{fancyvrb}{frame}{\def\verb@frame{#1}}
\def\verb@frame{none}
\def\begin@frame@{\@open{table}{style="border:0;border-spacing:0" class="cellpadding0"}\verb@toplabel\@open{tr}{}\@open{td}{}\@open{table}{\@getprint{\verb@fillcolor} style="border:0;border-spacing:0" class="cellpadding0"
 }\ifverb@top\verb@horiz@line\fi\@open{tr}{}\ifverb@left\verb@vert@line\fi\@open{td}{}\@open{table}{style="border:0;border-spacing:0"}\@open{tr}{}\@open{td}{style="padding:\verb@framesep"}}
\def\end@frame@{\@close{td}\@close{tr}\@close{table}\@close{td}\ifverb@right\verb@vert@line\fi\@close{tr}\ifverb@bottom\verb@horiz@line\fi\@close{table}\@close{td}\@close{tr}\verb@bottomlabel\@close{table}}
\newif\ifverb@left\newif\ifverb@bottom\newif\ifverb@top\newif\ifverb@right
\def\reset@frame
  {\setcounter{verb@count}{0}%
  \verb@leftfalse\verb@bottomfalse\verb@topfalse\verb@rightfalse%
  \def\verb@toplabel{}\def\verb@bottomlabel{}}
\def\verb@labelmaker#1#2{\ifu#2\else#1#2\fi}
\def\check@labels
  {\ifthenelse{\equal{\verb@labelpos}{topline}}
    {\verb@labelmaker{\verb@deftop}{\verb@label}}{}%
  \ifthenelse{\equal{\verb@labelpos}{bottomline}}
    {\verb@labelmaker{\verb@defbottom}{\verb@label}%
    \verb@labelmaker{\verb@defbottom}{\verb@labelbis}}{}%
  \ifthenelse{\equal{\verb@labelpos}{all}}
    {\verb@labelmaker{\verb@deftop}{\verb@label}%
    \verb@labelmaker{\verb@defbottom}{\verb@label}%
    \verb@labelmaker{\verb@defbottom}{\verb@labelbis}}{}%
  \ifthenelse{\equal{\verb@labelpos}{default}}
    {\verb@labelmaker{\verb@deftop}{\verb@label}%
    \verb@labelmaker{\verb@defbottom}{\verb@labelbis}}{}}
\def\check@frame
  {\reset@frame%
   \ifthenelse{\equal{\verb@frame}{lines}}{\verb@toptrue\verb@bottomtrue}{}%
   \ifthenelse{\equal{\verb@frame}{leftline}}{\verb@lefttrue}{}%
   \ifthenelse{\equal{\verb@frame}{topline}}{\verb@toptrue}{}%
   \ifthenelse{\equal{\verb@frame}{bottomline}}{\verb@bottomtrue}{}%
   \ifthenelse{\equal{\verb@frame}{single}}
     {\verb@toptrue\verb@bottomtrue\verb@lefttrue\verb@righttrue}{}%
   \ifthenelse{\equal{\verb@frame}{none}}
      {\let\begin@frame\@empty\let\end@frame\@empty}
      {\check@labels\let\begin@frame\begin@frame@\let\end@frame\end@frame@}}
%%%%%%%%% Line numbers
\newcounter{verb@count}
\newcommand{\verb@startline}{\stepcounter{verb@count}\theverb@count}
%%%%%%%%%% User command
\newcommand{\fvset}[1]{\@setkeys{fancyvrb}{#1}}
\newenvironment{Verbatim}[1][]
  {\@setkeys{fancyvrb}{#1}%
  \def\endVerbatim{\@endVerbatim\end@frame}%
  \check@frame\begin@frame\verb@shape\verb@size\@Verbatim}
  {}
\newcommand{\VerbatimInput}[1]
  {\@scaninput{\begin{Verbatim}}{#1}{\end{Verbatim}}}
