%% %% This is file `latexdemo.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% latexdemo.dtx (with options: `latexdemo.sty') %% %% IMPORTANT NOTICE: %% %% For the copyright see the source file. %% %% Any modified versions of this file must be renamed %% with new filenames distinct from latexdemo.sty. %% %% For distribution of the original source see the terms %% for copying and modification in the file latexdemo.dtx. %% %% This generated file may be distributed as long as the %% original source files, as listed above, are part of the %% same distribution. (The sources need not necessarily be %% in the same archive or directory.) \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{latexdemo}[2012/12/01 v0.1 typeset code and resulting output] \@ifpackageloaded{hypdoc} {\RequirePackage[loadHyperref=true,% createIndexEntries=false,% applyLayout=false]{doctools}} {\@ifpackageloaded{doc} {\RequirePackage[loadHyperref=false,% createIndexEntries=false,% applyLayout=false]{doctools}} {}} %%% listings (must be loaded before \AtBeginDocument) \RequirePackage{listings} \PassOptionsToPackage{table}{xcolor} %% Programming \RequirePackage{xspace} \RequirePackage{etoolbox} %% Packages for frames \RequirePackage{mdframed} \RequirePackage{framed} \AtBeginDocument{% %% Package for colors \RequirePackage{xcolor} %% load doctools without hyperref if not loaded and no documentation %% package was loaded. \@ifpackageloaded{doctools}{} {\RequirePackage[loadHyperref=false,% createIndexEntries=true,% applyLayout=false]{doctools}} %% Colors \colorlet{demo@stringcolor}{green!40!black!100} \colorlet{demo@commentcolor}{green!50!black!100} \colorlet{demo@numbercolor}{white!50!black!100} \colorlet{demo@codebackcolor}{white!95!black!100} \colorlet{demo@resultbackcolor}{white} \definecolor{demo@keywordcolor}{rgb}{0,0.47,0.80} \definecolor{demo@rulecolor}{rgb}{0,0.4,0.5} \definecolor{demo@code@rulecolor}{rgb}{0.5,0.5,0.5} %% === Simple Commands =============================== \newcommand{\democodefile}{democode} \newcommand{\democodeprefix}{Code: } \newcommand{\demoresultprefix}{\noindent Result:} %% Print Error \newcommand{\DemoError}[1]{ \ifcsdef{textcolor} {\textcolor{red}{Error:~}} {Error:~} #1 \par\noindent } %% === Define Keys =================================== \RequirePackage{kvoptions-patch} \RequirePackage{kvoptions} % options \RequirePackage{pdftexcmds} % string comparison \SetupKeyvalOptions{family=demo,prefix=demo@} \DeclareStringOption[stacked]{style} \ProcessKeyvalOptions{demo} \newcommand{\PrintDemoUsingKeys}{% \ifnum\pdf@strcmp{\demo@style}{parallel}=0% \PrintCodeAndResultsParallel% \else\ifnum\pdf@strcmp{\demo@style}{stacked}=0% \PrintCodeAndResultsStacked% \else\ifnum\pdf@strcmp{\demo@style}{lines}=0% \PrintCodeAndResultsStackedLines% \else\ifnum\pdf@strcmp{\demo@style}{page}=0% \PrintCodeAndResultsPage% \else\ifnum\pdf@strcmp{\demo@style}{none}=0% \PrintCodeAndResultsNone% \else% \PackageError{latexdemo}{% \MessageBreak% value >\tplbugs@style< unkown \MessageBreak% }{}% \fi\fi\fi\fi\fi% }% \newenvironment{DefineCode}{% \csname filecontents*\endcsname[overwrite]{\democodefile}% }{% \csname endfilecontents*\endcsname% } \newcommand{\PrintDemo}[1]{% \begingroup \setkeys{demo}{#1}% \PrintDemoUsingKeys \endgroup } %% === Listings style ================================ %% reuses style from doctools \lstdefinestyle{demostyle}{ ,style=lstDemoStyleLaTeXCode% ,numbers=none% } \lstloadlanguages{[LaTeX]TeX} %% === Mdframed style ================================ \mdfdefinestyle{DemoStyleFrames}{ linecolor=demo@rulecolor,% linewidth=0.8pt, skipabove=0.5\baselineskip, skipbelow=0.5\baselineskip, leftmargin =-3.5pt, rightmargin=-3.5pt, innerleftmargin=3pt, innerrightmargin=3pt, needspace=3\baselineskip, }% %% === Formating commands ============================ \newcommand{\preResultSkip}{}%\vspace*{-0.5\baselineskip} \newenvironment{latexresult}{% \demoresultprefix \nopagebreak[4] \preResultSkip \mdframed[% style=DemoStyleFrames, backgroundcolor=demo@resultbackcolor,% usetwoside=false, ]% }{ \endmdframed \noindent } %% Single Line for results \newcommand{\resultline}{% \nopagebreak[4] %% Insert single line \mdframed[% style=DemoStyleFrames, skipabove=3pt, skipbelow=3pt, topline=true,bottomline=false,leftline=false,rightline=false, backgroundcolor=white,% ]\mbox{}\endmdframed \nopagebreak[4] } %% === Output commands =============================== %% Print Code with prefix \newcommand{\printlatexcode}[1][\democodefile]{% \def\demoInputFile{#1}% \IfFileExists{\demoInputFile.tex}{% \democodeprefix% \lstinputlisting[style=demostyle,nolol=true]{\demoInputFile}}{}% }% %% Print Result with standard box \newcommand{\printlatexresult}[1][\democodefile]{% \def\demoInputFile{#1}% \begin{latexresult}% \IfFileExists{\demoInputFile.tex}{\input{\demoInputFile.tex}}{}% \end{latexresult}% }% %% Print result with lines \newcommand{\printlatexresultlines}{% \demoresultprefix \nopagebreak[4] \resultline \nopagebreak[4] \IfFileExists{\democodefile}{\input{\democodefile}}{}% \nopagebreak[4] \resultline \nopagebreak[4] }% %% === Output commands for code and result =========== \newcommand{\PrintCodeAndResultsParallel}{% \nopagebreak[4] \vspace*{0.5em}\par\noindent \begin{minipage}[t]{0.48\linewidth} \printlatexcode \end{minipage} \hfill \begin{minipage}[t]{0.48\linewidth} \printlatexresult \end{minipage} \par\noindent } \newcommand{\PrintCodeAndResultsStacked}{% \nopagebreak[4] \vspace*{0.5em}\par\noindent \printlatexcode% \printlatexresult% \par\noindent }% \newcommand{\PrintCodeAndResultsStackedLines}{% \nopagebreak[4] \vspace*{0.5em}\par\noindent \printlatexcode% \printlatexresultlines% \vspace*{0.5em}\par\noindent }% \newcommand{\PrintCodeAndResultsNone}{% \nopagebreak[4] \vspace*{0.5em}\par\noindent \printlatexcode% \demoresultprefix \nopagebreak[4] \par\noindent \IfFileExists{\democodefile}{\input{\democodefile}}{}% \vspace*{0.5em}\par\noindent }% \newcommand{\PrintCodeAndResultsPage}{% \nopagebreak[4] \vspace*{0.5em}\par\noindent \printlatexcode% \demoresultprefix: Shown on the following page. \newpage \IfFileExists{\democodefile}{\input{\democodefile}}{}% \newpage }% } % end of \AtBeginDocument \endinput %% %% End of file `latexdemo.sty'.