diff options
author | Karl Berry <karl@freefriends.org> | 2014-06-26 21:40:47 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-06-26 21:40:47 +0000 |
commit | f4e5b3818f612b0d0d9192ef22c1ceaea54f1f48 (patch) | |
tree | 183539be8fb7de01228bae6c08966d3a2e05353c /Master/texmf-dist/tex/latex/latexdemo | |
parent | c0306171dcd01fdff7a9858c8b830da14ea16c9a (diff) |
latexdemo (26jun14)
git-svn-id: svn://tug.org/texlive/trunk@34434 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/latexdemo')
-rw-r--r-- | Master/texmf-dist/tex/latex/latexdemo/latexdemo.sty | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/latexdemo/latexdemo.sty b/Master/texmf-dist/tex/latex/latexdemo/latexdemo.sty new file mode 100644 index 00000000000..fbcb1c3f89a --- /dev/null +++ b/Master/texmf-dist/tex/latex/latexdemo/latexdemo.sty @@ -0,0 +1,222 @@ +%% +%% 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} +%% Write contents to files +\RequirePackage{filecontents} +%% 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% +}% +\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'. |