%%
%% This is file `showexpl.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% showexpl.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2004 by Rolf Niepraschk <Rolf.Niepraschk@ptb.de>
%% 
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.2 of this license
%% or (at your option) any later version.  The latest version of this
%% license is in:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% and version 1.2 or later is part of all distributions of LaTeX version
%% 1999/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{showexpl}
    [2012/09/22 v0.3j Typesetting example code (RN)]
\DeclareOption{final}{%
  \PassOptionsToPackage{\CurrentOption}{graphicx}%
  \PassOptionsToPackage{\CurrentOption}{listings}%
}%
\DeclareOption{draft}{%
  \PassOptionsToPackage{\CurrentOption}{graphicx}%
  \PassOptionsToPackage{\CurrentOption}{listings}%
}%
\DeclareOption{attachfiles}{%
  \AtBeginDocument{\IfFileExists{attachfile.sty}%
    {\RequirePackage{attachfile}}{\def\SX@attachfile{}}}
}%
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{listings}}
\ProcessOptions\relax
\RequirePackage{listings,calc,ifthen,graphicx,varwidth}
\lst@RequireAspects{writefile}
\newcommand*\SX@defaultWD[2]{%
  \afterassignment\SX@def@WD\dimen@#2\linewidth\relax{#1}}
\newcommand*\SX@def@WD{}
\def\SX@def@WD#1\relax#2{\edef#2{\the\dimen@}}
\lst@Key{pos}\relax{\def\SX@pos{#1}}
\lst@Key{width}\relax{\def\SX@width{#1}}
\lst@Key{hsep}\relax{\@tempdima=#1\relax\edef\SX@hsep{\the\@tempdima}}
\lst@Key{vsep}\relax{\@tempdima=#1\relax\edef\SX@vsep{\the\@tempdima}}
\lst@Key{overhang}\relax{\def\SX@overhang{#1}}
\lst@Key{wide}f[t]{\lstKV@SetIf{#1}\if@SX@wide}
\lst@Key{rframe}\relax{\def\SX@rframe{#1}}
\lst@Key{preset}\relax{\def\SX@preset{#1}}
\lst@Key{explpreset}\relax{\def\SX@explpreset{#1}}
\lst@Key{codefile}\relax{\def\SX@codefile{#1}}
\newif\if@SX@rangeaccept \@SX@rangeacceptfalse
\newif\if@SX@varwidth \@SX@varwidthfalse
\newif\if@SX@wide \@SX@widefalse
\newif\if@SX@attachfile \@SX@attachfilefalse
\lst@Key{rangeaccept}f[t]{\lstKV@SetIf{#1}\if@SX@rangeaccept}
\lst@Key{varwidth}f[t]{\lstKV@SetIf{#1}\if@SX@varwidth}
\lst@Key{justification}\relax{\def\SX@justification{#1}}
\lst@Key{attachfile}f[t]{\lstKV@SetIf{#1}\if@SX@attachfile}
\newcommand*\SX@graphicname{}%
\newcommand*\SX@graphicparam{}%
\lst@Key{graphic}{}[]{%
  \lstKV@OptArg[width=\linewidth]{#1}{%
    \edef\SX@graphicparam{##1}\edef\SX@graphicname{##2}%
  }%
}%
\newbox\SX@ResBox
\newcommand*\SX@pos{}
\newcommand*\SX@width{}
\newcommand*\SX@hsep{}
\newcommand*\SX@vsep{}
\newcommand*\SX@overhang{}
\newcommand*\SX@rframe{}
\newcommand\SX@preset{}
\newcommand*\SX@explpreset{}
\newcommand*\SX@@explpreset{}
\newcommand*\SX@codefile{}\edef\SX@codefile{\jobname.tmp}
\newcommand*\SX@justification{\raggedright}
\newcommand*\SX@@preset{%
  \renewcommand\documentclass[2][]{\SX@eat@version}%
  \renewcommand\usepackage[2][]{\SX@eat@version}%
  \renewenvironment{document}{}{}%
  \renewenvironment{figure}[1][]{\def\@captype{figure}}{}%
  \renewenvironment{table}[1][]{\def\@captype{table}}{}%
  \renewcommand\cite[1][]{}%
  \let\tableofcontens\relax \let\listoffigures\relax
  \let\listoftables\relax \let\printindex\relax
  \let\listfiles\relax \let\nofiles\relax
  \let\index\@gobble \let\label\@gobble
  \let\bibliography\@gobble
  \let\pagestyle\@gobble \let\thispagestyle\@gobble
  %%\let\immediate\relax \let\write\@gobbletwo
  %%\let\closeout\@gobble \let\@@input\@gobble
  \renewcommand\marginpar[2][]{}%
  \renewcommand\footnote[2][]{}%
  \let\@footnotetext\@gobble
  %%\abovedisplayskip=\z@
  %%\abovedisplayshortskip=\z@
}
\newcommand*\SX@eat@version[1][]{}
\newif\ifSX@wasodd
\if@twoside
  \newcommand*{\isSX@odd}[2]{%
    \ifthenelse{\isodd{\pageref{\SX@IDENT}}}%
      {\SX@wasoddtrue #1}{\SX@wasoddfalse #2}}
\else
  \newcommand*{\isSX@odd}[2]{#1}\SX@wasoddtrue
\fi
\newcounter{ltxexample}
\newcommand*{\SX@IDENT}{SX@\number\value{ltxexample}}
\newcommand*\SX@attachfile{%
  \if@SX@attachfile
    \attachfile[mimetype=text/plain,subject={example \theltxexample}]%
      {\SX@codefile}{}%
  \fi
}
\newcommand*\SX@put@t[3]{%
  \SX@ResultArea{\linewidth}{#2}\endgraf\pagebreak[2]%
  \setlength\@tempdima{\SX@vsep}\vskip\@tempdima
  \SX@CodeArea{\linewidth}{#3}%
}
\newcommand*\SX@put@b[3]{%
  \SX@CodeArea{\linewidth}{#3}\endgraf\pagebreak[2]%
  \setlength\@tempdima{\SX@vsep}\vskip\@tempdima
  \SX@ResultArea{\linewidth}{#2}%
}
\newcommand*\SX@put@l[3]{%
  \setlength\@tempdimc{\linewidth-#1-\SX@hsep}%
  \SX@ResultArea{#1}{#2}\hfill\SX@CodeArea{\@tempdimc}{#3}%
}
\newcommand*\SX@put@r[3]{%
  \setlength\@tempdimc{\linewidth-#1-\SX@hsep}%
  \SX@CodeArea{\@tempdimc}{#3}\hfill\SX@ResultArea{#1}{#2}%
}
\newcommand*\SX@put@o[3]{%
  \@nameuse{SX@put@\ifSX@wasodd r\else l\fi}{#1}{#2}{#3}%
}
\newcommand*\SX@put@i[3]{%
  \@nameuse{SX@put@\ifSX@wasodd l\else r\fi}{#1}{#2}{#3}%
}
\newcommand\SX@ResultArea[2]{%
  \SX@justification\setlength\@tempdima{#1}%
  %\minipage\@tempdima#2\endminipage
  \parbox\@tempdima{#2}%
}
\newcommand\SX@CodeArea[2]{%
  \setlength\@tempdima{#1}%
  \sbox\@tempboxa{\parbox\@tempdima{#2}}%
  \@tempdima=\dp\@tempboxa\usebox\@tempboxa
  \rlap{\raisebox{-\@tempdima}[0pt][0pt]{\SX@attachfile}}%
}
\newcommand*\SX@KillAboveCaptionskip{%
  \ifx\lst@caption\@empty\else
    \lst@IfSubstring t\lst@captionpos
      {\vskip-\abovecaptionskip}{}%
  \fi
}
\newcommand*\SX@KillBelowCaptionskip{%
  \ifx\lst@caption\@empty\else
    \lst@IfSubstring b\lst@captionpos
      {\vskip-\belowcaptionskip}{}%
  \fi
}
\lstnewenvironment{LTXexample}[1][]
{%
  \@temptokena{#1}%
  \begingroup
    \advance\c@ltxexample\@ne \advance\c@lstlisting\@ne
    \expandafter\lstset\expandafter{\SX@explpreset,#1}%
    \edef\x{\endgroup
      \def\noexpand\SX@codefile{\SX@codefile}%
      \def\noexpand\SX@graphicname{\SX@graphicname}%
      \def\noexpand\SX@graphicparam{\SX@graphicparam}}%
  \x
  \xdef\SX@@explpreset{\the\@temptokena,codefile=\SX@codefile,
    graphic={[\SX@graphicparam]{\SX@graphicname}}}%
  \setbox\@tempboxa=\hbox\bgroup% Warum noetig?
  \lst@BeginWriteFile{\SX@codefile}%
}
{%
  \lst@EndWriteFile\egroup
  \SX@put@code@result
}
\newcommand*\SX@put@code@result{%
  \begingroup
    \expandafter\lstset\expandafter{\SX@explpreset}%
    \let\lst@float=\relax\let\SX@float=\relax
    \expandafter\lstset\expandafter{\SX@@explpreset}%
    \ifx\lst@float\relax\else
      \let\SX@float=\lst@float\let\lst@float=\relax
      \g@addto@macro\SX@@explpreset{,float=false}%
      \edef\@tempa{\noexpand\lst@beginfloat{lstlisting}[\SX@float]}%
      \expandafter\@tempa
    \fi
    \ifx\lst@caption\@empty
      \lstset{nolol=true}%
    \fi
    \if@SX@wide\def\SX@overhang{\marginparwidth+\marginparsep}\fi
    \trivlist\item\relax
      \stepcounter{ltxexample}\label{\SX@IDENT}%
      \SX@defaultWD\SX@width{\SX@width}%
      \ifdim\SX@width<\z@
        \@tempswatrue
        \def\@tempa{t}%
        \ifx\@tempa\SX@pos\@tempswafalse\fi
        \def\@tempa{b}%
        \ifx\@tempa\SX@pos\@tempswafalse\fi
        \setlength\@tempdima{\linewidth+\SX@overhang}%
        \if@tempswa\@tempdima=.5\@tempdima\fi%
        \edef\SX@width{\the\@tempdima}%
      \fi
      \ifx\SX@rframe\@empty
        \long\def\SX@frame##1{##1}%
      \else
        \let\SX@frame\fbox
        \setlength\@tempdima{\SX@width-2\fboxsep-2\fboxrule}%
        \edef\SX@width{\the\@tempdima}%
      \fi
      \isSX@odd{\def\@tempa{l}}{\def\@tempa{r}}%
      \makebox[\linewidth][\@tempa]{%
        \parbox{\linewidth+\SX@overhang}{%
          \let\@addtofilelist\@gobble
          \let\lst@ifdisplaystyle=\iftrue
          \SX@KillAboveCaptionskip\lst@MakeCaption{t}%
          \lst@belowskip=\z@
          \setbox\SX@ResBox\hbox{%
            \SX@frame{%
              \@nameuse{\if@SX@varwidth varwidth\else minipage\fi}%
                  \SX@width\relax
                \begingroup
                  \SX@resultInput
                \endgroup
              \@nameuse{end\if@SX@varwidth varwidth\else minipage\fi}}}%
          \edef\SX@width{\the\wd\SX@ResBox}%
          \@ifundefined{SX@put@\SX@pos}%
            {\@latex@error{Parameter `\SX@pos' undefined}\@ehd}%
          {\@nameuse{SX@put@\SX@pos}%
            {\SX@width}{\box\SX@ResBox}{\SX@codeInput}}%
          \lst@MakeCaption{b}\SX@KillBelowCaptionskip
        }%
      }%
    \endtrivlist
    \ifx\SX@float\relax\else\expandafter\lst@endfloat\fi
    \gdef\SX@@explpreset{}%
  \endgroup
}
\newcommand\SX@SkipToFirst{%
  \ifeof\@inputcheck\else
    \ifnum \lst@lineno=\lst@firstline\else
      \readline\@inputcheck to\SX@tempa
      \typeout{IGNORE (\the\lst@lineno)}%
      \global\advance\lst@lineno\@ne
      \SX@SkipToFirst
    \fi
  \fi
}
\newcommand\SX@ProcessResult{%
  \ifeof\@inputcheck
    \let\SX@tempb\relax
  \else
    \let\SX@tempb\SX@ProcessResult
    \ifnum \lst@lineno>\lst@lastline\relax
      \ifx\lst@linerange\@empty
        \let\SX@tempb\relax
      \else
        \lst@GetLineInterval
        \SX@SkipToFirst
      \fi
    \else
      \readline\@inputcheck to\SX@tempa
      \typeout{READ (\the\lst@lineno)}%
      \expandafter\g@addto@macro
        \expandafter\SX@lines\expandafter{\SX@tempa^^J}%
      \global\advance\lst@lineno\@ne
    \fi
  \fi
  \SX@tempb
}
\newcommand\SX@input[1]{%
  \begingroup
    \IfFileExists{#1}{}%
    {%
      \filename@parse{#1}%
      \ifx\filename@ext\relax \def\filename@ext{tex}\fi
      \@latexerr{File
        `\filename@area\filename@base.\filename@ext' not found.^^J^^J}\@ehd%
    }%
    \openin\@inputcheck#1
    \lsthk@PreSet\let\lst@linerange\@empty\global\lst@lineno\@ne
    \expandafter\lstset\expandafter{\SX@@explpreset}%
    \ifx\lst@linerange\@empty
      \edef\lst@linerange{{\lst@firstline}-{\lst@lastline},}%
    \fi
    \lst@GetLineInterval
    \SX@Info
    \newlinechar=`\^^J\relax
    \SX@SkipToFirst\let\SX@lines\@empty
    \SX@ProcessResult
    \closein\@inputcheck
    \scantokens\expandafter{\SX@lines}%
  \endgroup
}
\newcommand*\SX@Info{%
  \typeout{--------------------------------}%
  \typeout{pos=\SX@pos}%
  \typeout{width=\SX@width}%
  \typeout{hsep=\SX@hsep}%
  \typeout{vsep=\SX@vsep}%
  \typeout{overhang=\SX@overhang}%
  \typeout{rframe=\SX@rframe}%
  \typeout{codefile=\SX@codefile}%
  \@ifundefined{lst@firstline}{}%
    {\typeout{\string\lst@firstline=\lst@firstline}}%
  \@ifundefined{lst@lastline}{}%
    {\typeout{\string\lst@lastline=\lst@lastline}}%
  \@ifundefined{lst@linerange}{}%
    {\typeout{\string\lst@linerange=\lst@linerange}}%
  \typeout{\string\if@SX@wide=\if@SX@wide TRUE\else FALSE\fi}%
  \typeout{\string\if@SX@rangeaccept=\if@SX@rangeaccept TRUE\else FALSE\fi}%
  \typeout{\string\if@SX@varwidth=\if@SX@varwidth TRUE\else FALSE\fi}%
  \typeout{graphicfile=\SX@graphicname, graphicparameter=[\SX@graphicparam]}%
  \typeout{--------------------------------}%
}
\providecommand*\MakePercentIgnore{\catcode`\%9\relax}
\providecommand*\MakePercentComment{\catcode`\%14\relax}
\newcommand*\SX@resultInput{%
  \ifx\SX@graphicname\@empty
    \begingroup
      \MakePercentComment\makeatother\catcode`\^^M=5\relax
      \SX@@preset\SX@preset
      \if@SX@rangeaccept
       \let\SX@tempa=\SX@input
      \else
       \let\SX@tempa=\input
      \fi
      \SX@tempa{\SX@codefile}\par%
    \endgroup
  \else
    \expandafter\includegraphics\expandafter[\SX@graphicparam]%
      {\SX@graphicname}%
  \fi
}
\newcommand*\SX@codeInput{%
  \begingroup
  \expandafter\lstset\expandafter{\SX@explpreset}%
    \expandafter\lstset\expandafter{\SX@@explpreset}%
    \ifx\lst@PlaceNumber\@empty
      \g@addto@macro\SX@@explpreset{,xleftmargin=0pt,xrightmargin=0pt}%
    \fi
    \SX@Info
    \expandafter\lstinputlisting\expandafter%
      [\SX@@explpreset,nolol=true,caption={}]{\SX@codefile}%
  \endgroup
}%
\newcommand*\LTXinputExample[2][]{%
  \g@addto@macro\SX@@explpreset{#1,codefile=#2}%
  \SX@put@code@result}%
\lstset{explpreset={numbers=left,numberstyle=\tiny,numbersep=.3em,
  xleftmargin=1em,columns=flexible,language=[LaTeX]TEX},pos=l,width=-99pt,
  overhang=0pt,hsep=\columnsep,vsep=\bigskipamount,rframe=single}
\InputIfFileExists{showexpl.cfg}{}{}
\endinput
%%
%% End of file `showexpl.sty'.
