summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/latexdemo/latexdemo.sty
blob: fbcb1c3f89a6366984744abd721ddd14b838d1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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'.