%%
%% 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@gmx.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}
    [2021/01/06 v0.3s 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{refcount,listings,graphicx,varwidth,float}
\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}}
\newcommand*\SX@scaled{}
\lst@Key{scaled}{?}[!]{\def\SX@scaled{#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\ResultBox{} \let\ResultBox=\fbox
\newdimen\ResultBoxSep  \ResultBoxSep=\fboxsep
\newdimen\ResultBoxRule \ResultBoxRule=\fboxrule
\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}{}{}%
  \renewcommand\cite[1][]{}%
  \let\tableofcontens\relax \let\listoffigures\relax
  \let\listoftables\relax \let\printindex\relax
  \let\listfiles\relax \let\nofiles\relax
  \let\index\@gobble
  \expandafter\ifx\csname ver@cleveref.sty\endcsname\relax
    \let\refstepcounter=\stepcounter
    \let\label\@gobble
  \else
    \let\cref@old@refstepcounter=\stepcounter
    \let\cref@old@label=\@gobble
  \fi
  \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{%
    \begingroup
      \ifodd\getpagerefnumber{\SX@IDENT}%
        \aftergroup\SX@wasoddtrue
      \else
        \aftergroup\SX@wasoddfalse
      \fi
    \endgroup
    \ifSX@wasodd
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
  }
\else
  \SX@wasoddtrue
  \newcommand*\isSX@odd[2]{#1}
\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]%
  \@tempdima=\dimexpr\SX@vsep\vskip\@tempdima
  \SX@CodeArea{\linewidth}{#3}%
}
\newcommand*\SX@put@b[3]{%
  \SX@CodeArea{\linewidth}{#3}\endgraf\pagebreak[2]%
  \@tempdima=\dimexpr\SX@vsep\vskip\@tempdima
  \SX@ResultArea{\linewidth}{#2}%
}
\newcommand*\SX@put@l[3]{%
  \@tempdimc=\dimexpr\linewidth-#1-\SX@hsep %
  \SX@ResultArea{#1}{#2}\hfill\SX@CodeArea{\@tempdimc}{#3}%
}
\newcommand*\SX@put@r[3]{%
  \@tempdimc=\dimexpr\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\@tempdima=\dimexpr #1 %
  \parbox\@tempdima{#2}%
}
\newcommand\SX@CodeArea[2]{%
  \@tempdima=\dimexpr #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
  \lst@BeginWriteFile{\SX@codefile}%
}
{%
  \lst@EndWriteFile\egroup
  \SX@put@code@result
}
\newcommand*\SX@put@code@result{%
  \begingroup
    \expandafter\lstset\expandafter{\SX@explpreset}%
    \expandafter\lstset\expandafter{\SX@@explpreset}%
    \ifx\lst@float\relax\else
      \edef\@tempa{\noexpand\lst@beginfloat{lstlisting}[\lst@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
        \@tempdima=\dimexpr\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\ResultBox
        \@tempdima=\dimexpr\SX@width-2\ResultBoxSep-2\ResultBoxRule %
        \edef\SX@width{\the\@tempdima}%
      \fi
      \isSX@odd{\def\@tempa{l}}{\def\@tempa{r}}%
      \makebox[\linewidth][\@tempa]{%
        \parbox{\dimexpr\linewidth+\SX@overhang}{%
          \let\@addtofilelist\@gobble
          \let\lst@ifdisplaystyle=\iftrue
          \SX@KillAboveCaptionskip\lst@MakeCaption{t}%
          \setbox\SX@ResBox\hbox{%
            \fboxsep=\ResultBoxSep
            \fboxrule=\ResultBoxRule
            \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\lst@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
      \if\SX@scaled ?%
        \let\SX@tempb=\@firstofone
      \else
        \if\SX@scaled !%
          \def\SX@tempb##1{\resizebox{\SX@width}{!}{##1}}%
        \else
          \def\SX@tempb##1{\scalebox{\SX@scaled}{##1}}%
        \fi
      \fi
      \let\SX@lst@Init=\lst@Init
      \def\@xfloat##1[##2]{%
        \def\@captype{##1}%
        \@namedef{the\@captype}{0}%
        \@float@HH{##1}[H]}%
      \def\lst@Init{%
        \let\lst@float=\relax
        \setcounter\@captype{-1}%
        \SX@lst@Init
      }
      \SX@tempb{\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={},belowskip=\z@,aboveskip=\z@,float=false]{\SX@codefile}%
  \endgroup
}%
\newcommand*\LTXinputExample[2][]{%
  \g@addto@macro\SX@@explpreset{float=false,#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}
\AtBeginDocument{%
  \def\theHlstnumber{\thelstlisting.\arabic{lstnumber}.\lst@neglisting}%
}
\InputIfFileExists{showexpl.cfg}{}{}
\endinput
%%
%% End of file `showexpl.sty'.
