\def\filedate{1996/09/23}
\ProvidesFile{fancyvrb.rc}[\filedate\space fancyvrb customization
by Sebastian Rahtz]
% 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** - one above other, with frames
%  Example   - Rendered as PS, like original, side by side
%  Example*  - Rendered as PS, one above other
%  Example** - Rendered as PS, one above other, with frames
%  Escape - Rendered as PS, with *no* verbatim text
%  PSTExample   - PSTricks picture, like original, side by side
%  GridPSTExample   - PSTricks (gridded) picture, like original, side by side
% The example environments have the following steps 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 \EXdir directory
% (this needs a trailing / as part of the definition)
%
\RequirePackage{ifthen}
\RequirePackage{graphicx}
\RequirePackage{calc}
\def\ExampleFraction{.5}
\def\CodeFraction{.5}
% variable features
%
\def\EXdir{}
\def\EXprefix{}
\def\EXclass{article}
\def\PreambleCommands{}
\def\EscapeParameters{}
%
\@ifundefined{fullwidth}{\let\fullwidth\textwidth}{}
\@ifundefined{thechapter}{\newcounter{chapter}}{}
%
\newcounter{eps@counter}[section]
\renewcommand\theeps@counter{%
 \arabic{chapter}-\arabic{section}-\arabic{eps@counter}}
\newcounter{side@count}
%\newwrite\exepsfile
%\immediate\openout\exepsfile \EXdir\jobname.expslist\relax

