\def\filedate{1996/11/24}
\def\filedate{1996/11/28 FMi}
\def\filedate{1996/12/03 FMi}
\def\filedate{1996/12/06 FMi}
\def\filedate{1996/12/07a FMi}
\def\filedate{1996/12/10 FMi}
\def\filedate{1996/12/15 FMi}
\def\filedate{1996/12/13 FMi}
\def\filedate{1996/12/26 FMi}
\def\filedate{1997/01/02 FMi}
\def\filedate{1997/01/07 FMi}
\def\filedate{1997/01/11 FMi}
\ProvidesFile{fancyvrb.rc}[\filedate\space fancyvrb customization
    by Sebastian Rahtz and Frank Mittelbach for LaTeX Graphics Companion]
% Define verbatim and example environments:
%  Verbatim  - indented like quote environment, \small font.
%  nVerbatim - Like "Verbatim", but numbered.
%  example   - code and output, side by side
%  example*  - one above other
%  Example   - Rendered as PS, like original, side by side
%  Example*  - Rendered as PS, one above other
%  MPExample - Metapost example, side by side
%  MPExample* - Metapost example, one above another
%  MPEscape - Metapost exaple, just PS
%  InlineEscape - for use inline
%  Escape - Rendered as PS, with *no* verbatim text
% The example environments have the following step in common:
% 1. Save example verbatim to numbered example file
% 2. Input file verbatim  or EPS file
% 3. Input again 
% All of them save their text as files in the \EX@dir directory
% (this needs a trailing / as part of the definition)
%

% bug fix for fancyvrb: missing percent sign results in issued \par!

