| 1 |
% \iffalse meta-comment |
| 2 |
% !TeX spellcheck = en-US |
| 3 |
% |
| 4 |
% File: latexdemo.sty |
| 5 |
% Version: 2023/03/26 v0.2 |
| 6 |
% Author: Matthias Pospiech |
| 7 |
% Email: <[email protected]> |
| 8 |
% |
| 9 |
% Copyright (C) 2023 by Matthias Pospiech ([email protected]) |
| 10 |
% --------------------------------------------------------------------------- |
| 11 |
% This work may be distributed and/or modified under the |
| 12 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 13 |
% of this license or (at your option) any later version. |
| 14 |
% The latest version of this license is in |
| 15 |
% http://www.latex-project.org/lppl.txt |
| 16 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 17 |
% version 2005/12/01 or later. |
| 18 |
% |
| 19 |
% This work has the LPPL maintenance status `maintained'. |
| 20 |
% |
| 21 |
% The Current Maintainer of this work is Matthias Pospiech. |
| 22 |
% |
| 23 |
% This work consists of the files latexdemo.dtx and latexdemo.ins |
| 24 |
% and the derived filebase latexdemo.sty. |
| 25 |
% |
| 26 |
% \fi |
| 27 |
% |
| 28 |
% \iffalse |
| 29 |
%<*driver> |
| 30 |
\ProvidesFile{latexdemo.dtx} |
| 31 |
%</driver> |
| 32 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 33 |
%<package>\ProvidesPackage{latexdemo} |
| 34 |
%<*package> |
| 35 |
[2023/03/26 v0.2 typeset code and resulting output] |
| 36 |
%</package> |
| 37 |
% |
| 38 |
%<*driver> |
| 39 |
\documentclass{ltxdoc} |
| 40 |
\usepackage{hypdoc} |
| 41 |
\RequirePackage{latexdemo} |
| 42 |
\usepackage{lmodern} |
| 43 |
%%%% Additional packages |
| 44 |
\usepackage{soulutf8} |
| 45 |
% |
| 46 |
%%% Configures doc.sty and its (outdated) index generation, which does |
| 47 |
% not work together with any modern package and has no hyperref support |
| 48 |
% and thus no links. Furthermore it is conflicts with the index macros |
| 49 |
% of doctools. |
| 50 |
% |
| 51 |
\EnableCrossrefs % (default) Every new macro name used within a macrocode or |
| 52 |
% macrocode∗ environment will produce an index entry. |
| 53 |
% \DisableCrossrefs % turn off this feature |
| 54 |
% |
| 55 |
% If an index is created is determined by the use of the following |
| 56 |
% declarations in the driver file preamble; if neither is used, no index is |
| 57 |
% produced. |
| 58 |
\PageIndex % all index entries refer to their page number |
| 59 |
% \CodelineIndex % index entries produced by \DescribeMacro and \DescribeEnv |
| 60 |
% refer to page number but those produced by the macro |
| 61 |
% environment refer to the code lines, |
| 62 |
% which will be numbered automatically. |
| 63 |
% \CodelineNumbered % no index is created, but the code lines are numbered |
| 64 |
|
| 65 |
\RecordChanges |
| 66 |
|
| 67 |
\listfiles |
| 68 |
|
| 69 |
\begin{document} |
| 70 |
\DocInput{latexdemo.dtx} |
| 71 |
\PrintChanges |
| 72 |
\PrintIndex |
| 73 |
\end{document} |
| 74 |
%</driver> |
| 75 |
% \fi |
| 76 |
% |
| 77 |
% \CheckSum{0} |
| 78 |
% |
| 79 |
% \CharacterTable |
| 80 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 81 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 82 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 83 |
% Exclamation \! Double quote \" Hash (number) \# |
| 84 |
% Dollar \$ Percent \% Ampersand \& |
| 85 |
% Acute accent \' Left paren \( Right paren \) |
| 86 |
% Asterisk \* Plus \+ Comma \, |
| 87 |
% Minus \- Point \. Solidus \/ |
| 88 |
% Colon \: Semicolon \; Less than \< |
| 89 |
% Equals \= Greater than \> Question mark \? |
| 90 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 91 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 92 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 93 |
% Right brace \} Tilde \~} |
| 94 |
% |
| 95 |
% |
| 96 |
% \changes{v0.1}{2012/12/01}{initial version (converted to dtx file)} |
| 97 |
% |
| 98 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 99 |
% |
| 100 |
% \providecommand*{\url}{\texttt} |
| 101 |
% \GetFileInfo{latexdemo.dtx} |
| 102 |
% \title{The \textsf{latexdemo} package} |
| 103 |
% \author{Matthias Pospiech \\ \url{[email protected]}} |
| 104 |
% \date{\fileversion~from \filedate} |
| 105 |
% |
| 106 |
% \maketitle |
| 107 |
% \section{Introduction} |
| 108 |
% In order to demonstrate \latex{} code it is very useful to have the code and |
| 109 |
% the resulting output together in the same document. |
| 110 |
% \package{latexdemo} |
| 111 |
% is a package that provides configurable tools to print out \latex{} code and the |
| 112 |
% resulting output in the same document. |
| 113 |
% |
| 114 |
% The difference to other similar packages is the support of |
| 115 |
% verbatim material inside a conditional sequence and the consequence that each |
| 116 |
% code must be written to an external file. |
| 117 |
% |
| 118 |
% The commands provided by this package are based on the packages |
| 119 |
% \package{listings}, \package{mdframed} and the enviroment \environment{filecontents}. |
| 120 |
% |
| 121 |
% \section{Basic example} |
| 122 |
% \label{sec:example:basic} |
| 123 |
% Below is a principle example, |
| 124 |
% which demonstrates the usage of the package by showing some commands of a |
| 125 |
% package (\package{soul}) with the resulting code side by side: |
| 126 |
% |
| 127 |
% \iffalse |
| 128 |
%<*example> |
| 129 |
% \fi |
| 130 |
\begin{DefineCode} |
| 131 |
\so{letterspacing}, \\ |
| 132 |
\ul{underlining}, \\ |
| 133 |
\st{overstriking} \\ |
| 134 |
and \hl{highlighting}. |
| 135 |
\end{DefineCode} |
| 136 |
% \iffalse |
| 137 |
%</example> |
| 138 |
% \fi |
| 139 |
% |
| 140 |
% \PrintDemo{style=parallel} |
| 141 |
% |
| 142 |
% which is created with the code of this package using \cs{ifcsdef} from etoolbox |
| 143 |
% to test if the code will run through or fail because of unkown commands. |
| 144 |
% |
| 145 |
% \iffalse |
| 146 |
%<*example> |
| 147 |
% \fi |
| 148 |
\begin{lstlisting}[style=demostyle] |
| 149 |
\begin{DefineCode} |
| 150 |
\so{letterspacing}, \\ |
| 151 |
\ul{underlining}, \\ |
| 152 |
\st{overstriking} \\ |
| 153 |
and \hl{highlighting}. |
| 154 |
\end{DefineCode} |
| 155 |
|
| 156 |
\ifcsdef{so}{% |
| 157 |
% |
| 158 |
\PrintDemo{style=parallel} |
| 159 |
% |
| 160 |
}{% |
| 161 |
\DemoError{Command \cs{so} of package% |
| 162 |
\package{soul} not available. |
| 163 |
Probably the package was not loaded. |
| 164 |
} |
| 165 |
}% |
| 166 |
\end{lstlisting} |
| 167 |
% \iffalse |
| 168 |
%</example> |
| 169 |
% \fi |
| 170 |
% |
| 171 |
% \section{Usage} |
| 172 |
% |
| 173 |
% \subsection{Define code} |
| 174 |
% This package requires the example code to be written to an external file. The |
| 175 |
% filename is saved in the command sequence \cs{democodefile}. The output is done |
| 176 |
% with the \environment{DefineCode} environment: |
| 177 |
% |
| 178 |
% \iffalse |
| 179 |
%<*example> |
| 180 |
% \fi |
| 181 |
\begin{lstlisting}[style=demostyle] |
| 182 |
\begin{DefineCode} |
| 183 |
... code ... |
| 184 |
\end{DefineCode} |
| 185 |
\end{lstlisting} |
| 186 |
% \iffalse |
| 187 |
%</example> |
| 188 |
% \fi |
| 189 |
% |
| 190 |
% The requirement for an external file originates from the problem that verbatim |
| 191 |
% content cannot be saved in normal tex macros since the line breaks and white |
| 192 |
% spaces get lost. Furthermore, any solution which would solve this problem would |
| 193 |
% fails finally because saving such contend cannot be included in conditional |
| 194 |
% code statements\footnote{See discussion on: |
| 195 |
% \url{http://tex.stackexchange.com/questions/29256/}}. |
| 196 |
% |
| 197 |
% The content in the file defined by \cs{democodefile} is further read for the |
| 198 |
% printing of the code and the corresponding output. |
| 199 |
% |
| 200 |
% \subsection{Print code and result} |
| 201 |
% |
| 202 |
% \DescribeMacro{\PrintDemo}\arg{style=\meta{option}} \AfterLastParam% |
| 203 |
% This is the macro for the output of code and result. |
| 204 |
% The layout of both is defined with the style option. |
| 205 |
% The following options are possible |
| 206 |
% \begin{Optionlist} |
| 207 |
% \option{parallel} & code and result side by side. \\ |
| 208 |
% \option{stacked} & (default) code and result with 100\,\% text width |
| 209 |
% stacked.\\ |
| 210 |
% \option{lines} & like \texttt{stacked}, but with lines on |
| 211 |
% top and bottom of the result instead of a |
| 212 |
% surrounding box. \\ |
| 213 |
% \option{none} & like \texttt{stacked}, but with nothing around the |
| 214 |
% result. \\ |
| 215 |
% \option{page} & result on a single page.\\ |
| 216 |
% \end{Optionlist} |
| 217 |
% |
| 218 |
% You should use \option{parallel} for small examples and \option{stacked} |
| 219 |
% otherwise. The options \option{lines} and \option{none} is primarily |
| 220 |
% for those cases where a surrounding box is disturbing or impossible. |
| 221 |
% The latter occurs for example in cases where content is written across |
| 222 |
% the text width boundaries. The option \option{page} is obviously for |
| 223 |
% those cases where the output is very large or written to another page anyway. |
| 224 |
% |
| 225 |
% \subsubsection{Examples} |
| 226 |
% The following code is used in the examples |
| 227 |
% \iffalse |
| 228 |
%<*example> |
| 229 |
% \fi |
| 230 |
\begin{lstlisting}[style=demostyle] |
| 231 |
\begin{DefineCode} |
| 232 |
This code shows some basic math: $a^2 + b^2 = c^2$. |
| 233 |
\end{DefineCode} |
| 234 |
\end{lstlisting} |
| 235 |
% |
| 236 |
\begin{DefineCode} |
| 237 |
This code shows some basic math: $a^2 + b^2 = c^2$. |
| 238 |
\end{DefineCode} |
| 239 |
% \iffalse |
| 240 |
%</example> |
| 241 |
% \fi |
| 242 |
% |
| 243 |
% \begin{itemize} |
| 244 |
% \item \cs{PrintDemo}\{style=parallel\} |
| 245 |
% \PrintDemo{style=parallel} |
| 246 |
% |
| 247 |
% \item \cs{PrintDemo}\{style=stacked\} |
| 248 |
% \PrintDemo{style=stacked} |
| 249 |
% |
| 250 |
% \item \cs{PrintDemo}\{style=lines\} |
| 251 |
% \PrintDemo{style=lines} |
| 252 |
% |
| 253 |
% \item \cs{PrintDemo}\{style=none\} |
| 254 |
% \PrintDemo{style=none} |
| 255 |
% \end{itemize} |
| 256 |
% |
| 257 |
% The prefix text for code and result and the filename can be changed. The |
| 258 |
% commands are introduced in section~\ref{sec:setup}. Commands for the output of |
| 259 |
% content such as the name of of a package, a command, an environment or a |
| 260 |
% generalized error message are introduced in section~\ref{sec:commands:output}. |
| 261 |
% |
| 262 |
% \subsection{Setup} |
| 263 |
% \label{sec:setup} |
| 264 |
% |
| 265 |
% The following commands define the name for the temporary file or the strings |
| 266 |
% used for the printing of code or results. Use \cs{renewcommand} to change the |
| 267 |
% definitions. |
| 268 |
% |
| 269 |
% \DescribeMacro{\democodefile}% |
| 270 |
% Filename for the temporary file required for code and results printing. |
| 271 |
% \Default{democode} |
| 272 |
% |
| 273 |
% \DescribeMacro{\democodeprefix}% |
| 274 |
% Prefix text for output of code. |
| 275 |
% \Default{Code: } |
| 276 |
% |
| 277 |
% \DescribeMacro{\demoresultprefix}% |
| 278 |
% Prefix text for output of the result. |
| 279 |
% \Default{Result: } |
| 280 |
% |
| 281 |
% \subsection{Output commands} |
| 282 |
% \label{sec:commands:output} |
| 283 |
% |
| 284 |
% The following commands are provided for the user to print out and format |
| 285 |
% commands, environments, packages and errors. Some are provided by the |
| 286 |
% \package{doctools} package. |
| 287 |
% |
| 288 |
% \DescribeMacro{\command} \marg{cmd} \AfterLastParam |
| 289 |
% Prints out the argument \cs{command}\arg{foo} as \cs{foo}. |
| 290 |
% |
| 291 |
% \DescribeMacro{\cs} \marg{cmd} \AfterLastParam |
| 292 |
% Shortcut for \cs{command}. |
| 293 |
% |
| 294 |
% \DescribeMacro{\arg} \marg{cmd} \AfterLastParam |
| 295 |
% Prints out an argument in curled brackets without the use of |
| 296 |
% angle brackets as in \cs{marg} or \cs{oarg}. |
| 297 |
% Thus prints \cs{arg}\arg{foo} as \arg{foo}. |
| 298 |
% |
| 299 |
% \DescribeMacro{\environment} \marg{environment} \AfterLastParam |
| 300 |
% Prints out an environment name as \environment{environment}. |
| 301 |
% |
| 302 |
% \DescribeMacro{\env} \marg{environment} \AfterLastParam |
| 303 |
% Shortcut for \cs{environment} |
| 304 |
% |
| 305 |
% \DescribeMacro{\package} \marg{package} \AfterLastParam |
| 306 |
% Prints out a package name as \package{package}. |
| 307 |
% |
| 308 |
% \DescribeMacro{\DemoError}% |
| 309 |
% prints out the given error message |
| 310 |
% \Example{\DemoError{foo}} |
| 311 |
% |
| 312 |
% |
| 313 |
% \StopEventually{} |
| 314 |
% |
| 315 |
% \clearpage |
| 316 |
% \section{Implementation} |
| 317 |
% |
| 318 |
% \iffalse |
| 319 |
%<*latexdemo.sty> |
| 320 |
% \fi |
| 321 |
% |
| 322 |
% \begin{macrocode} |
| 323 |
\NeedsTeXFormat{LaTeX2e} |
| 324 |
\ProvidesPackage{latexdemo}[2012/12/01 v0.1 typeset code and resulting output] |
| 325 |
\@ifpackageloaded{hypdoc} |
| 326 |
{\RequirePackage[loadHyperref=true,% |
| 327 |
createIndexEntries=false,% |
| 328 |
applyLayout=false]{doctools}} |
| 329 |
{\@ifpackageloaded{doc} |
| 330 |
{\RequirePackage[loadHyperref=false,% |
| 331 |
createIndexEntries=false,% |
| 332 |
applyLayout=false]{doctools}} |
| 333 |
{}} |
| 334 |
%%% listings (must be loaded before \AtBeginDocument) |
| 335 |
\RequirePackage{listings} |
| 336 |
\PassOptionsToPackage{table}{xcolor} |
| 337 |
% This code needs to be executed at the beginning |
| 338 |
% of the document because some packages (eg. xcolor) |
| 339 |
% could lead to option clashes otherwise |
| 340 |
% |
| 341 |
%% Programming |
| 342 |
\RequirePackage{xspace} |
| 343 |
\RequirePackage{etoolbox} |
| 344 |
%% Packages for frames |
| 345 |
\RequirePackage{mdframed} |
| 346 |
\RequirePackage{framed} |
| 347 |
% |
| 348 |
\AtBeginDocument{% |
| 349 |
% \end{macrocode} |
| 350 |
% \subsection{Preamble} |
| 351 |
% \subsubsection{Packages} |
| 352 |
% |
| 353 |
% \begin{macrocode} |
| 354 |
%% Package for colors |
| 355 |
\RequirePackage{xcolor} |
| 356 |
% |
| 357 |
%% load doctools without hyperref if not loaded and no documentation |
| 358 |
%% package was loaded. |
| 359 |
\@ifpackageloaded{doctools}{} |
| 360 |
{\RequirePackage[loadHyperref=false,% |
| 361 |
createIndexEntries=true,% |
| 362 |
applyLayout=false]{doctools}} |
| 363 |
% \end{macrocode} |
| 364 |
% |
| 365 |
% \subsubsection{Colors} |
| 366 |
% |
| 367 |
% \begin{macrocode} |
| 368 |
%% Colors |
| 369 |
\colorlet{demo@stringcolor}{green!40!black!100} |
| 370 |
\colorlet{demo@commentcolor}{green!50!black!100} |
| 371 |
\colorlet{demo@numbercolor}{white!50!black!100} |
| 372 |
\colorlet{demo@codebackcolor}{white!95!black!100} |
| 373 |
\colorlet{demo@resultbackcolor}{white} |
| 374 |
\definecolor{demo@keywordcolor}{rgb}{0,0.47,0.80} |
| 375 |
\definecolor{demo@rulecolor}{rgb}{0,0.4,0.5} |
| 376 |
\definecolor{demo@code@rulecolor}{rgb}{0.5,0.5,0.5} |
| 377 |
% \end{macrocode} |
| 378 |
% |
| 379 |
% \subsection{Commands} |
| 380 |
% |
| 381 |
% \begin{macrocode} |
| 382 |
%% === Simple Commands =============================== |
| 383 |
% \end{macrocode} |
| 384 |
% |
| 385 |
% \begin{macro}{\democodefile} |
| 386 |
% Saves the filename for temporary file output. |
| 387 |
% \begin{macrocode} |
| 388 |
\newcommand{\democodefile}{democode} |
| 389 |
% \end{macrocode} |
| 390 |
% \end{macro} |
| 391 |
% |
| 392 |
% \begin{macro}{\democodeprefix} |
| 393 |
% Prefix text for code output. |
| 394 |
% \begin{macrocode} |
| 395 |
\newcommand{\democodeprefix}{Code: } |
| 396 |
% \end{macrocode} |
| 397 |
% \end{macro} |
| 398 |
% |
| 399 |
% \begin{macro}{\demoresultprefix} |
| 400 |
% Prefix text for result output. |
| 401 |
% \begin{macrocode} |
| 402 |
\newcommand{\demoresultprefix}{\noindent Result:} |
| 403 |
% \end{macrocode} |
| 404 |
% \end{macro} |
| 405 |
% |
| 406 |
% \begin{macro}{\DemoError} |
| 407 |
% Output and formatting of error messages. |
| 408 |
% \begin{macrocode} |
| 409 |
%% Print Error |
| 410 |
\newcommand{\DemoError}[1]{ |
| 411 |
\ifcsdef{textcolor} |
| 412 |
{\textcolor{red}{Error:~}} |
| 413 |
{Error:~} |
| 414 |
#1 \par\noindent |
| 415 |
} |
| 416 |
% \end{macrocode} |
| 417 |
% \end{macro} |
| 418 |
% |
| 419 |
% \subsection{Define keys} |
| 420 |
% |
| 421 |
% \begin{macrocode} |
| 422 |
%% === Define Keys =================================== |
| 423 |
\RequirePackage{kvoptions-patch} |
| 424 |
\RequirePackage{kvoptions} % options |
| 425 |
\RequirePackage{pdftexcmds} % string comparison |
| 426 |
\SetupKeyvalOptions{family=demo,prefix=demo@} |
| 427 |
% \end{macrocode} |
| 428 |
% Define default option for style key: \emph{stacked} |
| 429 |
% \begin{macrocode} |
| 430 |
\DeclareStringOption[stacked]{style} |
| 431 |
\ProcessKeyvalOptions{demo} |
| 432 |
% \end{macrocode} |
| 433 |
% |
| 434 |
% \begin{macro}{\PrintDemoUsingKeys} |
| 435 |
% Evaluate key and execute corresponding commands |
| 436 |
% \begin{macrocode} |
| 437 |
\newcommand{\PrintDemoUsingKeys}{% |
| 438 |
\ifnum\pdf@strcmp{\demo@style}{parallel}=0% |
| 439 |
\PrintCodeAndResultsParallel% |
| 440 |
\else\ifnum\pdf@strcmp{\demo@style}{stacked}=0% |
| 441 |
\PrintCodeAndResultsStacked% |
| 442 |
\else\ifnum\pdf@strcmp{\demo@style}{lines}=0% |
| 443 |
\PrintCodeAndResultsStackedLines% |
| 444 |
\else\ifnum\pdf@strcmp{\demo@style}{page}=0% |
| 445 |
\PrintCodeAndResultsPage% |
| 446 |
\else\ifnum\pdf@strcmp{\demo@style}{none}=0% |
| 447 |
\PrintCodeAndResultsNone% |
| 448 |
\else% |
| 449 |
\PackageError{latexdemo}{% |
| 450 |
\MessageBreak% |
| 451 |
value >\tplbugs@style< unkown \MessageBreak% |
| 452 |
}{}% |
| 453 |
\fi\fi\fi\fi\fi% |
| 454 |
}% |
| 455 |
% \end{macrocode} |
| 456 |
% \end{macro} |
| 457 |
% |
| 458 |
% \begin{environment}{DefineCode} |
| 459 |
% Define code for demonstration using the enviroment \environment{DefineCode} which is based on the enviroment \environment{filecontents*}. |
| 460 |
% \begin{macrocode} |
| 461 |
\newenvironment{DefineCode}{% |
| 462 |
\csname filecontents*\endcsname[overwrite]{\democodefile}% |
| 463 |
}{% |
| 464 |
\csname endfilecontents*\endcsname% |
| 465 |
} |
| 466 |
% \end{macrocode} |
| 467 |
% \end{environment} |
| 468 |
% |
| 469 |
% \begin{macro}{\PrintDemo} |
| 470 |
% Print code and result using the key-value syntax |
| 471 |
% \begin{macrocode} |
| 472 |
\newcommand{\PrintDemo}[1]{% |
| 473 |
\begingroup |
| 474 |
\setkeys{demo}{#1}% |
| 475 |
\PrintDemoUsingKeys |
| 476 |
\endgroup |
| 477 |
} |
| 478 |
% \end{macrocode} |
| 479 |
% \end{macro} |
| 480 |
% |
| 481 |
% \subsection{listings package style} |
| 482 |
% \begin{macrocode} |
| 483 |
%% === Listings style ================================ |
| 484 |
%% reuses style from doctools |
| 485 |
\lstdefinestyle{demostyle}{ |
| 486 |
,style=lstDemoStyleLaTeXCode% |
| 487 |
,numbers=none% |
| 488 |
} |
| 489 |
\lstloadlanguages{[LaTeX]TeX} |
| 490 |
% \end{macrocode} |
| 491 |
% |
| 492 |
% \subsection{mdframed package style} |
| 493 |
% |
| 494 |
% \begin{macrocode} |
| 495 |
%% === Mdframed style ================================ |
| 496 |
\mdfdefinestyle{DemoStyleFrames}{ |
| 497 |
linecolor=demo@rulecolor,% |
| 498 |
linewidth=0.8pt, |
| 499 |
skipabove=0.5\baselineskip, |
| 500 |
skipbelow=0.5\baselineskip, |
| 501 |
leftmargin =-3.5pt, |
| 502 |
rightmargin=-3.5pt, |
| 503 |
innerleftmargin=3pt, |
| 504 |
innerrightmargin=3pt, |
| 505 |
needspace=3\baselineskip, |
| 506 |
}% |
| 507 |
% \end{macrocode} |
| 508 |
% |
| 509 |
% \subsection{Commands for the formatting} |
| 510 |
% |
| 511 |
% \begin{macro}{\preResultSkip} |
| 512 |
% Default skip at the beginning of a result |
| 513 |
% \begin{macrocode} |
| 514 |
%% === Formating commands ============================ |
| 515 |
\newcommand{\preResultSkip}{}%\vspace*{-0.5\baselineskip} |
| 516 |
% \end{macrocode} |
| 517 |
% \end{macro} |
| 518 |
% |
| 519 |
% |
| 520 |
% \begin{environment}{latexresult} |
| 521 |
% Environment to print the result in a box |
| 522 |
% \begin{macrocode} |
| 523 |
\newenvironment{latexresult}{% |
| 524 |
\demoresultprefix |
| 525 |
\nopagebreak[4] |
| 526 |
\preResultSkip |
| 527 |
\mdframed[% |
| 528 |
style=DemoStyleFrames, |
| 529 |
backgroundcolor=demo@resultbackcolor,% |
| 530 |
usetwoside=false, |
| 531 |
]% |
| 532 |
}{ |
| 533 |
\endmdframed |
| 534 |
\noindent |
| 535 |
} |
| 536 |
% \end{macrocode} |
| 537 |
% \end{environment} |
| 538 |
% |
| 539 |
% |
| 540 |
% \begin{macro}{\resultline} |
| 541 |
%% Single Line for results |
| 542 |
% \begin{macrocode} |
| 543 |
\newcommand{\resultline}{% |
| 544 |
\nopagebreak[4] |
| 545 |
%% Insert single line |
| 546 |
\mdframed[% |
| 547 |
style=DemoStyleFrames, |
| 548 |
skipabove=3pt, |
| 549 |
skipbelow=3pt, |
| 550 |
topline=true,bottomline=false,leftline=false,rightline=false, |
| 551 |
backgroundcolor=white,% |
| 552 |
]\mbox{}\endmdframed |
| 553 |
\nopagebreak[4] |
| 554 |
} |
| 555 |
% \end{macrocode} |
| 556 |
% \end{macro} |
| 557 |
% |
| 558 |
% % \subsection{Low level commands for printing of code and result} |
| 559 |
% |
| 560 |
% \begin{macro}{\printlatexcode} |
| 561 |
% Prints the code using \cs{lstinputlisting} |
| 562 |
% \begin{macrocode} |
| 563 |
%% === Output commands =============================== |
| 564 |
%% Print Code with prefix |
| 565 |
\newcommand{\printlatexcode}[1][\democodefile]{% |
| 566 |
\def\demoInputFile{#1}% |
| 567 |
\IfFileExists{\demoInputFile.tex}{% |
| 568 |
\democodeprefix% |
| 569 |
\lstinputlisting[style=demostyle,nolol=true]{\demoInputFile}}{}% |
| 570 |
}% |
| 571 |
% \end{macrocode} |
| 572 |
% \end{macro} |
| 573 |
% |
| 574 |
% |
| 575 |
% \begin{macro}{\printlatexresult} |
| 576 |
% Prints the result enclosed in the \environment{latexresult} environment. |
| 577 |
% The evaluation of the code is simply achieved by loading the file with |
| 578 |
% \cs{input}. |
| 579 |
% \begin{macrocode} |
| 580 |
%% Print Result with standard box |
| 581 |
\newcommand{\printlatexresult}[1][\democodefile]{% |
| 582 |
\def\demoInputFile{#1}% |
| 583 |
\begin{latexresult}% |
| 584 |
\IfFileExists{\demoInputFile.tex}{\input{\demoInputFile.tex}}{}% |
| 585 |
\end{latexresult}% |
| 586 |
}% |
| 587 |
% \end{macrocode} |
| 588 |
% \end{macro} |
| 589 |
% |
| 590 |
% |
| 591 |
% \begin{macro}{\printlatexresultlines} |
| 592 |
% Like \cs{printlatexresult} but with lines above and below instead of a |
| 593 |
% surrounding box. |
| 594 |
% \begin{macrocode} |
| 595 |
%% Print result with lines |
| 596 |
\newcommand{\printlatexresultlines}{% |
| 597 |
\demoresultprefix |
| 598 |
\nopagebreak[4] \resultline \nopagebreak[4] |
| 599 |
\IfFileExists{\democodefile}{\input{\democodefile}}{}% |
| 600 |
\nopagebreak[4] \resultline \nopagebreak[4] |
| 601 |
}% |
| 602 |
% \end{macrocode} |
| 603 |
% \end{macro} |
| 604 |
% |
| 605 |
% \subsection{Output of code and result} |
| 606 |
% |
| 607 |
% \begin{macro}{\PrintCodeAndResultsParallel} |
| 608 |
% \begin{macrocode} |
| 609 |
%% === Output commands for code and result =========== |
| 610 |
\newcommand{\PrintCodeAndResultsParallel}{% |
| 611 |
\nopagebreak[4] |
| 612 |
\vspace*{0.5em}\par\noindent |
| 613 |
\begin{minipage}[t]{0.48\linewidth} |
| 614 |
\printlatexcode |
| 615 |
\end{minipage} \hfill |
| 616 |
\begin{minipage}[t]{0.48\linewidth} |
| 617 |
\printlatexresult |
| 618 |
\end{minipage} |
| 619 |
\par\noindent |
| 620 |
} |
| 621 |
% \end{macrocode} |
| 622 |
% \end{macro} |
| 623 |
% |
| 624 |
% |
| 625 |
% \begin{macro}{\PrintCodeAndResultsStacked} |
| 626 |
% \begin{macrocode} |
| 627 |
\newcommand{\PrintCodeAndResultsStacked}{% |
| 628 |
\nopagebreak[4] |
| 629 |
\vspace*{0.5em}\par\noindent |
| 630 |
\printlatexcode% |
| 631 |
\printlatexresult% |
| 632 |
\par\noindent |
| 633 |
}% |
| 634 |
% \end{macrocode} |
| 635 |
% \end{macro} |
| 636 |
% |
| 637 |
% |
| 638 |
% \begin{macro}{\PrintCodeAndResultsStackedLines} |
| 639 |
% \begin{macrocode} |
| 640 |
\newcommand{\PrintCodeAndResultsStackedLines}{% |
| 641 |
\nopagebreak[4] |
| 642 |
\vspace*{0.5em}\par\noindent |
| 643 |
\printlatexcode% |
| 644 |
\printlatexresultlines% |
| 645 |
\vspace*{0.5em}\par\noindent |
| 646 |
}% |
| 647 |
% \end{macrocode} |
| 648 |
% \end{macro} |
| 649 |
% |
| 650 |
% |
| 651 |
% \begin{macro}{\PrintCodeAndResultsNone} |
| 652 |
% \begin{macrocode} |
| 653 |
\newcommand{\PrintCodeAndResultsNone}{% |
| 654 |
\nopagebreak[4] |
| 655 |
\vspace*{0.5em}\par\noindent |
| 656 |
\printlatexcode% |
| 657 |
% \end{macrocode} |
| 658 |
% |
| 659 |
% \begin{macrocode} |
| 660 |
\demoresultprefix |
| 661 |
\nopagebreak[4] |
| 662 |
\par\noindent |
| 663 |
\IfFileExists{\democodefile}{\input{\democodefile}}{}% |
| 664 |
% \end{macrocode} |
| 665 |
% |
| 666 |
% \begin{macrocode} |
| 667 |
\vspace*{0.5em}\par\noindent |
| 668 |
}% |
| 669 |
% \end{macrocode} |
| 670 |
% \end{macro} |
| 671 |
% |
| 672 |
% |
| 673 |
% \begin{macro}{\PrintCodeAndResultsPage} |
| 674 |
% \begin{macrocode} |
| 675 |
\newcommand{\PrintCodeAndResultsPage}{% |
| 676 |
\nopagebreak[4] |
| 677 |
\vspace*{0.5em}\par\noindent |
| 678 |
\printlatexcode% |
| 679 |
\demoresultprefix: Shown on the following page. |
| 680 |
\newpage |
| 681 |
\IfFileExists{\democodefile}{\input{\democodefile}}{}% |
| 682 |
\newpage |
| 683 |
}% |
| 684 |
% \end{macrocode} |
| 685 |
% |
| 686 |
% \begin{macrocode} |
| 687 |
} % end of \AtBeginDocument |
| 688 |
% \end{macrocode} |
| 689 |
% \end{macro} |
| 690 |
% |
| 691 |
% |
| 692 |
% \iffalse |
| 693 |
%</latexdemo.sty> |
| 694 |
% \fi |
| 695 |
% |
| 696 |
% \Finale |
| 697 |
\endinput |
| 698 |
|