\def\EPSinput{\@ifnextchar[{\@EPSinput}{\@EPSinput[]}}
\def\@EPSinput[#1]#2{%
\IfFileExists{\EXdir\EXprefix#2.eps}%
 {\ifx\\#1\\\else\typeout{Change EPS input to #1}\fi
   \includegraphics[#1]{\EXdir\EXprefix#2.eps}}
 {\underline{\EXdir\EXprefix#2}}%
}


\def\SideBySideEx#1{% 
\bgroup\def\baselinestretch{1}%
\trivlist\item[]%
  \leavevmode
   \global\advance\c@side@count by 1
   \label{\thechapter.\theside@count}%
   \IdentifyExample{-1,0}%
   \ifthenelse{\isodd{\pageref{\thechapter.\theside@count}}}{%
   \makebox[\fullwidth][l]{\@@Display{#1}\hspace{5mm}
    \BVerbatimInput[fontsize=\small]{\EXdir\EXprefix\theeps@counter}}%
      }{%
   \makebox[\fullwidth][r]{\@@Display{#1}\hspace{5mm}
     \BVerbatimInput[fontsize=\small]{\EXdir\EXprefix\theeps@counter}}%
    }%
  \endtrivlist
  \egroup
}
\newsavebox{\@display}
\def\@@Display#1{%
 \savebox{\@display}{%
\begin{minipage}[b]{\CodeFraction\fullwidth}#1\end{minipage}%
}
 \raisebox{\depth}{\usebox{\@display}}%
}

\newcommand{\BeginExample}{%
  \multiply\topsep by 2
  \global\advance\c@eps@counter\@ne
  \edef\@tempa{%
    \write\@auxout{\string
      \newlabel{ex-\theeps@counter}{{\theeps@counter}{\noexpand\the\c@page}}}}
  \@tempa
  \nobreak
  \VerbatimEnvironment
  \catcode`\<=12
  \begin{VerbatimOut}{\EXdir\EXprefix\theeps@counter.tex}%
}
\newcommand{\EndExample}{%
  \end{VerbatimOut}%
}

\def\IdentifyExample#1{%
  %\typeout{Here is example \theeps@counter}%
  \rput[b]{0}(#1){\psframebox[linecolor=gray]{{\small\theeps@counter}}}%
}
\def\EndRuleExample{\vskip 7pt \hrule height 1.5pt\relax}



\def\FVE@VerbatimOut{\Write@Ex{\string\end{document}}%
\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\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@Ex{\string\documentclass{\EXclass}}%
    \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
    \Write@OneEx{\PreambleCommands}%
    \Write@Ex{\string\pagestyle{empty}}%
    \Write@Ex{\EX@extra}%
    \Write@Ex{\string\begin{document}}%
    \let\FV@FontScanPrep\relax
    \FV@Scan}

%
% 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
}

\newif\ifgrid
\gridfalse
%--------------------------------------------------------
% here are the environment definitions
%--------------------------------------------------------
\def\PSTExample(#1,#2)(#3,#4){%
    \def\PictureSize{(#1,#2)(#3,#4)}%
    \def\Write@Ex##1{}%
% \def\Write@OneEx##1{}
    \BeginExample
   }
\def\endPSTExample{%
  \EndExample
  \SideBySideEx{%
    %\ifgrid\vskip 8pt \else\relax\fi
    \expandafter\pspicture\PictureSize
    \ifgrid\usergrid\else\relax\fi
    \input{\EXdir\theeps@counter}%
    \endpspicture
    %\ifgrid\vskip 8pt \fi
 }%
}

\newenvironment{GridPSTExample}{\gridtrue\PSTExample}{\endPSTExample}

\def\PSTInlineExample(#1,#2){%
    \def\PictureSize{(-.2,-.5)(#1,#2)}%
    \def\Write@Ex##1{}%
% \def\Write@OneEx##1{}
    \BeginExample
   }
\def\endPSTInlineExample{%
  \EndExample
  \expandafter\pspicture\PictureSize
  \usergrid
  \input{\EXdir\theeps@counter}%
  \endpspicture
 \hspace{16pt}%
 \BVerbatimInput[gobble=0,fontsize=\small]{\EXdir\theeps@counter}%
}
% side by side
\newenvironment{example}{%
  \def\Write@Ex##1{}%
% \def\Write@OneEx##1{}
    \BeginExample}%
  {\EndExample\SideBySideEx{\input{\EXdir\theeps@counter}}}

% one above the other
\newenvironment{example*}%
  {\def\Write@Ex##1{}\def\Write@Ex##1{}\BeginExample}%
  {%
    \EndExample
    \VerbatimInput[gobble=0,fontsize=\small]{\EXdir\theeps@counter}%
    \IdentifyExample{-1,0}%
      \begin{center}
        \leavevmode\input{\EXdir\theeps@counter}\par
      \end{center}
}
% one above the other, line numbered
\newenvironment{numexample*}%
  {\def\Write@Ex##1{}\def\Write@Ex##1{}\BeginExample}%
  {%
    \EndExample
    \VerbatimInput[gobble=0,numbers=left,
        fontsize=\small]{\EXdir\theeps@counter}%
     \IdentifyExample{-1,0}%
      \begin{center}
        \leavevmode\input{\EXdir\theeps@counter}\par
      \end{center}
}

% with a frame, one above the other
\newenvironment{example**}%
{\def\Write@Ex##1{}\def\Write@Ex##1{}\BeginExample}%
{%
\EndExample
\VerbatimInput[gobble=0,fontsize=\small,
      frame=topline,framerule=1.5pt]{\EXdir\theeps@counter}%
    \IdentifyExample{-1,0}%
\begin{center}
\input{\EXdir\theeps@counter}
        \EndRuleExample
\end{center}
}

% 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 half the normal width.
\def\EX@extra{}
\def\HalfWidth{%
 \def\EX@extra{%
 \string\makeatletter
 \string\@tempdima\string\textwidth
 \string\textwidth\ExampleFraction\string\@tempdima
 \string\addtolength{\string\textwidth}{-6mm}
 \string\makeatother}
}
\def\Setup@Escape{%
 \edef\FancyVerbStopString{\string\end{document}}%
 \edef\FancyVerbStartString{\string\begin{document}}%
}
% side by side
\newenvironment{Example}{%
 \HalfWidth
 \BeginExample} %
 {\EndExample
\Setup@Escape
\SideBySideEx{\EPSinput{\theeps@counter}}}

% first verbatimcode, then actual example
\newenvironment{Example*}{\BeginExample}%
  {\EndExample
  \Setup@Escape
    \IdentifyExample{-1,0}%
  \begin{center}\leavevmode\def\baselinestretch{1}%
    \VerbatimInput[gobble=0,fontsize=\small]{\EXdir\EXprefix\theeps@counter}%
 \EPSinput{\theeps@counter}%
 \end{center}%
}

% one above the other, framed
\newenvironment{Example**}%
{\BeginExample}%
{%
\EndExample
\Setup@Escape
    \IdentifyExample{-1,0}%
    \VerbatimInput[gobble=0,fontsize=\small,
      frame=topline,framerule=1.5pt]{\EXdir\EXprefix\theeps@counter}%
\EPSinput{\theeps@counter}
\EndRuleExample
}

% no verbatim text at all, just to run the thing separately
\newenvironment{Escape}%
{\BeginExample}%
{%
\EndExample
\Setup@Escape
    \IdentifyExample{-1,0}%
\expandafter\EPSinput\expandafter
                [\EscapeParameters]{\theeps@counter}
}
%
% 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]{#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=\normalsize}
%
\DefineVerbatimEnvironment{sssverbatim}{Verbatim}{fontsize=\SixPt}
\DefineVerbatimEnvironment{ssverbatim}{Verbatim}{fontsize=\scriptsize}
\DefineVerbatimEnvironment{fverbatim}{Verbatim}{fontsize=\footnotesize}
\DefineVerbatimEnvironment{sverbatim}{Verbatim}{fontsize=\small}
\DefineVerbatimEnvironment{verbatim}{Verbatim}{fontsize=\normalsize}
% numbered
\DefineVerbatimEnvironment{nverbatim}{Verbatim}{fontsize=\small,numbers=left}
\DefineVerbatimEnvironment{continueverbatim}{Verbatim}{fontsize=\small,
  firstnumber=continue,numbers=left}
\endinput