\begingroup
\catcode`\^^M=\active
  \gdef\FV@BeginScanning#1^^M{%
    \def\@tempa{#1}\ifx\@tempa\@empty\else\FV@BadBeginError\fi%  <------
    \FV@GetLine}%
\endgroup



\RequirePackage{ifthen}
\RequirePackage{graphicx}
\RequirePackage{calc}
\newdimen\ExampleWidth
\newdimen\CodeWidth
\@ifundefined{fullwidth}{\let\fullwidth\textwidth}{}
\setlength\ExampleWidth{.5\fullwidth - 6pt}            % 12pt separation
% variable features
\def\EX@dir{}
\def\EX@prefix{}
\def\EX@class{article}
\def\PreambleCommands{}
\def\HiddenPreambleCommands{}
\def\EscapeParameters{}
\def\index@vals{}		% index entries etc passed on

%
\@ifundefined{thechapter}{\newcounter{chapter}}{}
%
\newcounter{EX@ct}[section]
\renewcommand\theEX@ct{%
 \arabic{chapter}-\arabic{section}-\arabic{EX@ct}}
\newcounter{side@count}

\newcommand\EPSinput[2][]{%
  \IfFileExists{\EX@dir\EX@prefix#2.eps}%
    {\ifx\\#1\\\else\typeout{Change EPS input to #1}\fi
     \includegraphics[#1,type=mps]{\EX@dir\EX@prefix#2.eps}}%
    {%
     \IfFileExists{\EX@dir\EX@prefix#2.eps.bb}%
       {\includegraphics[#1]{\EX@dir\EX@prefix#2}}%
       {\underline{\EX@dir\EX@prefix#2}}%
    }%
}

\def\IdentifyOddExample#1{}
\def\IdentifyEvenExample#1{}
\def\IdentifyExample#1{}




\def\SideBySideEx#1#2{% final picture, verbatim code
\bgroup\def\baselinestretch{1}%
\trivlist\item[]%
 \leavevmode
  \global\advance\c@side@count\@ne
  \setlength\CodeWidth{\fullwidth -12pt -\ExampleWidth}%
  \label{\thechapter:\theside@count}%
  \index@vals
  \ifthenelse{\isodd{\pageref{\thechapter:\theside@count}}}{%
   \IdentifyOddExample{-6pt,0}%
%%D   \typeout{Odd Example <\theEX@ct, \theside@count>
%%D       <code: \the\CodeWidth>+<picture: 
%%D       \the\ExampleWidth>/\the\fullwidth}%
    \makebox[\textwidth][l]{\@@Display{#1}\hspace{12pt}%
                            \@@VDisplay{#2}}%
  }{%
%%D   \typeout{Even Example <\theEX@ct, \theside@count>
%%D       <code: \the\CodeWidth>+<picture: 
%%D       \the\ExampleWidth>/\the\fullwidth}%
    \makebox[\textwidth][r]{%
      \@@Display{#1}%
      \hspace{12pt}%
      \@@VDisplay{#2}}%
   \IdentifyEvenExample{6pt,0}%
  }%
  \endtrivlist
  \egroup
}
\def\EX@input#1{\input{#1}}
\newsavebox{\@display}

\def\@@Display#1{%
 \sbox\@display{%
  \begin{minipage}[b]{\ExampleWidth}\centering#1\end{minipage}%
 }\raisebox{\depth}{\usebox{\@display}}%
}

\def\@@VDisplay#1{%
 \sbox\@display{%
  \begin{minipage}[b]{\CodeWidth}%
     \BVerbatimInput[fontsize=\small]{#1}\end{minipage}}%
% \raisebox{\depth}{\usebox{\@display}}%
 \usebox{\@display}%
}

\def\@@WideDisplay#1{%
 \sbox\@display{#1}%
 \setlength\ExampleWidth\columnwidth
   \global\advance\c@side@count\@ne
   \label{\thechapter:\theside@count}\nobreak
   \ifthenelse{\isodd{\pageref{\thechapter:\theside@count}}}{%
    \IdentifyOddExample{-6pt,0}%
%%D    \typeout{Odd Wide Example <\theEX@ct, \theside@count>
%%D       <picture: \the\wd\@display>/\the\ExampleWidth}%
    \makebox[\textwidth][l]{\@@Display{#1}}%
  }{%
%%D   \typeout{Even Wide Example <\theEX@ct, \theside@count>
%%D       <picture: \the\wd\@display>/\the\ExampleWidth}%
    \makebox[\textwidth][r]{\@@Display{#1}}%
    \IdentifyEvenExample{6pt,0}%
  }%
}



\def\BeginExample{%
  \refstepcounter{EX@ct}%
  \nobreak
  \VerbatimEnvironment
  \catcode`\<=12
  \begin{VerbatimOut}{\EX@dir\EX@prefix\theEX@ct.\EX@suffix}%
}

\newcommand{\EndExample}{\end{VerbatimOut}%
% after parsing the verb code we have to change some
% start/stop strings for the secnd parsing phase:
      \init@post@extension@code\EX@suffix}



\def\FVE@VerbatimOut{%
   \Write@Postamble
   \immediate\closeout\FV@OutFile\endgroup\@esphack}

\def\Write@Ex#1{%
      \begingroup
       \let\protect\@unexpandable@protect
       \edef\reserved@a{\immediate\write\FV@OutFile{#1}}
       \reserved@a
      \endgroup
}

\def\Write@OneEx#1{%
    {\@temptokena\expandafter{#1}%
     \immediate\write\FV@OutFile{\the\@temptokena}%
    }%
}

\def\Write@ExOne#1{%
     {\@temptokena\expandafter{#1}%
      \immediate\write\FV@OutFile{\the\@temptokena}%
     }%
}

\def\FVB@VerbatimOut#1{%
  \@bsphack
  \begingroup
    \FV@UseKeyValues
    \FV@DefineWhiteSpace
    \def\FV@Space{\space}%
    \FV@DefineTabOut
    \def\FV@ProcessLine{\immediate\write\FV@OutFile}%
    \immediate\openout\FV@OutFile #1\relax
    \Write@Preamble
    \let\FV@FontScanPrep\relax
    \FV@Scan}


