\@primitives{fancyvrb}
\usepackage{keyval}
%%%%%%%%
\def\verb@background{background-color:white;}
\let\verb@fillcolor\relax
\def\verb@margin{margin:1em 0pt;}
\def\verb@border{border:none;}
\def\verb@bordercolor{border-color:black;}
\def\verb@borderwidth{border-width:2px;}
\def\verb@padding{padding:0.5em 0.5em;}
\def\verb@style{\verb@margin\verb@border\verb@bordercolor\verb@borderwidth\verb@padding\verb@fillcolor}
%%%%%%%% Helper
\newtokens{\verb@start}\newtokens{\verb@start@line}
\def\verb@warn#1#2{\hva@warn{fancyvrb, unknown value #1 for key #2}}
\def\verb@getcolor#1{\bgroup\let\color\@getstylecolor#1\egroup}
\let\verb@getlength\@getlength
%%%%%%%%% Font change, probably quite brittle
\def\verb@size{}
\def\verb@fontsize@key#1{\def\verb@size{#1}}
\define@key{fancyvrb}{fontsize}{\verb@fontsize@key{#1}}
\def\verb@shape{}
\def\verb@fontshape@key#1{\def\verb@shape{\csname #1shape\endcsname}}
\define@key{fancyvrb}{fontshape}{\verb@fontshape@key{#1}}
\addtokens{\verb@start}{\verb@size\verb@shape}
%%%%%%% Labels
%Positioning, depending upon two booleans
\newif\ifverb@top\newif\ifverb@bot
\def\verb@fmt@label#1{\bgroup\@styleattr{code}{class="verb"}#1\egroup}
\def\verb@top@top
  {\@open{div}{style="\verb@margin"}\let\verb@margin\relax%
  \@open{div}{style="text-align:center;"}\verb@fmt@label{\verb@label@top}\@close{div}}
\def\verb@top@bot{\@open{div}{style="\verb@margin"}\let\verb@margin\relax}
\def\verb@bot@bot
  {\@open{div}{style="text-align:center;"}\verb@fmt@label{\verb@label@bot}\@close{div}\@close{div}}
\def\verb@bot@top{\@close{div}}
\def\verb@top
{\ifverb@top\verb@top@top
\else\ifverb@bot\verb@top@bot\else\relax\fi
\else\relax\fi}
\def\verb@bot
{\ifverb@bot\verb@bot@bot
\else\ifverb@top\verb@bot@top\else\relax\fi
\else\relax\fi}
% Key
\newcommand{\verb@labelkey}[2][]
  {\def\verb@test{#1}%
  \ifx\verb@test\@empty%
    \def\verb@label@top{#2}\def\verb@label@bot{#2}%
    \verb@toptrue\verb@botfalse
  \else
    \def\verb@label@top{#1}\def\verb@label@bot{#2}%
    \verb@toptrue\verb@bottrue
  \fi}
\define@key{fancyvrb}{label}{\@callopt{\verb@labelkey}{#1}}
% Label position
\define@key{fancyvrb}{labelposition}{\verb@pos@set{#1}}
% Delayed position change
\addtokens{\verb@start}{\verb@pos}
\let\verb@pos@default\relax
\let\verb@pos\verb@pos@default
\def\verb@pos@none{\verb@topfalse\verb@botfalse}
\def\verb@pos@all{\verb@toptrue\verb@bottrue}
\def\verb@pos@topline{\verb@toptrue\verb@botfalse}
\def\verb@pos@bottomline{\verb@topfalse\verb@bottrue}
\def\verb@pos@set#1{%
\ifu\csname verb@pos@#1\endcsname\verb@warn{#1}{labelposition}%
\else\let\verb@pos\csname verb@pos@#1\endcsname\fi}
%%%%%%%%%%%
% Framing %
%%%%%%%%%%%
\define@key
  {fancyvrb}
  {framerule}
  {\def\verb@borderwidth{border-width:\verb@getlength{#1};}}
\define@key
  {fancyvrb}
  {framesep}
  {\def\verb@padding{padding:\verb@getlength{#1} 0.5em;}}
\define@key
  {fancyvrb}
  {rulecolor}
  {\def\verb@bordercolor{border-color:\verb@getcolor{#1};}}
\define@key
  {fancyvrb}
  {fillcolor}
  {\def\verb@fillcolor{background-color:\verb@getcolor{#1};}}
%% Frame key
\def\verb@frame@single{\def\verb@border{border:solid;}}
\def\verb@frame@lines{\def\verb@border{border-top-style:solid;border-bottom-style:solid;}}
\def\verb@frame@none{\let\verb@border\relax}
\def\verb@frame@leftline{\def\verb@border{border-left:solid;}\def\verb@padding{padding:2pt;}}
\def\verb@frame@topline{\def\verb@border{border-top:solid;}}
\def\verb@frame@bottomline{\def\verb@border{border-bottom:solid;}}
\newcommand{\verb@frame@key}[1]
{\ifu\csname verb@frame@#1\endcsname
\verb@warn{#1}{frame}%
\else\csname verb@frame@#1\endcsname\fi}
\define@key{fancyvrb}{frame}{\verb@frame@key{#1}}
%%%%%%%%% Line numbers
% counter, with initial value settings
\newcounter{verb@count}
\def\verb@fst@auto{\setcounter{verb@count}{0}}
\def\verb@fst@int#1{\setcounter{verb@count}{#1}\addtocounter{verb@count}{-1}}
\let\verb@fst@last\relax
\let\verb@start@num\verb@fst@auto
\newcommand{\verb@pad}[1]{\@pad{\@print{ }}{3}{#1}  }
\newcommand{\verb@num}{\stepcounter{verb@count}\verb@pad{\theverb@count}}
\def\verb@activate@num
{\addtokens{\verb@start}{\verb@start@num}%
\addtokens{\verb@start@line}{\verb@num}}
\let\verb@num@left\verb@activate@num
\def\verb@num@right
{\hva@warn{fancyvrb, 'right' value for key numbers changed into 'left'}%
\verb@num@left}
\let\verb@num@none\relax
\newcommand{\verb@numbers@key}[1]
  {\ifu\csname verb@num@#1\endcsname\verb@warn{#1}{numbers}%
  \else\csname verb@num@#1\endcsname\fi}
\define@key{fancyvrb}{numbers}{\verb@numbers@key{#1}}
% first number
\newcommand{\verb@firstnumber@key}[1]
{\ifu\csname verb@fst@#1\endcsname\def\verb@start@num{\verb@fst@int{#1}}%
\else\let\verb@start@num\csname verb@fst@#1\endcsname\fi}
\define@key{fancyvrb}{firstnumber}{\verb@firstnumber@key{#1}}
%%%%%%%%%% User command
\newcommand{\fvset}[1]{\@setkeys{fancyvrb}{#1}}
\newenvironment{Verbatim}[1][]
  {\@setkeys{fancyvrb}{#1}%
  \verb@start%
  \def\endVerbatim{\@endVerbatim\@close{div}\verb@bot}%
  \ifthenelse{\equal{\verb@fillcolor}{}}{\let\verb@background\relax}{}%
  \verb@top%
  \@open{div}{style="\verb@style"}\@Verbatim{margin:0pt;padding:0pt;\verb@background}}
  {}
\newcommand{\VerbatimInput}[2][]
  {\@scaninput{\begin{Verbatim}[#1]}{#2}{\end{Verbatim}}}