\def\Write@Preamble@LaTeX{%
    \Write@Ex{\string\documentclass{\EX@class}}%
    \Write@Ex{\string\nonstopmode}%
% notice that this different command to write the preamble
% commands means that all verbatim code gets the current
% preamble commands printed out
%
% order is important Hidden ones first to allow setting things up for
% the other ones! FMi
%
 \ifx\HiddenPreambleCommands\@empty\else
    \Write@OneEx{\HiddenPreambleCommands}%
 \fi
    \Write@OneEx{\PreambleCommands}%
    \Write@Ex{\string\pagestyle{empty}}%
    \Write@Ex{\EX@width@spec}%
    \Write@Ex{\string\begin{document}}%
    \Write@Ex{\string\ResetPreambleCommands}%
    \Write@Ex{\string\ReadyForTheFray}%
    \Write@ExOne{\PreambleCommands}%
}
\def\Write@Preamble@MP{%
  \Write@OneEx{\PreambleCommands}%
  \Write@Ex{defaultfont:="ptmr8r";} % force Times for labels
  \Write@Ex{warningcheck:=0;}% this is to correct a known bug in MP
  \Write@Ex{beginfig(1)}%
}
%
% allows for numbered verbatim carrying on where the last
% ended
%
\define@key{FV}{firstnumber}[auto]{%
  \def\@tempa{#1}\def\@tempb{auto}%
  \ifx\@tempa\@tempb
    \def\FV@SetLineNo{%
      \c@FancyVerbLine\FV@CodeLineNo
      \advance\c@FancyVerbLine\m@ne}%
  \else
    \def\@tempb{continue}%
    \ifx\@tempa\@tempb
       \def\FV@SetLineNo{}%
    \else
     \def\@tempb{last}%
     \ifx\@tempa\@tempb
       \let\FV@SetLineNo\relax
     \else
       \def\FV@SetLineNo{\c@FancyVerbLine#1}%
     \fi
  \fi
\fi
}


% side by side LaTeX from external file
\newcommand{\Preexample}[1]{%
 \PrepareExampleWidth
 \SideBySideEx{\EX@input{\EX@dir#1}}{\EX@dir#1}%
}

% now the ones which write stuff for an EPS file
% for side by side examples, the text width of the separate file
% needs to be specified.
\def\EX@width@spec{}
\def\PrepareExampleWidth{%
 \def\EX@width@spec{\string\setlength\string\textwidth{\the\ExampleWidth}}}

%%% don't think so FMi: \string\addtolength{\string\textwidth}{-6mm}}}


%
% compatibility with Michel, with moreverb, and verbatim package
%
\def\SixPt{\fontsize{6}{7\p@}\selectfont}
%
% input files verbatim, numbered and unnumbered
%
\def\verbfile#1{\VerbatimInput[fontsize=\small,xleftmargin=\parindent]{#1}}
\let\verbatiminput\verbfile
\def\listinginput#1#2{\VerbatimInput[fontsize=\small,firstnumber=#1,%
                                     numbers=left]{#2}}
%
% verbatim in various sizes; these are all Verbatim, ie flush left,
% not LVerbatim, which uses a list, and is indented
\DefineVerbatimEnvironment{verbatim}{Verbatim}
                          {fontsize=\small,xleftmargin=\parindent}
%
\DefineVerbatimEnvironment{ssverbatim}{Verbatim}{fontsize=\scriptsize}
\DefineVerbatimEnvironment{fverbatim}{Verbatim}{fontsize=\footnotesize}
\DefineVerbatimEnvironment{tverbatim}{Verbatim}{fontsize=\tiny}
\DefineVerbatimEnvironment{sverbatim}{Verbatim}
                          {fontsize=\small}
% numbered
\DefineVerbatimEnvironment{nverbatim}{Verbatim}
  {fontsize=\small,numbers=left,xleftmargin=\parindent}
\DefineVerbatimEnvironment{continueverbatim}{Verbatim}{fontsize=\small,%
  firstnumber=continue,numbers=left,xleftmargin=\parindent}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example type definitions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newcommand\ExampleType[5]{%
   \@namedef{#1@init}{%
     \def\EX@suffix{#1}%      
     \def\Write@Preamble{#2}%
     \def\Write@Postamble{#3}}%
   \@namedef{#1@init2}{%
     \edef\FancyVerbStartString{#4}%
     \edef\FancyVerbStopString{#5}%
   }}


\ExampleType{ltx}
  {\Write@Preamble@LaTeX}
  {\Write@Ex{\string\end{document}}}
  {\string\ReadyForTheFray}
  {\string\end{document}}


\ExampleType{pic}
  {\Write@Preamble@LaTeX}
  {\Write@Ex{\string\usebox\string\graph}%
   \Write@Ex{\string\end{document}}}
  {\string\ReadyForTheFray}
  {\string\usebox\string\graph}



\ExampleType{m4}
  {\Write@Preamble@LaTeX}
  {\Write@Ex{\string\end{document}}}
  {\string\ReadyForTheFray}
  {\string\end{document}}



\ExampleType{abc}
  {\Write@Ex{X:1}%
   \Write@Ex{T:}}
  {}
  {T:}
  {}


%\ExampleType{mpp}  {} {} {} {}

\ExampleType{mpp}
  {\Write@Ex{\string\verb{\string\hsize=\the\ExampleWidth}}%
   \Write@Ex{\string\verb{}}} 
  {} {\string\verb{}} {}

\ExampleType{ptx}	% plain TeX source
  {} {} {} {}

\ExampleType{inl}            % inline
 {\Write@Preamble@LaTeX} {} {} {}

\ExampleType{mp}
  {\Write@Preamble@MP}
  {\Write@Ex{endfig;}%
   \Write@Ex{end;}%
  }
  {beginfig(1)}
  {endfig;}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\init@extension@code#1#2{%
    \def\index@vals{#2}%
    \sbox\@tempboxa{\index@vals}%
    \ifdim\wd\@tempboxa>0pt\relax\errmessage{index arg problem}\fi
    \expandafter\ifx\csname #1@init\endcsname\relax 
        \errmessage{Example Type #1 unknown}%
    \else
        \csname #1@init\endcsname
%%D        \typeout{Example Type \EX@suffix}%
    \fi
}

\def\init@post@extension@code#1{%
   \csname #1@init2\endcsname
   \ifx\FancyVerbStartString\@empty
       \let\FancyVerbStartString\relax \fi
   \ifx\FancyVerbStopString\@empty
       \let\FancyVerbStopString\relax  \fi
}

\newcommand\ExtendExampleWidth[1]{%
   \addtolength\ExampleWidth{24pt*#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% side by side generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newenvironment{GenExample}[2]
   {\init@extension@code{#1}{#2}%
    \PrepareExampleWidth
    \BeginExample}
 {\EndExample
  \SideBySideEx{\EPSinput{\theEX@ct}}%
               {\EX@dir\EX@prefix\theEX@ct.\EX@suffix}%
 }


% side by side
\newenvironment{genexample}[2]
   {\init@extension@code{#1}{#2}%
%   \def\Write@OneEx##1{}%
    \def\Write@ExOne##1{}%
    \def\Write@Ex##1{}%
    \BeginExample}
   {\EndExample
    \let\FancyVerbStartString\relax 
    \let\FancyVerbStopString\relax
    \SideBySideEx{\EX@input{\EX@dir\theEX@ct.\EX@suffix}}%
                 {\EX@dir\EX@prefix\theEX@ct.\EX@suffix}}





%%%%%%%%%%%%%%%%%%%%%%%%%%%
% on top of each other generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

% first verbatimcode, then actual example
\newenvironment{GenExamplestar}[3][]
  {\init@extension@code{#2}{#3}%
   \def\verb@opts{#1}\BeginExample}
  {\EndExample
   \begin{center}
    \def\baselinestretch{1}%
    \index@vals
    \expandafter\VerbatimInput\expandafter[\verb@opts 
            gobble=0,fontsize=\small]%
      {\EX@dir\EX@prefix\theEX@ct.\EX@suffix}%
    \EPSinput{\theEX@ct}%
   \end{center}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%
% inline on above the other generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

% one above the other
\newenvironment{genexamplestar}[3][]
  {\def\Write@Ex##1{}\def\Write@ExOne##1{}%
   \init@extension@code{#2}{#3}\def\verb@opts{#1}\BeginExample}
  {\EndExample
   \let\FancyVerbStartString\relax 
   \let\FancyVerbStopString\relax
   \index@vals
   \expandafter\VerbatimInput\expandafter[\verb@opts 
                   gobble=0,fontsize=\small]%
      {\EX@dir\theEX@ct.\EX@suffix}%
   \begin{center}%
      \@@WideDisplay{\EX@input{\EX@dir\theEX@ct.\EX@suffix}}%
%
% the line above replaced the following:
%
%      \leavevmode\EX@input{\EX@dir\theEX@ct.\EX@suffix}\par
   \end{center}%
%   \IdentifyExample{-2,1}%
}




%%%%%%%%%%%%%%%%%%%%%%%%%%%
% only results generic
%%%%%%%%%%%%%%%%%%%%%%%%%%%

% no verbatim text at all, just to run the thing separately

\newenvironment{GenEscape}[2]
  {\init@extension@code{#1}{#2}\BeginExample}
  {\EndExample
%
% that will probably *not* work, but the alternative isn't better either
%
   \IdentifyOddExample{-6pt,0}%
%
%  \par\noindent     % i fear that is necessary
%  \@@WideDisplay{%
   \index@vals
   \expandafter\EPSinput\expandafter
                [\EscapeParameters]{\theEX@ct}%
%    }%
  }

\newenvironment{InlineEscape}{\ERRORreplaceInlineEscape
  \GenEscape{ltx}{}}{\endGenEscape}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% special environments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newenvironment{example}[1]   {\genexample{inl}{#1}} {\endgenexample}

\newenvironment{example*}[1] {\genexamplestar{inl}{#1}} {\endgenexamplestar}

\newenvironment{numexample*}[1]{%
    \genexamplestar[numbers=left,xleftmargin=18pt,]{inl}{#1}}
                            {\endgenexamplestar}

\newenvironment{Escape}[1]   {\GenEscape{ltx}{#1}}  {\endGenEscape}
\newenvironment{MPEscape}[1] {\GenEscape{mp}{#1}}   {\endGenEscape}

\newenvironment{Example}[1]  {\GenExample{ltx}{#1}} {\endGenExample}
\newenvironment{ABCExample}[1]{\GenExample{abc}{#1}} {\endGenExample}
\newenvironment{MPExample}[1]{\GenExample{mp}{#1}}  {\endGenExample}

\newenvironment{MPPExample}[1]{\GenExample{mpp}{#1}}  {\endGenExample}


\newenvironment{NExample}[1] {\GenExample%
                 [firstnumber=0,numbers=left,xleftmargin=18pt,]{ltx}{#1}} {\endGenExample}

\newenvironment{NExample*}[1] {\GenExamplestar%
                 [firstnumber=0,numbers=left,xleftmargin=18pt,]{ltx}{#1}} {\endGenExamplestar}

\newenvironment{Example*}[1]  {\GenExamplestar{ltx}{#1}}{\endGenExamplestar}
\newenvironment{MPExample*}[1]{\GenExamplestar{mp}{#1}} {\endGenExamplestar}
\newenvironment{MPExampleSmall*}[1]
         {\GenExamplestar[fontsize=scriptsize]{mp}{#1}} {\endGenExamplestar}

\newenvironment{MPPExample*}[1]{\setlength\ExampleWidth{\textwidth-2pt}%
               \GenExamplestar{mpp}{#1}}{\endGenExamplestar}


\endinput