Debian Codegraph @

texmf-dist/source/latex/texpower/texpower.dtx

raw
1 % \iffalse meta-comment
2 % --------------------------------------------------------------
3 % Part of the TeXPower bundle
4 % Copyright (C) 1999-2004 Stephan Lehmke
5 % Copyright (C) 2003-2005 Hans Fredrik Nordhaug
6 %
7 % This program is free software; you can redistribute it and/or
8 % modify it under the terms of the GNU General Public License
9 % as published by the Free Software Foundation; either version 2
10 % of the License, or (at your option) any later version.
11 %
12 % This program is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 % --------------------------------------------------------------
17 %
18 % texpower.dtx,v 1.13 2005/04/09 23:37:36 hansfn Exp
19 %
20 % \fi
21 %
22 % \iffalse
23 %
24 %<*driver>
25 \ProvidesFile{texpower.dtx}
26 %</driver>
27 %<texpower>\NeedsTeXFormat{LaTeX2e}
28 %<texpower>\ProvidesPackage{texpower}
29 %<*texpower>
30 [2005/04/08 v0.2 Create Dynamic Presentations with LaTeX.]
31 %</texpower>
32 %
33 %<*driver>
34 \documentclass{ltxdoc}
35 \EnableCrossrefs
36 \CodelineIndex
37 \RecordChanges
38 \usepackage{longtable}
39 \usepackage[bookmarksopen,colorlinks]{hyperref}
40 \begin{document}
41 \DocInput{texpower.dtx}
42 \end{document}
43 %</driver>
44 %
45 % \fi
46 %
47 % \CheckSum{5957}
48 %
49 % \CharacterTable
50 % {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
51 % 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
52 % Digits \0\1\2\3\4\5\6\7\8\9
53 % Exclamation \! Double quote \" Hash (number) \#
54 % Dollar \$ Percent \% Ampersand \&
55 % Acute accent \' Left paren \( Right paren \)
56 % Asterisk \* Plus \+ Comma \,
57 % Minus \- Point \. Solidus \/
58 % Colon \: Semicolon \; Less than \<
59 % Equals \= Greater than \> Question mark \?
60 % Commercial at \@ Left bracket \[ Backslash \\
61 % Right bracket \] Circumflex \^ Underscore \_
62 % Grave accent \` Left brace \{ Vertical bar \|
63 % Right brace \} Tilde \~}
64 %
65 % \GetFileInfo{texpower.dtx}
66 %
67 % \DoNotIndex{\newcommand,\newenvironment}
68 %
69 % \title{The \textsf{texpower} package\thanks{This document
70 % corresponds to \textsf{texpower}~\fileversion, dated \filedate.}}
71 % \author{ Stephan Lehmke \\ \texttt{[email protected]}}
72 %
73 % \maketitle
74 %
75 % \tableofcontents
76 %
77 % \section{Introduction}
78
79 % LaTeX Package for creating `dynamic' presentations.
80 %
81 % The user documentation is found in \texttt{manual.tex} and the FAQ.
82 % Only the implementation documentation is covered in this document.
83 %
84 % The TeXPower Bundle can be found at |http://texpower.sourceforge.net/|
85 %
86 % \section{Disclaimer}
87 %
88 % This is still work in progress.
89 %
90 % During the subsequent error correction and extension of the
91 % functionality, the syntax and implementation of the macros are
92 % liable to change.
93 %
94 % Even though we are using dtx-files, these are still not fully
95 % documented dtx-files.
96 %
97 % \StopEventually{\PrintChanges\PrintIndex}
98 %
99 % \section{Implementation}
100 %
101 % \changes{v0.0.1}{1999/10/26}{First pre-alpha version.}
102 %
103 % \changes{v0.0.2}{2000/02/15}{Squashing a bug...}
104 %
105 % \changes{v0.0.3}{2000/03/13}{Tidying up command syntax; adding some in-line documentation.}
106 %
107 % \changes{v0.0.4}{2000/03/17}{In-line documentation for the first pre-alpha version completed.}
108 %
109 % \changes{v0.0.5}{2000/03/17}{Fixed some problems with incompatible versions of hyperref (spotted
110 % by Marc van Dongen). (Apr 14: this code no longer exists)}
111 %
112 % \changes{v0.0.6}{2000/03/20}{Added papersize settings. (Mar 28: these are now in fixseminar.sty)}
113 %
114 % \changes{v0.0.7}{2000/04/07}{Removed dependency on hyperref; added support for color emphasis;
115 % respect the display option; now loading tpsettings.cfg and tpoptions.cfg; added \cs{bstep},
116 % \cs{switch}, \cs{rebstep}, \cs{reswitch}.}
117 %
118 % \changes{v0.0.7a}{2000/04/28}{\cs{pause} and \cs{stepwise} now use \cs{leaders} for inserting duplicated
119 % parts of pages. This way, processing of whatsits is turned off in the duplicates so that table of
120 % contents entries are no longer duplicated when a section occurs on a page where \cs{pause} or
121 % \cs{stepwise} is used (spotted by heiner richter). Thanks to Heiko Oberdiek for his suggestion how
122 % \cs{leaders} can be successfully applied for this purpose. \cs{stepwise} now does the right thing if
123 % no \cs{step} command occurs in contents. There was a bug in \cs{save@TP} which would become
124 % apparent if \cs{stepwise} was the first thing on a page. Spotted and fixed by Ross Moore (thanks!).}
125 %
126 % \changes{v0.0.7b}{2000/05/04}{Changed hyperref version check from 2000/03/22 to 2000/03/23.
127 % Spotted by Ross Moore.}
128 %
129 % \changes{v0.0.7c}{2000/05/06}{\cs{eject} changed to \cs{newpage} in \cs{stepwise} to cure some problems
130 % with the foils package. Spotted by Ross Moore.}
131 %
132 % \changes{v0.0.7d}{2000/05/18}{\cs{everydisplay} finally removed from colormath option because it
133 % only causes trouble. Maybe I should look for a less fragile solution for the whole thing. Fixed a
134 % bug in texpower's definition of \cs{set@page@color} (used only if pdftex.def doesn't define it)
135 % which would cause a fatal error if two \cs{pagecolor} commands occur. Added command
136 % \cs{replacecolor}.}
137 %
138 % \changes{v0.0.8}{2000/05/24}{Now providing two methods for creating duplicates of page contents
139 % (used by \cs{pause} and \cs{stepwise}). The former default method using \cs{leaders}, which leads to
140 % problems with footnotes (spotted by Heiner Richter), is now activated by the newly introduced
141 % option robustduplicates. The new default method uses \cs{unvbox} as the \cs{pause} command from
142 % texpause.sty, but redefines \cs{write} for suppressing duplicate toc and bookmark entries due to
143 % duplicated whatsits. Changed the way \cs{liststepwise} and \cs{parstepwise} are implemented. Instead
144 % of wrapping the whole contents in a minipage (which caused a lot of problems), an invisible
145 % \cs{hrule} is inserted in front of contents, which seems to do the job as well. With option
146 % robustduplicates, this seems to be unneccessary for \cs{parstepwise}. Now all counters are saved
147 % before \cs{stepwise} starts and restored for every \cs{step}. This remedies problems with equation
148 % numbers etc. Added a modification for the slides class so that slides are not centered if the
149 % display option is given. Option slifonts now also handles math fonts. Added a \cs{hidetext}
150 % command which respects line breaks (needs soul package).}
151 %
152 % \changes{v0.0.8a}{2000/06/02}{Fixed a bug in the code which disables \cs{pageDuration} if the
153 % pdfpageduration key doesn't exist (spotted by Friedrich Eisenbrand).}
154 %
155 % \changes{v0.0.8b}{2000/06/09}{Added additional `dimmed' and `enhanced' color sets for all standard
156 % colors, with corresponding commands \cs{dimcolors} and \cs{enhancecolors}. Added a `color stack
157 % correction' option fixcolorstack, which should avoid that the duplication of ``color push'' and
158 % ``color pop'' specials confuses the driver's color stack (spotted by Ross Moore). Added new
159 % display commands \cs{hidedimmed}, \cs{hidevanish}, \cs{highlightenhanced}. Added \cs{step} variants
160 % \cs{dstep} and \cs{vstep}. Added patches for \cs{[}, equation, eqnarray, and eqnarray* when the
161 % colormath option is used. Now also saving and restoring footnotes at \cs{pause} and \cs{stepwise}.
162 % Added a command \cs{releasecounter} to keep a counter from `freezing' during the execution of
163 % \cs{stepwise}.}
164 %
165 % \changes{v0.0.8c}{2000/06/13}{The default duplication method will now (only) attack
166 % \cs{protected@write}. There's a new option hackwrite which restores the former default method (of
167 % attacking \cs{write}). Corrected a bug newly introduced into \cs{switch} with version 0.0.8b.
168 % Corrected a bug in the color correction code (spotted by Ross Moore).}
169 %
170 % \changes{v0.0.8d}{2000/06/15}{Corrected a minor quirk in \cs{hidetext}. Added a command
171 % \cs{addTPcolor} for defining new `standard' colors. In printout versions, the last step will no
172 % longer think it's `first activated'.}
173 %
174 % \changes{v0.0.8e}{2000/06/21}{Yet another rewrite of the page duplication code. I hope it's
175 % perfect this time :) The options robustduplicates and hackwrite are obsolete now. Thanks to
176 % Martin Schroeder for permission to use his everyshi code. Fixed a small quirk in \cs{dstep} and
177 % \cs{vstep}. \cs{darkbackground} and relatives now set both page and text color.}
178 %
179 % \changes{v0.0.8f}{2000/06/27}{A small change in the definition of \cs{liststepwise} to enhance
180 % vertical spacing.}
181 %
182 % \changes{v0.0.8g}{2000/07/19}{Color management extended and largely rewritten. A small change to
183 % make page transition and page duration settings local to groups. \cs{dstep} and \cs{vstep} now
184 % understand the usual optional arguments.}
185 %
186 % \changes{v0.0.9}{2000/10/17}{Added support for structured backgrounds (command
187 % \cs{backgroundstyle}). New commands for gradient rules and boxes. Added a hack to keep hyperref
188 % from producing duplicate page anchors (suggested by Thomas Emmel). Some slight changes in the
189 % mode of accounting in \cs{step} to hopefully give better results for `complicated' orders of
190 % activating steps using \cs{step}'s optional arguments. Added (experimental) commands \cs{multistep}
191 % and \cs{movie} for aiding in (simple) animations. \cs{pagecolor} hack removed, as pdftex.def on CTAN
192 % now supports \cs{pagecolor}. \cs{set@color} hack for seminar removed (made unneccessary by
193 % enhancements to powersem). Added rudimentary support for panels. Added rudimentary support for
194 % navigation elements. Now put a hyper anchor ``firstpage.n'' on the first element of the sequence
195 % for page n.}
196 %
197 % \changes{v0.0.9a}{2002/02/01}{Tidying up the inline documentation. When the color package is
198 % loaded before texpower, texpower's color management is no longer activated automatically.
199 % Definitions of standard colors moved to file tpcolors.cfg. Option `slifonts' is obsolete now. The
200 % code is now part of the much more sophisticated package ``tpslifonts''. Now the `colormath'
201 % option cooperates with array.sty (and thus colortbl.sty). New option ``nineminutes'' to
202 % circumvent a strange behaviour of acrobat/acroread v4.05 and later wrt. page duration. Option
203 % `fixcolorstack' now checks also for VTeX. \cs{hidedimmed}, \cs{highlightenhanced} and \cs{dstep} now
204 % check for math mode. Now using ifpdf package if available.}
205 %
206 % \changes{v0.0.9b}{2002/11/13}{colormath adapted to different handling of `equation' by amsmath
207 % 2.x. Adapted for new version of soul package. Added another patch to colormath for handling
208 % array package's ``m'' columns without color change. `Turn on' seminar parameters in panel boxes
209 % even before \cs{begin\{document\}}. Added a command \cs{overlays}, sibling of \cs{multistep}, which
210 % prints all steps over each other. Added a command \cs{steponce}, sibling of \cs{step}, which is
211 % active only for one step. Removed a bug in color correction code introduced in v0.0.8g.}
212 %
213 % \changes{v0.0.9c}{2003/04/29}{A small fix to give \cs{overlays} a width. \cs{mklength} is now a user
214 % command. The \cs{@nobreak} switch and \cs{everypar} are now saved and restored by \cs{stepwise},
215 % hopefully enhancing cooperation with section headings and list environments. Changed
216 % \cs{newcommand} to \cs{providecommand} to allow background.sty to be loaded in parallel (thanks to
217 % Hans Fr. Nordhaug for the original patch).}
218 %
219 % \changes{v0.0.9d}{2003/05/15}{Release.}
220 %
221 % \changes{v0.1}{2003/06/03}{Removed font stuff (now resides in tpslifonts). A small fix to avoid
222 % warnings about extremely overfull hboxes when measuring steps. Our dabbling with \cs{shipout}
223 % created display errors with some packages like pdfscreen. Thanks to Maarten Fokkinga for spotting
224 % it. Fixed.}
225 %
226 % \changes{v0.1a}{2003/06/04}{Color management extended a little to integrate better with LaTeX.
227 % Made \cs{step}-like commands give better error messages when outside \cs{stepwise}.}
228 %
229 % \changes{v0.1b}{2004/07/27}{Moved to dtx format. No other code changes.}
230 %
231 % \changes{v0.2}{2005/04/07}{Fixed bugs \#1029803 and \#1073319 reported at SourceForge.
232 % Made the handling of whatsits smarter (making write to file and hyperref
233 % commands) stepwise-aware. Added option/command to turn on/off the old
234 % aggressive/robust filtering. Added fragilesteps environment.}
235 %
236 % We need the programming tools provided by these packages.
237 % \begin{macrocode}
238 \RequirePackage{ifthen}
239 \RequirePackage{calc}
240 \RequirePackage{keyval}
241 % \end{macrocode}
242 %
243 % \subsection{Options and general setup}
244 %
245 % \subsubsection{General options}
246 %
247 % The option verbose turns on some automatic messages.
248 % \begin{macrocode}
249 \newboolean{verbose@TP}
250 \DeclareOption{verbose}{\setboolean{verbose@TP}{true}}
251 % \end{macrocode}
252 % The (global) option display is respected and turns on the `dynamic' features.
253 % \begin{macrocode}
254 \provideboolean{display}
255 \DeclareOption{display}{\setboolean{display}{true}}
256 % \end{macrocode}
257 % The option printout turns off the `dynamic' features. Can be used to undo a default setting of display.
258 % \begin{macrocode}
259 \DeclareOption{printout}{\setboolean{display}{false}}
260 % \end{macrocode}
261 % The option fixcolorstack switches on a `color stack correction' method which undoes damage to the driver's color stack
262 % when ``color push'' and ``color pop'' specials are duplicated.
263 % \begin{macrocode}
264 \newboolean{fixcolorstack@TP}
265 \DeclareOption{fixcolorstack}{\setboolean{fixcolorstack@TP}{true}}
266 % \end{macrocode}
267 % The option oldfiltering reverts to the old (pre v0.2) aggressive/robust filtering of whatsits.
268 % \begin{macrocode}
269 \newboolean{oldfiltering@TP}
270 \DeclareOption{oldfiltering}{\setboolean{oldfiltering@TP}{true}}
271 \newcommand{\oldfilteringon}{\setboolean{oldfiltering@TP}{true}}
272 \newcommand{\oldfilteringoff}{\setboolean{oldfiltering@TP}{false}}
273 % \end{macrocode}
274 % The option nineminutes sets the page duration of every single page to a high value (of about nine minutes; this seems
275 % to be a hardcoded upper limit in acrobat 5; see below). This way, a setting in acrobat reader's fullscreen dialogue
276 % is masked. Otherwise, pages without an explicit page duration setting don't get any page duration setting at all, so
277 % they will follow the dialogue setting.
278 % \begin{macrocode}
279 \newboolean{nineminutes@TP}
280 \DeclareOption{nineminutes}{\setboolean{nineminutes@TP}{true}}
281 % \end{macrocode}
282 %
283 % \subsubsection{Color options}
284 %
285 % The following switch indicates whether color management should be turned on at all.
286 % \begin{macrocode}
287 \newboolean{TPcolor}
288 % \end{macrocode}
289 % The option coloremph makes |\em| and |\emph| switch the text color instead of the font shape.
290 % \begin{macrocode}
291 \newboolean{coloremph@TP}
292 \DeclareOption{coloremph}
293 {\setboolean{TPcolor}{true}\setboolean{coloremph@TP}{true}}
294 % \end{macrocode}
295 % The option colormath makes math formulae be color highlighted.
296 % \begin{macrocode}
297 \newboolean{colormath@TP}
298 \DeclareOption{colormath}
299 {\setboolean{TPcolor}{true}\setboolean{colormath@TP}{true}}
300 % \end{macrocode}
301 % The option colorhighlight makes highlighting commands use colors.
302 % \begin{macrocode}
303 \newboolean{colorhighlight@TP}
304 \DeclareOption{colorhighlight}
305 {\setboolean{TPcolor}{true}\setboolean{colorhighlight@TP}{true}}
306 % \end{macrocode}
307 % The option whitebackground selects standard colors for white backgrounds.
308 % \begin{macrocode}
309 \newboolean{whitebackground@TP}
310 \setboolean{whitebackground@TP}{true}% This is the default.
311 \DeclareOption{whitebackground}
312 {\setboolean{TPcolor}{true}\setboolean{whitebackground@TP}{true}}
313 % \end{macrocode}
314 % The option lightbackground selects standard colors for light (but not white) backgrounds.
315 % \begin{macrocode}
316 \newboolean{lightbackground@TP}
317 \DeclareOption{lightbackground}
318 {\setboolean{TPcolor}{true}\setboolean{lightbackground@TP}{true}}
319 % \end{macrocode}
320 % The option blackbackground selects standard colors for black backgrounds.
321 % \begin{macrocode}
322 \newboolean{blackbackground@TP}
323 \DeclareOption{blackbackground}
324 {\setboolean{TPcolor}{true}\setboolean{blackbackground@TP}{true}}
325 % \end{macrocode}
326 % The option darkbackground selects standard colors for dark (but not black) backgrounds.
327 % \begin{macrocode}
328 \newboolean{darkbackground@TP}
329 \DeclareOption{darkbackground}
330 {\setboolean{TPcolor}{true}\setboolean{darkbackground@TP}{true}}
331 % \end{macrocode}
332 %
333 % Load the config file with default options if file exists.
334 % \begin{macrocode}
335 \InputIfFileExists{tpoptions.cfg}{}{}
336 % \end{macrocode}
337 %
338 % Process options.
339 % \begin{macrocode}
340 \ProcessOptions
341
342 \ifthenelse{\boolean{display}}
343 {\PackageInfo{texpower}{Producing display version. Dynamic features activated.}}
344 {\PackageInfo{texpower}{Producing printout version. Dynamic features inactive.}}
345 % \end{macrocode}
346 %
347 % General option-driven initialization.
348 %
349 % If the verbose option is set, we give a lot of context information when an error is raised.
350 % \begin{macrocode}
351 \ifthenelse{\boolean{verbose@TP}}{\setcounter{errorcontextlines}{10000}}{}
352 % \end{macrocode}
353 %
354 % Driver-specific defaults.
355 %
356 % We provide a switch which (hopefully) allows to distinguish whether postscript specials (as used by PSTricks) can be
357 % used safely or not.
358 % \begin{macrocode}
359 \newboolean{psspecialsallowed}
360 \setboolean{psspecialsallowed}{true} % optimistic default
361 % \end{macrocode}
362 % The switch |\ifpdf| is to determine whether pdfLaTeX is being run and outputting pdf, using Heiko Oberdiek's faultproof
363 % pdf detector:
364 % \begin{macrocode}
365 \@ifundefined{pdftrue}{
366 \IfFileExists{ifpdf.sty}{\RequirePackage{ifpdf}}{%
367 \expandafter\newif\csname ifpdf\endcsname
368 \ifx\pdfoutput\undefined
369 \else
370 \ifx\pdfoutput\relax
371 \else
372 \ifcase\pdfoutput
373 \else
374 \pdftrue
375 \fi
376 \fi
377 \fi
378 }
379 }{% \ifpdf is defined - nothing to do
380 }
381
382 \ifpdf\setboolean{psspecialsallowed}{false}\fi
383 % \end{macrocode}
384 %
385 % Class-specific defaults.
386 %
387 % The following switches centering of slides off for the slides document class because this would disturb dynamic
388 % building of slides.
389 % \begin{macrocode}
390 \@ifclassloaded{slides}%
391 {%
392 \ifthenelse{\boolean{display}}%
393 {\let\@topfil\relax}%
394 {}%
395 }
396 {}
397 % \end{macrocode}
398 %
399 % Some registers and macros for general use throughout texpower.sty.
400 % \begin{macrocode}
401 \newcounter{tmpcnta@TP}
402 \newcounter{tmpcntb@TP}
403
404 \newlength{\tempdima@TP}
405 \newlength{\tempdimb@TP}
406
407 \newbox\tempbox@TP
408
409 \newboolean{carryon@TP}
410 % \end{macrocode}
411 % These are needed for calculating the size of the page background box.
412 % \begin{macrocode}
413 \newcommand{\TPpagewidth}{\strip@pt\paperwidth truept}
414 \newcommand{\TPpageheight}{\strip@pt\paperheight truept}
415 % \AtBeginDocument
416 % {%
417 % \edef\TPpagewidth{\strip@pt\paperwidth truept}%
418 % \edef\TPpageheight{\strip@pt\paperheight truept}%
419 % }
420 % \end{macrocode}
421 % \begin{macro}{\mkfactor}
422 % |\mkfactor{<cs>}{<exp>}| is a helper command for automatically generating the fixed point numbers between 0 and 1
423 % which are employed by the color calculation commands. |<exp>| can be anything which can stand behind * in calc
424 % (for instance: |\value{counter}/\value{maxcounter}| or |\ratio| or whatever). |<cs>| should be a valid macro name. |<exp>|
425 % is converted into a fixed-point representation which is then assigned to |<cs>|.
426 % \begin{macrocode}
427 \newcommand{\mkfactor}[2]%
428 {\setlength{\tempdima@TP}{1pt*#2}\edef#1{\strip@pt\tempdima@TP}}
429 % \end{macrocode}
430 % \end{macro}
431 % Make a string representation of a length expression.
432 % \begin{macrocode}
433 \newcommand{\mklength@TP}[2]
434 {\setlength{\tempdima@TP}{#2}\edef#1{\the\tempdima@TP}}
435
436 \newcommand{\mklength}{}
437 \let\mklength\mklength@TP
438 % \end{macrocode}
439 %
440 % \subsection{Color management, color emphasis and highlighting}
441 %
442 % Initialization.
443 %
444 % If we are to use colors, we need the color package.
445 % \begin{macrocode}
446 \ifthenelse{\boolean{TPcolor}}{\RequirePackage{color}}{}%
447 % \end{macrocode}
448 %
449 % \subsubsection{Color management kernel}
450 %
451 % Only load the kernel if TeXPower's color management is active.
452 % \begin{macrocode}
453 \ifthenelse{\boolean{TPcolor}}{% Yes.
454 % \end{macrocode}
455 % We need a hook which can be defined otherwise to turn off colors.
456 % \begin{macrocode}
457 \let\setcolor@TP=\color%
458 % \end{macrocode}
459 % Overload |\definecolor| to store a `driver-independent' copy of the color definition for later use by |\colorbetween|
460 % and relatives.
461 % \begin{macrocode}
462 \let\o@definecolor@TP=\definecolor%
463 \def\definecolor#1#2#3%
464 {%
465 \o@definecolor@TP{#1}{#2}{#3}%
466 \expandafter\edef\csname colordef@TP@#1\endcsname%
467 {\csname processcolor@TP@#2\endcsname{#3}}%
468 }%
469 % \end{macrocode}
470 % Repeat color.sty's standard color definitions to make the original definitions available to TeXPower.
471 % Begin excerpt from color.sty:
472 % \begin{macrocode}
473 \@ifundefined{c@lor@namefile}{}{\input{\c@lor@namefile}}
474
475 \ifx\color@gray\@undefined
476 \ifx\color@rgb\@undefined
477 \else
478 \definecolor{black}{rgb}{0,0,0}
479 \definecolor{white}{rgb}{1,1,1}
480 \fi
481 \else
482 \definecolor{black}{gray}{0}
483 \definecolor{white}{gray}{1}
484 \fi
485 \ifx\color@rgb\@undefined\else
486 \definecolor{red}{rgb}{1,0,0}
487 \definecolor{green}{rgb}{0,1,0}
488 \definecolor{blue}{rgb}{0,0,1}
489 \fi
490 \ifx\color@cmyk\@undefined\else
491 \definecolor{cyan}{cmyk}{1,0,0,0}
492 \definecolor{magenta}{cmyk}{0,1,0,0}
493 \definecolor{yellow}{cmyk}{0,0,1,0}
494 \fi
495 % \end{macrocode}
496 % End excerpt from color.sty.
497 %
498 % \subsubsection{Commands for calculating new colors}
499 %
500 % \begin{macro}{\interpolate@TP} Calculates the weighted average between two fixed point values.
501 % \begin{macrocode}
502 \newcommand{\interpolate@TP}[3]%
503 {%
504 \setlength{\tempdima@TP}{1pt-#1pt}% Calculate the second factor for the weighted average.
505 \edef\secondfactor@TP{\strip@pt\tempdima@TP}%
506 \setlength{\tempdima@TP}{#2pt*\real{#1}+#3pt*\real{\secondfactor@TP}}% Calculate the weighted average.
507 \ifthenelse{\lengthtest{\tempdima@TP<0pt}}% Bound the result to the interval [0,1] (just in case the first
508 {\setlength{\tempdima@TP}{0pt}}% factor was not from [0,1]).
509 {\ifthenelse{\lengthtest{\tempdima@TP>1pt}}{\setlength{\tempdima@TP}{1pt}}{}}%
510 \edef\result@TP{\strip@pt\tempdima@TP}%
511 }
512 % \end{macrocode}
513 % \end{macro}
514 % \begin{macro}{\interpolate@three@TP} Interpolates a three-piece color value.
515 % \begin{macrocode}
516 \def\interpolate@three@TP#1,#2,#3;#4,#5,#6;#7%
517 {%
518 \interpolate@TP{#7}{#1}{#4}% First intermediary value.
519 \edef\newcolordef@TP{\result@TP,}% Store first value.
520 \interpolate@TP{#7}{#2}{#5}% Second intermediary value.
521 \edef\newcolordef@TP{\newcolordef@TP\result@TP,}% Store second value.
522 \interpolate@TP{#7}{#3}{#6}% Third intermediary value.
523 \edef\newcolordef@TP{\newcolordef@TP\result@TP}% Store third value.
524 }
525 % \end{macrocode}
526 % \end{macro}
527 % \begin{macro}{\interpolate@four@TP} Interpolates a four-piece color value.
528 % \begin{macrocode}
529 \def\interpolate@four@TP#1,#2,#3,#4;#5,#6,#7,#8;#9%
530 {%
531 \interpolate@TP{#9}{#1}{#5}% First intermediary value.
532 \edef\newcolordef@TP{\result@TP,}% Store first value.
533 \interpolate@TP{#9}{#2}{#6}% Second intermediary value.
534 \edef\newcolordef@TP{\newcolordef@TP\result@TP,}% Store second value.
535 \interpolate@TP{#9}{#3}{#7}% Third intermediary value.
536 \edef\newcolordef@TP{\newcolordef@TP\result@TP,}% Store third value.
537 \interpolate@TP{#9}{#4}{#8}% Fourth intermediary value.
538 \edef\newcolordef@TP{\newcolordef@TP\result@TP}% Store fourth value.
539 }
540 % \end{macrocode}
541 % \end{macro}
542 % \begin{macro}{\convert@cmykvalue@rgbvalue@TP} Converts one color value from CMYK to rgb.
543 % \begin{macrocode}
544 \def\convert@cmykvalue@rgbvalue@TP#1#2%
545 {%
546 \setlength{\tempdima@TP}{1pt-#1pt-#2pt}%
547 \ifthenelse{\lengthtest{\tempdima@TP<0pt}}{\setlength{\tempdima@TP}{0pt}}{}%
548 \edef\result@TP{\strip@pt\tempdima@TP}%
549 }%
550 % \end{macrocode}
551 % \end{macro}
552 % \begin{macro}{\convert@cmyk@rgb@TP} Converts CMYK color to rgb.
553 % \begin{macrocode}
554 \def\convert@cmyk@rgb@TP#1,#2,#3,#4;%
555 {%
556 \convert@cmykvalue@rgbvalue@TP{#1}{#4}%
557 \edef\newcolordef@TP{\result@TP,}% Store first value.
558 \convert@cmykvalue@rgbvalue@TP{#2}{#4}%
559 \edef\newcolordef@TP{\newcolordef@TP\result@TP,}% Store second value.
560 \convert@cmykvalue@rgbvalue@TP{#3}{#4}%
561 \edef\newcolordef@TP{\newcolordef@TP\result@TP}% Store third value.
562 }
563 % \end{macrocode}
564 % \end{macro}
565 % \begin{macro}{\convert@RGBvalue@rgbvalue@TP} Converts one color value from RGB to rgb.
566 % \begin{macrocode}
567 \def\convert@RGBvalue@rgbvalue@TP#1%
568 {%
569 \setlength{\tempdima@TP}{#1pt/255}%
570 \edef\result@TP{\strip@pt\tempdima@TP}%
571 }%
572 % \end{macrocode}
573 % \end{macro}
574 % \begin{macro}{\convert@RGB@rgb@TP} Converts RGB color to rgb.
575 % \begin{macrocode}
576 \def\convert@RGB@rgb@TP#1,#2,#3;%
577 {%
578 \convert@RGBvalue@rgbvalue@TP{#1}%
579 \edef\newcolordef@TP{\result@TP,}% Store first value.
580 \convert@RGBvalue@rgbvalue@TP{#2}%
581 \edef\newcolordef@TP{\newcolordef@TP\result@TP,}% Store second value.
582 \convert@RGBvalue@rgbvalue@TP{#3}%
583 \edef\newcolordef@TP{\newcolordef@TP\result@TP}% Store third value.
584 }
585 % \end{macrocode}
586 % \end{macro}
587 % |\colorbetween[<factor>]{<target>}{<source1>}{<source2>}| calculates a `weighted average' between
588 % two colors. |<source1>| and |<source2>| are the names of the two colors. |<factor>| (default: 0.5)
589 % is a fixed-point number between 0 and 1 giving the `weight' for the interpolation between
590 % |<source1>| and |<source2>|. |<target>| is the name to be given to the resulting mixed color. If
591 % |<factor>| is 1, then |<target>| will be identical to |<source1>| (up to color model conversions,
592 % see below), if |<factor>| is 0, then |<target>| will be identical to |<source2>|, if |<factor>| is
593 % 0.5, then |<target>| will be exactly in the middle between |<source1>| and |<source2>|.
594 %
595 % |\colorbetween| supports the following color models: rgb, RGB, gray, cmyk, hsb. If both colors are
596 % of the same model, the resulting color is also of the respective model. If |<source1>| and
597 % |<source2>| are from \texttt{different} models, then |<target>| will \texttt{always} be an rgb
598 % color. The only exception is the hsb color model: As I don't know how to convert hsb to rgb,
599 % mixing hsb with another color model will always raise an error.
600 % \begin{macrocode}
601 \newcommand{\colorbetween}[4][.5]%
602 {%
603 \begingroup% Make the definition of \processcolor... local.
604 \newcommand{\processcolor@TP@rgb}[3]% What if the first color is an rgb color?
605 {%
606 \ifx##2\processcolor@TP@rgb% Are both colors rgb colors?
607 \interpolate@three@TP##1;##3;{#1}% Calculate interpolated values.
608 \else
609 \ifx##2\processcolor@TP@gray% Is the second color from the gray model?
610 \interpolate@three@TP##1;##3,##3,##3;{#1}% Calculate interpolated values.
611 \else
612 \ifx##2\processcolor@TP@cmyk% Is the second color from the cmyk model?
613 \convert@cmyk@rgb@TP##3;% Convert to rgb.
614 \edef\newcolordef@TP{\noexpand\interpolate@three@TP##1;\newcolordef@TP;{#1}}%
615 \newcolordef@TP
616 \else
617 \ifx##2\processcolor@TP@RGB% Is the second color from the RGB model?
618 \convert@RGB@rgb@TP##3;% Convert to rgb.
619 \edef\newcolordef@TP{\noexpand\interpolate@three@TP##1;\newcolordef@TP;{#1}}%
620 \newcolordef@TP
621 \else
622 \ifx##2\processcolor@TP@hsb% Is the second color from the hsb model?
623 \PackageError{texpower}{Don't know how to convert an hsb color!}
624 \fi
625 \fi
626 \fi
627 \fi
628 \fi
629 \edef\newcolordef@TP{{rgb}{\newcolordef@TP}}% Store the result
630 }%
631 \newcommand{\processcolor@TP@gray}[3]% What if the first color is a gray color?
632 {%
633 \ifx##2\processcolor@TP@gray% Are both colors gray colors?
634 \interpolate@TP{#1}{##1}{##3}% Calculate interpolated value.
635 \edef\newcolordef@TP{{gray}{\result@TP}}% Store the result
636 \else
637 \processcolor@TP@rgb{##1,##1,##1}{##2}{##3}% Otherwise, convert first color to rgb and continue.
638 \fi
639 }%
640 \newcommand{\processcolor@TP@cmyk}[3]% What if the first color is a cmyk color?
641 {%
642 \ifx##2\processcolor@TP@cmyk% Are both colors cmyk colors?
643 \interpolate@four@TP##1;##3;{#1}% Calculate interpolated values.
644 \edef\newcolordef@TP{{cmyk}{\newcolordef@TP}}% Store the result
645 \else
646 \convert@cmyk@rgb@TP##1;% Otherwise, convert first color to rgb ...
647 \expandafter\processcolor@TP@rgb\expandafter{\newcolordef@TP}{##2}{##3}% ... and continue.
648 \fi
649 }%
650 \newcommand{\processcolor@TP@RGB}[3]% What if the first color is an RGB color?
651 {%
652 \convert@RGB@rgb@TP##1;% Convert to rgb ...
653 \expandafter\processcolor@TP@rgb\expandafter{\newcolordef@TP}{##2}{##3}% ... and continue.
654 }%
655 \newcommand{\processcolor@TP@hsb}[3]% What if the first color is an hsb color?
656 {%
657 \ifx##2\processcolor@TP@hsb% Are both colors hsb colors?
658 \interpolate@three@TP##1;##3;{#1}% Calculate interpolated values.
659 \edef\newcolordef@TP{{hsb}{\newcolordef@TP}}% Store the result
660 \else
661 \PackageError{texpower}{Don't know how to convert an hsb color!}
662 \fi
663 }%
664 \expandafter\let\expandafter
665 \firstcol@TP\csname colordef@TP@#3\endcsname % Retrieve definition of color <source1>...
666 \expandafter\expandafter\expandafter\firstcol@TP% and apply (remember \processcolor... is part of the definition)
667 \csname colordef@TP@#4\endcsname% to definition of color <source2>.
668 \edef\end@TP% Define color <target> (outside the enclosing group).
669 {\endgroup\noexpand\definecolor{#2}\newcolordef@TP}%
670 \end@TP
671 }% matches \newcommand{\colorbetween}
672 % \end{macrocode}
673 % \begin{macro}{\complement@TP} Calculates the complement of a fixed point value.
674 % \begin{macrocode}
675 \newcommand{\complement@TP}[1]%
676 {%
677 \setlength{\tempdima@TP}{1pt-#1pt}%
678 \edef\result@TP{\strip@pt\tempdima@TP}%
679 }
680 % \end{macrocode}
681 % \end{macro}
682 % \begin{macro}{\complement@three@TP} Complements a three-piece color value.
683 % \begin{macrocode}
684 \def\complement@three@TP#1,#2,#3;%
685 {%
686 \complement@TP{#1}%
687 \edef\newcolordef@TP{\result@TP,}% Store first value.
688 \complement@TP{#2}%
689 \edef\newcolordef@TP{\newcolordef@TP\result@TP,}% Store second value.
690 \complement@TP{#3}%
691 \edef\newcolordef@TP{\newcolordef@TP\result@TP}% Store third value.
692 }
693 % \end{macrocode}
694 % \end{macro}
695 % \begin{macro}{\grabfourth@TP} Separates the fourth element of a four-piece color value from the rest.
696 % \begin{macrocode}
697 \def\grabfourth@TP#1,#2,#3,#4;%
698 {%
699 \def\mem@TP{#4}% Store fourth element.
700 \def\result@TP{#1,#2,#3;}% Store first three elements.
701 }
702 % \end{macrocode}
703 % \end{macro}
704 % \begin{macro}{\complementcolor}
705 % |\complementcolor{<target>}{<source>}| calculates the numerical complement of a color. |<source>| is the name of the
706 % color to be complemented. |<target>| is the name to be given to the resulting color.
707 % |\complementcolor| supports the following color models: rgb, RGB, gray, cmyk, hsb.
708 % \begin{macrocode}
709 \newcommand{\complementcolor}[2]%
710 {%
711 \begingroup% Make the definition of \processcolor... local.
712 \newcommand{\processcolor@TP@rgb}[1]% What if the color is an rgb color?
713 {%
714 \complement@three@TP##1;% Calculate complemented values.
715 \edef\newcolordef@TP{{rgb}{\newcolordef@TP}}% Store the result
716 }%
717 \newcommand{\processcolor@TP@gray}[1]% What if the color is a gray color?
718 {%
719 \complement@TP{##1}% Calculate complemented value.
720 \edef\newcolordef@TP{{gray}{\result@TP}}% Store the result
721 }%
722 \newcommand{\processcolor@TP@cmyk}[1]% What if the color is a cmyk color?
723 {%
724 \grabfourth@TP##1;% Remember fourth element.
725 \expandafter\complement@three@TP\result@TP% Calculate complemented values of first three elements.
726 \edef\newcolordef@TP{{cmyk}{\newcolordef@TP,\mem@TP}}% Store the result, putting back the fourth element.
727 }%
728 \newcommand{\processcolor@TP@RGB}[1]% What if the color is an RGB color?
729 {%
730 \convert@RGB@rgb@TP##1;% Convert to rgb ...
731 \expandafter\processcolor@TP@rgb\expandafter{\newcolordef@TP}% ... and continue.
732 }%
733 \newcommand{\processcolor@TP@hsb}[1]% What if the color is an hsb color?
734 {%
735 \complement@three@TP##1;% Calculate complemented values.
736 \edef\newcolordef@TP{{hsb}{\newcolordef@TP}}% Store the result
737 }%
738 \csname colordef@TP@#2\endcsname% Execute definition of color <source> (which contains \processcolor...)
739 \edef\end@TP% Define color <target> (outside the enclosing group).
740 {\endgroup\noexpand\definecolor{#1}\newcolordef@TP}%
741 \end@TP
742 }% matches \newcommand{\complementcolor}
743 }% matches \ifthenelse{\boolean{TPcolor}}{% Yes.
744 {% No. Do nothing.
745 }
746 % \end{macrocode}
747 % \end{macro}
748 %
749 % \subsection{Color name and color set management}
750 %
751 % \begin{macro}{\replacecolor}
752 % |\replacecolor[<tset>]{<tcol>}[<sset>]{<scol>}| will make |<tcol>| have the same definition as |<scol>| (if |<scol>| is
753 % defined at all), where <tcol> and <scol> are color names as given in the first argument of |\definecolor|. If (one
754 % of) |<tset>| and |<sset>| are given, the colors will be taken from the respective color sets.
755 % \begin{macrocode}
756 \newcommand{\replacecolor}
757 {%
758 \let\replacecolor@hook@TP=\@gobble% This hook can be used for variant checking (see below).
759 \replacecolor@TP% Pick up arguments.
760 }
761
762 \newcommand{\replacecolor@TP}[2][]% Pick up the first two arguments of \replacecolor.
763 {%
764 \ifthenelse{\equal{#1}{}}{\edef\tcolname@TP{#2}}{\edef\tcolname@TP{#2@#1}}% Construct `real' target color name.
765 \@replacecolor@TP% Read second argument.
766 }%
767 % \end{macrocode}
768 % \end{macro}
769 % \begin{macrocode}
770 \ifthenelse{\boolean{TPcolor}}% Only if TeXPower's color management is active.
771 {% Yes.
772 \newcommand{\undefinecolor@TP}[1]% Make a color undefined.
773 {\expandafter\let\csname\string\color @#1\endcsname=\@undefined}%
774
775
776 \newcommand{\ifcolorexists@TP}[3]% Conditional for testing whether a color is defined.
777 {\@ifundefined{\string\color @#1}{#3}{#2}}% Test whether a given color is defined.
778
779
780 \newcommand{\@replacecolor@TP}[2][]% Second part of \replacecolor.
781 {%
782 \ifthenelse{\equal{#1}{}}{\edef\scolname@TP{#2}}{\edef\scolname@TP{#2@#1}}% Construct `real' source color name.
783 \ifcolorexists@TP{\scolname@TP}% Does the source color exist at all?
784 {% Yes.
785 \replacecolor@hook@TP{\tcolname@TP}% Execute hook.
786 \expandafter\let\csname\string\color @\tcolname@TP\expandafter\endcsname% Make value of target color
787 \csname\string\color @\scolname@TP\endcsname% identical with source color.
788 \expandafter\let\csname colordef@TP@\tcolname@TP\expandafter\endcsname% Make definition of target color
789 \csname colordef@TP@\scolname@TP\endcsname% identical with source color.
790 }%
791 {% No. Do nothing.
792 }%
793 }%
794 % \end{macrocode}
795 %
796 % The set of TeXPower's `standard colors' and some commands to manipulate them.
797 %
798 % \begin{macro}{\colors@TP} |\colors@TP| is the list of all standard colors defined by texpower.
799 % The list is empty initially.
800 % \begin{macrocode}
801 \newcommand{\colors@TP}{}
802 % \end{macrocode}
803 % \end{macro}
804 % \begin{macro}{\removecolor@TP} Removes a color name from the list.
805 % \begin{macrocode}
806 \newcommand{\removecolor@TP}[1]%
807 {%
808 \def\processme@TP##1% This macro does the real work.
809 {%
810 \ifthenelse{\equal{#1}{##1}}% Is this the color to be removed?
811 {% Yes. Do nothing, so it vanishes.
812 }
813 {% No. Re-insert.
814 \expandafter\def\expandafter\colors@TP\expandafter{\colors@TP\processme@TP{##1}}%
815 }%
816 }%
817 \expandafter\let\expandafter\colors@TP\expandafter\empty% Initialize \colors@TP.
818 \colors@TP% Execute \processme@TP for every color on the list.
819 }
820 % \end{macrocode}
821 % \end{macro}
822 % \begin{macro}{\addTPcolor}
823 % |\addTPcolor{<color>}| adds the color named |<color>| to TeXPower's list of standard colors.
824 % \begin{macrocode}
825 \newcommand{\addTPcolor}[1]%
826 {%
827 \removecolor@TP{#1}% Remove this color from the list (to avoid duplicates).
828 \expandafter\def\expandafter\colors@TP\expandafter{\colors@TP\processme@TP{#1}}% ... and insert.
829 \register@normalvariant@TP{#1}% Register the normal variant for this color.
830 }
831 % \end{macrocode}
832 % \end{macro}
833 % \begin{macro}{\defineTPcolor}
834 % |\defineTPcolor[<set>]{<name>}{<model>}{<def>}| acts like\\ |\definecolor{<name>}{<model>}{<def>}|, but
835 % \begin{enumerate}
836 % \item color |<name>| is automatically added to the list of standard colors and
837 % \item if the optional parameter is given, the color is defined in the color set |<set>| instead of
838 % the current color set.
839 % \end{enumerate}
840 % \begin{macrocode}
841 \newcommand{\defineTPcolor}[4][]
842 {%
843 \addTPcolor{#2}% Add color to the list.
844 \ifthenelse{\equal{#1}{}}% Color from the current color set?
845 {\definecolor{#2}{#3}{#4}}% Yep. Just define the color.
846 {\definecolor{#2@#1}{#3}{#4}}% No. Add color set identifyer.
847 }
848 % \end{macrocode}
849 % \end{macro}
850 %
851 % Some commands for manipluating whole color sets.
852 %
853 % \begin{macro}{\replacecolors@TP} Low level command for replacing a complete color set.
854 % \begin{macrocode}
855 \newcommand{\replacecolors@TP}%
856 {%
857 \@ifstar% The starred version will put the color set into normal variant.
858 {\let\replacecolor@hook@TP=\register@normalvariant@TP\@replacecolors@TP}
859 {\let\replacecolor@hook@TP=\@gobble\@replacecolors@TP}%
860 }
861
862 \newcommand{\@replacecolors@TP}[4]% This part does the real work.
863 {%
864 \def\processme@TP##1{\replacecolor@TP[#1]{#2##1}[#3]{#4##1}}%
865 \colors@TP
866 }
867 % \end{macrocode}
868 % \end{macro}
869 % \begin{macro}{\usecolorset}
870 % |\usecolorset{<set>}| switches to color set |<set>|.
871 % \begin{macrocode}
872 \newcommand{\usecolorset}[1]%
873 {%
874 \replacecolors@TP*{}{}{#1}{}% Replace normal variant (registering variants).
875 \replacecolors@TP{}{d}{#1}{d}% Replace dimmed variant.
876 \replacecolors@TP{}{e}{#1}{e}% Replace enhanced variant.
877 \color{textcolor}% Activate textcolor.
878 \pagecolor{pagecolor}% Activate pagecolor.
879 }%
880 % \end{macrocode}
881 % \end{macro}
882 % \begin{macro}{\dumpcolorset}
883 % |\dumpcolorset{<set>}| saves all standard colors from the current color set to the color set |<set>|.
884 % \begin{macrocode}
885 \newcommand{\dumpcolorset}[1]%
886 {%
887 \nonnormalwarnings@TP{Dumping color set #1}% Output a warning for every color not in the normal variant.
888 \replacecolors@TP{#1}{}{}{}% Dump normal variant (hopefully).
889 \replacecolors@TP{#1}{d}{}{d}% Dump dimmed variant.
890 \replacecolors@TP{#1}{e}{}{e}% Dump enhanced variant.
891 }%
892 % \end{macrocode}
893 % \end{macro}
894 % Commands for color variants.
895 % \begin{macrocode}
896 \newcommand{\registervariant@TP}[2]% Remember which variant a color is currently in.
897 {\expandafter\def\csname cvar@#1@TP\endcsname{#2}}
898
899 \newcommand{\register@normalvariant@TP}[1]% Register that a color is now in the normal variant.
900 {\registervariant@TP{#1}{}}
901
902 \newcommand{\currentvariant@TP}[1]% Return the current variant of a color.
903 {\csname cvar@#1@TP\endcsname}
904
905 \newcommand{\ifnormalvariant@TP}[3]% Conditional for checking whether a color is in the normal variant.
906 {\ifthenelse{\equal{\currentvariant@TP{#1}}{}}{#2}{#3}}
907
908 \newcommand{\nonnormalwarnings@TP}[1]% Checks the current variant for every standard color and gives a warning
909 {% if it's not the normal one.
910 \def\processme@TP##1%
911 {%
912 \ifnormalvariant@TP{##1}{}
913 {%
914 \PackageWarning{texpower}
915 {#1\MessageBreak when color ##1 is in \currentvariant@TP{##1} variant}%
916 }%
917 }%
918 \colors@TP
919 }
920 % \end{macrocode}
921 % Default dim level for automatic color dimming.
922 % \begin{macrocode}
923 \newcommand{\dimlevel}{.7}
924 % \end{macrocode}
925 % |\dimcolor[<level>]{<color>}| dims the color named |<color>|. It checks whether an explicit `dimmed' variant d<color>
926 % exists. If yes, |<color>| is replaced by |d<color>|. Otherwise, the dimmed color is calculated by interpolating between
927 % pagecolor and |<color>|. The parameter for |\colorbetween| is given by the optional argument |<level>| (default:
928 % |\dimlevel|).
929 % \begin{macrocode}
930 \newcommand{\dimcolor}[2][\dimlevel]
931 {%
932 \ifnormalvariant@TP{#2}% Color in the normal variant?
933 {% Yes.
934 \registervariant@TP{#2}{d}% Register dimmed variant.
935 \ifcolorexists@TP{d#2}% Dedicated dimmed color found?
936 {\replacecolor{#2}{d#2}}% Yes. use that one.
937 {\colorbetween[#1]{#2}{pagecolor}{#2}}% No. Dim numerically using \colorbetween.
938 }%
939 {}% No. Do nothing.
940 }
941 % \end{macrocode}
942 % |\dimcolors[<level>]| dims all standard colors using |\dimcolor|. See the description of |\dimcolor| for details.
943 % \begin{macrocode}
944 \newcommand{\dimcolors}[1][\dimlevel]
945 {%
946 \def\processme@TP##1{\dimcolor[#1]{##1}}%
947 \colors@TP
948 }%
949 % \end{macrocode}
950 % Default enhance level for automatic color enhancing.
951 % \begin{macrocode}
952 \newcommand{\enhancelevel}{.5}
953 % \end{macrocode}
954 % |\enhancecolor[<level>]{<color>}| enhances the color named |<color>|. It checks whether an explicit `enhanced' variant
955 % |e<color>| exists. If yes, |<color>| is replaced by |e<color>|. Otherwise, the enhanced color is calculated by
956 % `extrapolating' from pagecolor and |<color>|. The parameter for |\colorbetween| is given by the optional argument
957 % |<level>| (default: |\enhancelevel|).
958 % \begin{macrocode}
959 \newcommand{\enhancecolor}[2][\enhancelevel]
960 {%
961 \ifnormalvariant@TP{#2}% Color in the normal variant?
962 {%
963 \registervariant@TP{#2}{e}% Register enhanced variant.
964 \ifcolorexists@TP{e#2}% Dedicated enhanced color found?
965 {\replacecolor{#2}{e#2}}% Yes. use that one.
966 {\colorbetween[-#1]{#2}{pagecolor}{#2}}% No. Enhance numerically using \colorbetween.
967 }%
968 {}%
969 }%
970 % \end{macrocode}
971 % |\enhancecolors[<level>]| enhances all standard colors using |\enhancecolor|. See the description of |\enhancecolor| for
972 % details.
973 % \begin{macrocode}
974 \newcommand{\enhancecolors}[1][\enhancelevel]
975 {%
976 \def\processme@TP##1{\enhancecolor[#1]{##1}}%
977 \colors@TP
978 }%
979 % \end{macrocode}
980 % Replace all colors from the current color set by a single color.
981 % \begin{macrocode}
982 \newcommand{\replacecolorsbyone@TP}[2]%
983 {%
984 \def\processme@TP##1{\replacecolor{#1##1}{#2}}%
985 \colors@TP
986 }
987 % \end{macrocode}
988 % The color used to make things `vanish'.
989 % \begin{macrocode}
990 \newcommand{\vanishcolor}{pagecolor}
991 % \end{macrocode}
992 % |\vanishcolors| replaces all standard colors by |\vanishcolor|.
993 % \begin{macrocode}
994 \newcommand{\vanishcolors}[1][\vanishcolor]{\replacecolorsbyone@TP{}{#1}}
995 % \end{macrocode}
996 % TeXPower's predefined color sets and commands to activate them. Redefine in tpcolors.cfg as convenient.
997 % \begin{macrocode}
998 \input{tpcolors.cfg}
999 % \end{macrocode}
1000 % |\whitebackground| sets the standard colors up for white background.
1001 % \begin{macrocode}
1002 \newcommand{\whitebackground}%
1003 {%
1004 \usecolorset{whitebg}%
1005 }
1006 % \end{macrocode}
1007 % When the whitebackground option (or no background option, but some other color-activating option like colormath) is
1008 % given, |\whitebackground| is executed automatically (at the end of the package to ensure that texpower.cfg was read).
1009 % \begin{macrocode}
1010 \ifthenelse{\boolean{whitebackground@TP}}
1011 {\AtEndOfPackage{\whitebackground}}
1012 {}
1013 % \end{macrocode}
1014 % |\lightbackground| sets the standard colors up for `light' background.
1015 % \begin{macrocode}
1016 \newcommand{\lightbackground}%
1017 {%
1018 \usecolorset{lightbg}%
1019 }
1020 % \end{macrocode}
1021 % When the lightbackground option is given, |\lightbackground| is executed automatically.
1022 % \begin{macrocode}
1023 \ifthenelse{\boolean{lightbackground@TP}}{\AtEndOfPackage{\lightbackground}}{}
1024 % \end{macrocode}
1025 % |\darkbackground| sets the standard colors up for `dark' background.
1026 % \begin{macrocode}
1027 \newcommand{\darkbackground}%
1028 {%
1029 \usecolorset{darkbg}%
1030 }
1031 % \end{macrocode}
1032 % Execute |\darkbackground| automatically if the darkbackground option was given.
1033 % \begin{macrocode}
1034 \ifthenelse{\boolean{darkbackground@TP}}{\AtEndOfPackage{\darkbackground}}{}
1035 % \end{macrocode}
1036 % |\blackbackground| sets the standard colors up for black background.
1037 % \begin{macrocode}
1038 \newcommand{\blackbackground}%
1039 {%
1040 \usecolorset{blackbg}%
1041 }
1042 % \end{macrocode}
1043 % Execute |\blackbackground| automatically if the blackbackground option was given.
1044 % \begin{macrocode}
1045 \ifthenelse{\boolean{blackbackground@TP}}{\AtEndOfPackage{\blackbackground}}{}
1046 % \end{macrocode}
1047 % If TeXPower's color management is active, setup LaTeX color management to use the dedicated colors.
1048 % \begin{macrocode}
1049 \ifthenelse{\boolean{TPcolor}}
1050 {%
1051 \renewcommand{\normalcolor}{\color{textcolor}}% \normalcolor should produce textcolor.
1052
1053 \let\o@textnormal@TP=\textnormal% \textnormal should also set text color.
1054 \def\textnormal#1{\o@textnormal@TP{\normalcolor#1}}
1055 % \end{macrocode}
1056 % Make sure current color is correct for the rest of the preamble.
1057 % \begin{macrocode}
1058 \AtEndOfPackage{\color{textcolor}\let\default@color\current@color}
1059 % \end{macrocode}
1060 % The following is deferred to the beginning of the document to allow redefinitions of colors and loading of
1061 % packages. We set page and text color and make amsmath's |\text| command switch to text color.
1062 % \begin{macrocode}
1063 \AtBeginDocument%
1064 {%
1065 \pagecolor{pagecolor}\color{textcolor}%
1066 \@ifpackageloaded{amstext}%
1067 {%
1068 \let\o@text@TP=\text%
1069 \def\text#1{\o@text@TP{\normalcolor\expandafter\everymath\expandafter{\the\everymath\color{mathcolor}}#1}}%
1070 }%
1071 {}%
1072 }%
1073 }
1074 {}
1075 % \end{macrocode}
1076 % If TeXPower's color management is active, set page and text color at the beginning of the document.
1077 % \begin{macrocode}
1078 \ifthenelse{\boolean{TPcolor}}{\AtBeginDocument{\pagecolor{pagecolor}\color{textcolor}}}{}
1079 }% matches \ifthenelse{\boolean{TPcolor}}{% Yes.
1080 {% No; provide dummies.
1081 \let\setcolor@TP=\@gobble%
1082 \newcommand{\@replacecolor@TP}[2][]{}%
1083 \let\addTPcolor=\@gobble
1084 \newcommand{\defineTPcolor}[4][]{}%
1085 \let\usecolorset=\@gobble
1086 \let\dumpcolorset=\@gobble
1087 \newcommand{\dimcolor}[2][]{}
1088 \newcommand{\dimcolors}[1][]{}
1089 \newcommand{\enhancecolor}[2][]{}
1090 \newcommand{\enhancecolors}[1][]{}
1091 \newcommand{\vanishcolors}[1][]{}
1092 }
1093 % \end{macrocode}
1094 %
1095 % \subsubsection{Implementation of the coloremph option}
1096 % \begin{macrocode}
1097 \ifthenelse{\boolean{coloremph@TP}}% Should \emph use color?
1098 {% Yes;
1099 \DeclareRobustCommand{\em}% Redefine \em.
1100 {%
1101 \@nomath\em \color{emcolor}% Change color.
1102 \replacecolor{tmp@TP}{emcolor}% Exchange emcolor and altemcolor.
1103 \replacecolor{emcolor}{altemcolor}%
1104 \replacecolor{altemcolor}{tmp@TP}%
1105 }%
1106 }%
1107 {}% No; keep original definition.
1108 % \end{macrocode}
1109 %
1110 % \subsubsection{Implementation of the colormath option}
1111 %
1112 % Note that the following code is quite fragile and contains some modifications of LaTeX internals. Thus it is likely to
1113 % cause trouble, especially in conjunction with other packages modifying the LaTeX kernel. The array package is
1114 % supported, but no explicit support of other packages exists. If you experience strange and inexplicable errors while
1115 % the colormath option is active, first of all try switching it off to see whether anything changes.
1116 % The implementation of colormath is likely to change several times before the first beta release, so expect backward
1117 % incompatible changes in behaviour.
1118 % \begin{macrocode}
1119 \ifthenelse{\boolean{colormath@TP}}% Should we color math?
1120 {% Yes.
1121 \AtBeginDocument
1122 {%
1123 % \end{macrocode}
1124 % The most basic magical incantation: Color inline math using |\everymath|. Beware of side effects of this hack.
1125 % \begin{macrocode}
1126 \expandafter\everymath\expandafter{\the\everymath\color{mathcolor}}%
1127 % \end{macrocode}
1128 % Color displayed math by overloading LaTeX's own math environments. Note that this doesn't work for the TeX
1129 % notation \$\$, which is deprecated in LaTeX anyway.
1130 % Note further that for the eqnarray and eqnarray* environments, the current implementation places the color change
1131 % command \textbf{outside} the math environment (for technical reasons; maybe this can be remedied by a more sophisticated
1132 % implementation), which will almost invariably lead to unwanted extra vertical space before and after equation
1133 % arrays. Currently there is no clean remedy, apart from using amsmath's align environment.
1134 % \begin{macrocode}
1135 \let\o@dm@TP=\[% Save the original definitions of begin and end macros for
1136 \let\o@enddm@TP=\]% LaTeX's displayed math environments.
1137 \let\o@eqa@TP=\eqnarray%
1138 \let\o@endeqa@TP=\endeqnarray%
1139 \expandafter\let\expandafter\o@eqastar@TP\csname eqnarray*\endcsname%
1140 \expandafter\let\expandafter\o@endeqastar@TP\csname endeqnarray*\endcsname%
1141 \def\[{\o@dm@TP\begingroup\color{mathcolor}}% Redefine the begin and end macros for LaTeX's displayed math
1142 \def\]{\endgroup\o@enddm@TP}% environments, adding the color change commands and an extra
1143 \def\eqnarray{\begingroup\color{mathcolor}\o@eqa@TP}% level of grouping.
1144 \def\endeqnarray{\o@endeqa@TP\endgroup\@ignoretrue}%
1145 \@namedef{eqnarray*}{\begingroup\color{mathcolor}\o@eqastar@TP}
1146 \@namedef{endeqnarray*}{\o@endeqastar@TP\endgroup\@ignoretrue}
1147 \@ifpackageloaded{amsmath}% Amsmath's displayed math environments are covered by the
1148 {% \everymath hack because they are `fake' displayed equations.
1149 \@ifpackagelater{amsmath}{2000/01/15}% As amsmath 1.x redefines the equation environment to be a
1150 {% variant of gather, treating it as a displayed math
1151 \let\o@eq@TP=\equation% environment would lead to problems, so this redefinition is
1152 \let\o@endeq@TP=\endequation% made only if amsmath 1.x is not loaded.
1153 \def\equation{\o@eq@TP\begingroup\color{mathcolor}}%
1154 \def\endequation{\endgroup\everymath{}\o@endeq@TP}%
1155 }%
1156 {}%
1157 }%
1158 {%
1159 \let\o@eq@TP=\equation%
1160 \let\o@endeq@TP=\endequation%
1161 \def\equation{\o@eq@TP\begingroup\color{mathcolor}}%
1162 \def\endequation{\endgroup\everymath{}\o@endeq@TP}%
1163 }%
1164 }% matches \AtBeginDocument{
1165 % \end{macrocode}
1166 % Sometimes, a math environment is used for something other than displaying math. The macro |\origmath| will put its
1167 % argument in math mode, but turn off coloring. If another math environemt should be nested inside the argument of
1168 % |\origmath|, it will be coloured.
1169 % \begin{macrocode}
1170 \newcommand{\origmath}[1]{{\everymath{}\ensuremath{\everymath{\color{mathcolor}}#1}}}%
1171 % \end{macrocode}
1172 % We need to redefine some LaTeX macros which internally use math mode, to make sure that not all tabulars and
1173 % parboxes are coloured. Note that this can break packages which mess with tabular themselves.
1174 % \begin{macrocode}
1175 \renewcommand*\labelitemi{\origmath{\m@th\bullet}}%
1176 \@ifpackageloaded{array}% The array package redefines \@tabular
1177 {%
1178 \def\@tabular{%
1179 \leavevmode
1180 \hbox \bgroup \everymath{}$\everymath{\color{mathcolor}}\col@sep\tabcolsep \let\d@llarbegin\begingroup % $
1181 \let\d@llarend\endgroup
1182 \@tabarray
1183 }%
1184 \@ifpackageloaded{colortbl}
1185 {%
1186 \def\@classz{\@classx
1187 \@tempcnta \count@
1188 \prepnext@tok
1189 \expandafter\CT@extract\the\toks\@tempcnta\columncolor!\@nil
1190 \@addtopreamble{%
1191 \setbox\z@\hbox\bgroup\bgroup
1192 \ifcase \@chnum
1193 \hskip\stretch{.5}\kern\z@
1194 \d@llarbegin
1195 \insert@column
1196 \d@llarend\hskip\stretch{.5}\or
1197 \d@llarbegin \insert@column \d@llarend \hfill \or
1198 \hfill\kern\z@ \d@llarbegin \insert@column \d@llarend \or
1199 \@startvcenter
1200 \@startpbox{\@nextchar}\insert@column \@endpbox $\or % $
1201 \vtop \@startpbox{\@nextchar}\insert@column \@endpbox \or
1202 \vbox \@startpbox{\@nextchar}\insert@column \@endpbox
1203 \fi
1204 \egroup\egroup
1205 \begingroup
1206 \CT@setup
1207 \CT@column@color
1208 \CT@row@color
1209 \CT@do@color
1210 \endgroup
1211 \@tempdima\ht\z@
1212 \advance\@tempdima\minrowclearance
1213 \vrule\@height\@tempdima\@width\z@
1214 \unhbox\z@}%
1215 \prepnext@tok}%
1216 }
1217 {%
1218 \def\@classz{\@classx
1219 \@tempcnta \count@
1220 \prepnext@tok
1221 \@addtopreamble{\ifcase \@chnum
1222 \hfil
1223 \d@llarbegin
1224 \insert@column
1225 \d@llarend \hfil \or
1226 \hskip1sp\d@llarbegin \insert@column \d@llarend \hfil \or
1227 \hfil\hskip1sp\d@llarbegin \insert@column \d@llarend \or
1228 \@startvcenter
1229 \@startpbox{\@nextchar}\insert@column \@endpbox $\or % $
1230 \vtop \@startpbox{\@nextchar}\insert@column \@endpbox \or
1231 \vbox \@startpbox{\@nextchar}\insert@column \@endpbox
1232 \fi}\prepnext@tok}%
1233 }
1234 \DeclareRobustCommand\@startvcenter{\everymath{}$\everymath{\color{mathcolor}}\vcenter}% $
1235 \expandafter\def\expandafter\@mkpream\expandafter#\expandafter1%
1236 \expandafter{%
1237 \expandafter\let\expandafter\@startvbox\expandafter\relax
1238 \@mkpream{#1}}
1239 }
1240 {%
1241 \def\@tabular{\leavevmode \hbox \bgroup \everymath{}$\everymath{\color{mathcolor}}\let\@acol\@tabacol
1242 \let\@classz\@tabclassz
1243 \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray% $
1244 }%
1245 }
1246 \long\def\@iiiparbox#1#2[#3]#4#5{%
1247 \leavevmode
1248 \@pboxswfalse
1249 \setlength\@tempdima{#4}%
1250 \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}%
1251 \ifx\@empty#2\else\ifx\relax#2\else
1252 \setlength\@tempdimb{#2}%
1253 \def\@parboxto{to\@tempdimb}%
1254 \fi\fi
1255 \if#1b\vbox
1256 \else\if #1t\vtop
1257 \else\ifmmode\vcenter
1258 \else\@pboxswtrue \everymath{}$\everymath{\color{mathcolor}}\vcenter
1259 \fi\fi\fi
1260 \@parboxto{\let\hss\vss\let\unhbox\unvbox
1261 \csname bm@#3\endcsname}%
1262 \if@pboxsw \m@th$\fi
1263 \@end@tempboxa}
1264 \let\o@textsuperscript@TP=\textsuperscript
1265 \def\textsuperscript#1{{\everymath{}\o@textsuperscript@TP{\everymath{\color{mathcolor}}#1}}}%
1266 }% matches \ifthenelse{\boolean{colormath@TP}}{% Yes.
1267 {% No; keep original definition.
1268 \let\origmath=\ensuremath% \origmath needs to have a sensible definition.
1269 }
1270 % \end{macrocode}
1271 %
1272 % New highlighting and emphasis commands. Most of them have a sensible alternative definition if the colorhighlight
1273 % option is not given.
1274 %
1275 % |\code{<text>}| will display <text> in a `code-like' style (for shell commands or macro names).
1276 % |\codeswitch| switches to the style used by |\code|, for use e.g. in verbatim environments.
1277 % \begin{macrocode}
1278 \ifthenelse{\boolean{colorhighlight@TP}}% Color highlighting enabled?
1279 {% Yes; code is displayed typewriter-style, bold and in a special color.
1280 \DeclareRobustCommand{\code}[1]{\textcolor{codecolor}{\textbf{\texttt{#1}}}}%
1281 \DeclareRobustCommand{\codeswitch}{\color{codecolor}\bfseries\ttfamily}%
1282 }
1283 {% No; code is displayed just in typewriter-style and bold.
1284 \DeclareRobustCommand{\code}[1]{\textbf{\texttt{#1}}}%
1285 \DeclareRobustCommand{\codeswitch}{\bfseries\ttfamily}%
1286 }
1287 % \end{macrocode}
1288 % \begin{macro}{\macroname}
1289 % |\macroname{<text>}| acts like |\code|, but adds a backslash in front.
1290 % \begin{macrocode}
1291 \newcommand{\macroname}[1]{\code{\textbackslash#1}}
1292 % \end{macrocode}
1293 % \end{macro}
1294 %
1295 % \begin{macro}{\commandapp}
1296 % |\commandapp[<opt>]{<name>}{<arg>}| displays a macro with an argument. |<name>| is the macro name, |<opt>| is an optional
1297 % argument, <arg> is the macro argument. Note that only one pair of braces is added for |<arg>|; for several arguments,
1298 % |\}\{| needs to be used inside |<arg>| to separate arguments.
1299 % \begin{macrocode}
1300 \newcommand{\commandapp}[3][]{\code{\macroname{#2}\ifthenelse{\equal{#1}{}}{}{[#1]}\{#3\}}}
1301 % \end{macrocode}
1302 % \end{macro}
1303 %
1304 % \begin{macro}{\carg}
1305 % |\carg{<text>}| displays a `symbolic argument', i.e. |<text>| in code style enclosed in pointy braces.
1306 % \begin{macrocode}
1307 \newcommand{\carg}[1]{\code{\origmath{\left<\code{#1}\right>}}}
1308 % \end{macrocode}
1309 % \end{macro}
1310 %
1311 % \begin{macro}{\underl}
1312 % |\underl{<text>}| emphasises |<text>| using a special color if the colorhighlight option is given and by boldfacing
1313 % otherwise.
1314 % \begin{macrocode}
1315 \ifthenelse{\boolean{colorhighlight@TP}}% Color highlighting enabled?
1316 {% Yes;
1317 \DeclareRobustCommand{\underl}{\textcolor{underlcolor}}% Use color to highlight.
1318 }
1319 {% No;
1320 \DeclareRobustCommand{\underl}{\textbf}% Use bold face.
1321 }
1322 % \end{macrocode}
1323 % \end{macro}
1324 %
1325 % \begin{macro}{\concept}
1326 % |\concept{<text>}| emphasises |<text>| using a special color if the colorhighlight option is given and by boldfacing
1327 % otherwise. To be used for emphasizing names of (new) concepts.
1328 % \begin{macrocode}
1329 \ifthenelse{\boolean{colorhighlight@TP}}% Color highlighting enabled?
1330 {% Yes;
1331 \DeclareRobustCommand{\concept}{\textcolor{conceptcolor}}% Use color to highlight.
1332 }
1333 {% No;
1334 \DeclareRobustCommand{\concept}{\textbf}% Use bold face.
1335 }
1336 % \end{macrocode}
1337 % \end{macro}
1338 %
1339 % \begin{macro}{\inactive}
1340 % |\inactive{<text>}| emphasises |<text>| using a special color if the colorhighlight option is given. Nothing is done if
1341 % the option is not given. To be used for `de-emphasizing' things not currently of interest.
1342 % \begin{macrocode}
1343 \ifthenelse{\boolean{colorhighlight@TP}}% Color highlighting enabled?
1344 {% Yes;
1345 \DeclareRobustCommand{\inactive}{\textcolor{inactivecolor}}% Use color to highlight.
1346 }
1347 {% No;
1348 \DeclareRobustCommand{\inactive}{\monochromeinactive}% Use monochrome default.
1349 }
1350
1351 \providecommand{\monochromeinactive}{}% What should \inactive do if colors can't be used? We provide a hook for
1352 % user definitions.
1353 % \end{macrocode}
1354 % \end{macro}
1355 %
1356 % \begin{macro}{\present}
1357 % |\present[<opt>]{<text>}| puts its argument into an |\fbox| with coloured background.
1358 % If |<opt>| is given, it is added to the left of the box without taking any space, i.e. it will overlap text to the left
1359 % of the box. This addition is useful mainly for adding `constraints' to things presented in a description or center
1360 % environment.
1361 % \begin{macrocode}
1362 \ifthenelse{\boolean{colorhighlight@TP}}% Color highlighting enabled?
1363 {% Yes; use a colored box.
1364 \newcommand{\present}[2][]{\leavevmode\llap{\textbf{\footnotesize#1}\,}\fcolorbox{textcolor}{presentcolor}{#2}}%
1365 \newcommand{\mkpbox@TP}[1]{\fcolorbox{presentcolor}{presentcolor}{#1}}% Internal macro for use by \presentbox.
1366 }
1367 {% No; use an \fbox.
1368 \newcommand{\present}[2][]{\leavevmode\llap{\textbf{\footnotesize#1}\,}\fbox{#2}}%
1369 \newcommand{\mkpbox@TP}[1]{\fbox{#1}}%
1370 }
1371 % \end{macrocode}
1372 % \end{macro}
1373 %
1374 % \begin{environment}{presentbox}
1375 % The presentbox environment creates a coloured patch of width |\linewidth| with a minipage inside. If the
1376 % colorhighlight option is not given, an |\fbox| containing the minipage is created.
1377 % \begin{macrocode}
1378 \newsavebox{\pbox@TP}% Container for the minipage to be boxed.
1379 \newenvironment{presentbox}%
1380 {%
1381 \par\smallskip% First a small space to separate the area from preceding text.
1382 \begin{lrbox}{\pbox@TP}% Save the contents in a minipage inside \pbox@TP.
1383 \noindent
1384 \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule}% Reduce the width of the minipage to leave space for the frame.
1385 \replacecolor{presentcolor}{pagecolor}% If \present is used inside the colored area...
1386 }%
1387 {%
1388 \end{minipage}
1389 \end{lrbox}%
1390 \noindent\mkpbox@TP{\usebox{\pbox@TP}}% This typesets the saved minipage inside the coloured area.
1391 \smallskip% A small space to separate the area from succeding text.
1392 \par
1393 }
1394 % \end{macrocode}
1395 % \end{environment}
1396 %
1397 %
1398 % \subsection{Structured rules, box and page backgrounds}
1399 %
1400 % \subsubsection{Structured rules}
1401 %
1402 % Some configurable defaults for rules and box backgrounds.
1403 %
1404 % Default number of stripes for gradient rules and box backgrounds.
1405 % \begin{macrocode}
1406 \newcommand{\rulestripes}{10}
1407 % \end{macrocode}
1408 % Default stripe overlap for avoiding `gaps' in color gradients.
1409 % \begin{macrocode}
1410 \newcommand{\stripeoverlap}{.15pt}
1411 % \end{macrocode}
1412 % Default gradient progression for rules and box backgrounds (single gradients or first part of double gradients).
1413 % \begin{macrocode}
1414 \newcommand{\rulefirstgradprogression}{1}
1415 % \end{macrocode}
1416 % Default gradient progression for rules and box backgrounds (second part of double gradients).
1417 % \begin{macrocode}
1418 \newcommand{\rulesecondgradprogression}{1}
1419 % \end{macrocode}
1420 % Default position of the `middle' color of a double gradient.
1421 % \begin{macrocode}
1422 \newcommand{\rulegradmidpoint}{.5}
1423 % \end{macrocode}
1424 %
1425 % The following are used internally when making color gradients.
1426 %
1427 % \begin{macrocode}
1428 \newcounter{stripe@TP}
1429
1430 \newcounter{stripes@TP}
1431
1432 \newcommand{\firstgradprogression@TP}{1}
1433
1434 \newcommand{\secondgradprogression@TP}{1}
1435
1436 \newcounter{gradprogression@TP}
1437
1438 \newcommand{\gradmidpoint@TP}{.5}
1439 % \end{macrocode}
1440 %
1441 % Special versions of |\mkfactor| which apply gradient progressions.
1442 % \begin{macrocode}
1443 \newcommand{\mkgradfirstfactor@TP}{\mkgradfactor@TP\firstgradprogression@TP}
1444
1445 \newcommand{\mkgradsecondfactor@TP}{\mkgradfactor@TP\secondgradprogression@TP}
1446
1447 \newcommand{\mkgradfactor@TP}[3]% Calculate a factor modified by a `progression' parameter.
1448 {%
1449 \mkfactor{#2}{#3}% Calculate the unmodified factor.
1450 \setcounter{gradprogression@TP}{#1}% Factor definition may contain a calc-expression.
1451 \ifthenelse{\value{gradprogression@TP}=1}{}% Progression value 1 is neutral.
1452 {%
1453 \ifthenelse{\value{gradprogression@TP}<0}% `Negative' progression?
1454 {% Yes.
1455 \@tempcnta-\value{gradprogression@TP}\relax% Complement progression wrt 0.
1456 \mkfactor{#2}{1-1pt*\real{#2}}% Complement factor definition wrt 1pt.
1457 }
1458 {\@tempcnta\value{gradprogression@TP}\relax}% No; Use progression as given.
1459 \whiledo{\the\@tempcnta>1}% Calculate (factor definition)^(progression).
1460 {\advance\@tempcnta by -1\relax\mkfactor{#2}{\real{#2}*\real{#2}}}%
1461 \ifthenelse{\value{gradprogression@TP}<0}% `Negative' progression?
1462 {% Yes.
1463 \mkfactor{#2}{1-1pt*\real{#2}}% Complement result wrt 1pt.
1464 }
1465 {}%
1466 }%
1467 }
1468 % \end{macrocode}
1469 %
1470 % \begin{macro}{\vgradrule}
1471 % |\vgradrule[<stripes>][<startmodel>]{<startcolor>}[<endmodel>]{<endcolor>}[<raise>]{<width>}{<height>}| creates a
1472 % rule-like object consisting of a vertical color gradient composed of horizontal stripes.
1473 %
1474 % The topmost stripe has color |{<startcolor>}|, the bottommost stripe has color |{<endcolor>}|. Inbetween, color changes
1475 % gradually from top to bottom.
1476 % The colors are specified exactly as for the |\color| command: if the optional argument |<startmodel>| is given,
1477 % |<startcolor>| contains an explicit definition of a color from model |<startmodel>|, otherwise |<startcolor>|
1478 % is the name of a defined color. The same holds for |<endmodel>| and |<endcolor>|.
1479 %
1480 % The arguments |[<raise>]{<width>}{<height>}| work exactly as for the |\rule| command.
1481 %
1482 % The optional argument |<stripes>|, if given, should contain a (calc expression for a) number specifying the number of
1483 % stripes. If |<stripes>| is not given, the default is the content of |\rulestripes| (default 10).
1484 %
1485 % There is one more parameter which is not given as an argument. The control sequence |\rulefirstgradprogression| should
1486 % expand to an (calc expression for an) integer. This value (default 1) controls the `order' of progression from
1487 % |<startcolor>| to |<endcolor>|.
1488 % The default value 1 means linear progression. 2 means quadratic progression, i.e. color values `nearer' to <endcolor>
1489 % are reached `later' (the square of 0.5, for instance, is 0.25, i.e. in the geometric middle point of the rule
1490 % produced, the color gradient will have traveled only to one quarter of the `distance' between |<startcolor>| and
1491 % |<endcolor>|).
1492 % 3 means cubic progression and so on. 0 and -1 mean the same as 1. -2 means quadratic progression ``from bottom to
1493 % top'', i.e. color values `nearer' to |<endcolor>| are reached `earlier', and analogously for -3, -4, ...
1494 %
1495 % If you wish to give the second optional argument but not the first, just write |\vgradrule[][<startmodel>]|...
1496 %
1497 % \begin{macrocode}
1498 \newcommand{\vgradrule}[1][]% Pick up first optional argument: [<stripes>]
1499 {%
1500 \let\firstgradprogression@TP=\rulefirstgradprogression% Use progression parameter for rules.
1501 \ifthenelse{\equal{#1}{}}% First optional argument given?
1502 {\setcounter{stripes@TP}{\rulestripes}}% No; use default value.
1503 {\setcounter{stripes@TP}{#1}}% Yes.
1504 \vgradrule@TP% Pick up [<startmodel>]{<startcolor>}.
1505 }
1506
1507 \newcommand{\vgradrule@TP}[2][]% Pick up next pair of arguments: [<startmodel>]{<startcolor>}.
1508 {%
1509 \ifthenelse{\equal{#1}{}}% <startmodel> given?
1510 {\replacecolor{startcolor@TP}{#2}}% No; <startcolor> is a color name.
1511 {\definecolor{startcolor@TP}{#1}{#2}}% Yes; {<startmodel>}{<startcolor>} is a color definition.
1512 \@vgradrule@TP% Pick up [<endmodel>]{<endcolor>}.
1513 }
1514
1515 \newcommand{\@vgradrule@TP}[2][]% Pick up next pair of arguments: [<endmodel>]{<endcolor>}.
1516 {%
1517 \ifthenelse{\equal{#1}{}}
1518 {\replacecolor{endcolor@TP}{#2}}
1519 {\definecolor{endcolor@TP}{#1}{#2}}%
1520 \@@vgradrule@TP% Pick up rule arguments and proceed.
1521 }
1522 % \end{macrocode}
1523 % Helper command for making \textbf{one} stripe. Can be overladed for making histograms.
1524 % \begin{macrocode}
1525 \newcommand{\hstripe@TP}[4]%
1526 {\hbox{{\setcolor@TP{stripecolor@TP}\rule{#2}{#3}}}#4}
1527 % \end{macrocode}
1528 % Main part of |\vgradrule|.
1529 % \begin{macrocode}
1530 \newcommand{\@@vgradrule@TP}[3][0pt]%
1531 {%
1532 \ifthenelse{\value{stripes@TP}<2}% A `pathological case' which can happen in animations: If 0 or 1 stripes are
1533 % requested, a division by zero error would be produced by the gradient code.
1534 {\mbox{{\setcolor@TP{startcolor@TP}\rule[#1]{#2}{#3}}}}% In this case, just produce a colored rule.
1535 {%
1536 \raisebox{#1}% Evaluate the <raise> argument of the rule.
1537 {%
1538 \vbox% A vbox with \offinterlineskip allows to align the stripes vertically.
1539 {%
1540 \offinterlineskip
1541 \setcounter{stripe@TP}{0}% Initialize the number of the current stripe.
1542 \whiledo{\value{stripe@TP}<\value{stripes@TP}}
1543 {%
1544 \mkgradfirstfactor@TP{\tmp@TP}% Make the weight for \colorbetween, based on the number of the current stripe
1545 {\value{stripe@TP}/(\value{stripes@TP}-1)}% and the first gradient progression.
1546 \colorbetween[\tmp@TP]{stripecolor@TP}{endcolor@TP}{startcolor@TP}% Calculate stripe color.
1547 \stepcounter{stripe@TP}%
1548 \ifthenelse{\value{stripe@TP}=\value{stripes@TP}}% Last stripe?
1549 {\hstripe@TP{\tmp@TP}{#2}{(#3)/\value{stripes@TP}}{}}% Yes; make stripe w/o overlap.
1550 {% No; add a kern to make stripes overlap.
1551 \hstripe@TP{\tmp@TP}{#2}{(#3)/\value{stripes@TP}+\stripeoverlap}{\kern-\stripeoverlap}%
1552 }%
1553 }% matches \whiledo{\value{stripe@TP}<\value{stripes@TP}}{%
1554 }% matches \vbox{%
1555 }% matches \raisebox{#1}{%
1556 }% matches second argument of \ifthenelse{\value{stripes@TP}<2}
1557 }% matches \newcommand{\@@vgradrule@TP}[3][0pt]{%
1558 % \end{macrocode}
1559 % \end{macro}
1560 %
1561 % \begin{macro}{\dblvgradrule}
1562 % |\dblvgradrule[<midpoint>][<stripes>][<startmodel>]|\\
1563 % | {<startcolor>}[<midmodel>]{<midcolor>}[<endmodel>]|\\
1564 % | {<endcolor>}[<raise>]{<width>}{<height>}|
1565 % creates a rule-like object consisting of a vertical color gradient composed of horizontal stripes.
1566 %
1567 % The behaviour is exactly like |\vgradrule|, only in addition to the defined `start' and `end' color, there is an
1568 % additional defined `middle' color. The color gradient first progresses from the start to the middle color and then
1569 % from the middle to the end color.
1570 %
1571 % |[<midmodel>]{<midcolor>}| specify the middle color exactly as described for the other colors in the description of
1572 % |\vgradrule|.
1573 %
1574 % The additional optional parameter |<midpoint>| is a fixed-point value specifying where in the produced gradient the
1575 % middle color is placed. 0 means the middle color replaces the start color; 1 means the middle color replaces the end
1576 % color; 0.5 means the middle color is placed in the geometric middle between start and end color. If |<midpoint>| is not
1577 % given, the default is the content of |\rulegradmidpoint| (default 0.5).
1578 %
1579 % There is another parameter not passed as an argument: while |\rulefirstgradprogression| specifies the order of
1580 % progression from first to middle color as described for |\vgradrule|, |\rulesecondgradprogression| specifies the order of
1581 % progression from middle to end color.
1582 %
1583 % If you wish to give one from the first row of optional arguments but not the other(s), any one can be replaced by |[]|
1584 % to use the default.
1585 %
1586 % \begin{macrocode}
1587 \newcommand{\dblvgradrule}[1][]% Pick up first optional argument: [<midpoint>]
1588 {%
1589 \let\firstgradprogression@TP=\rulefirstgradprogression% Use progression parameters for rules.
1590 \let\secondgradprogression@TP=\rulesecondgradprogression
1591 \ifthenelse{\equal{#1}{}}% First optional argument given?
1592 {\let\gradmidpoint@TP=\rulegradmidpoint}% No; use default value.
1593 {\def\gradmidpoint@TP{#1}}% Yes.
1594 \dblvgradrule@TP% Pick up second optional argument.
1595 }
1596
1597 \newcommand{\dblvgradrule@TP}[1][]% Pick up second optional argument: [<stripes>]
1598 {%
1599 \ifthenelse{\equal{#1}{}}
1600 {\setcounter{stripes@TP}{\rulestripes}}
1601 {\setcounter{stripes@TP}{#1}}%
1602 \@dblvgradrule@TP
1603 }
1604
1605 \newcommand{\@dblvgradrule@TP}[2][]% Pick up next pair of arguments: [<startmodel>]{<startcolor>}.
1606 {%
1607 \ifthenelse{\equal{#1}{}}
1608 {\replacecolor{startcolor@TP}{#2}}
1609 {\definecolor{startcolor@TP}{#1}{#2}}%
1610 \@@dblvgradrule@TP
1611 }
1612
1613 \newcommand{\@@dblvgradrule@TP}[2][]% Pick up next pair of arguments: [<midmodel>]{<midcolor>}.
1614 {%
1615 \ifthenelse{\equal{#1}{}}
1616 {\replacecolor{midcolor@TP}{#2}}
1617 {\definecolor{midcolor@TP}{#1}{#2}}%
1618 \@@@dblvgradrule@TP
1619 }
1620
1621 \newcommand{\@@@dblvgradrule@TP}[2][]% Pick up next pair of arguments: [<endmodel>]{<endcolor>}.
1622 {%
1623 \ifthenelse{\equal{#1}{}}
1624 {\replacecolor{endcolor@TP}{#2}}
1625 {\definecolor{endcolor@TP}{#1}{#2}}%
1626 \@@@@dblvgradrule@TP% Pick up rule arguments and proceed.
1627 }
1628
1629 \newcommand{\@@@@dblvgradrule@TP}[3][0pt]% Main part of \dblvgradrule.
1630 {%
1631 \ifthenelse{\value{stripes@TP}<2}% The gradient code is not equipped for making less than 2 stripes.
1632 {\mbox{{\setcolor@TP{midcolor@TP}\rule[#1]{#2}{#3}}}}% In this case, just produce a rule colored with the middle color.
1633 {%
1634 \raisebox{#1}% Evaluate the <raise> argument of the rule.
1635 {%
1636 \vbox% A vbox with \offinterlineskip allows to align the stripes
1637 {% vertically.
1638 \offinterlineskip
1639 \setcounter{stripe@TP}{0}% Initialize the number of the current stripe.
1640 \setcounter{tmpcnta@TP}% Number of the `middle' stripe.
1641 {\value{stripes@TP}*\real{\gradmidpoint@TP}}%
1642 \whiledo{\value{stripe@TP}<\value{tmpcnta@TP}}% Produce the upper part of the gradient.
1643 {%
1644 \mkgradfirstfactor@TP{\tmp@TP}% Make the weight for \colorbetween, based on the number of the
1645 {\value{stripe@TP}/\value{tmpcnta@TP}}% current stripe and the first gradient progression.
1646 \colorbetween[\tmp@TP]{stripecolor@TP}{midcolor@TP}{startcolor@TP}% Calculate stripe color.
1647 \hstripe@TP{\tmp@TP}% Make stripe with overlap.
1648 {#2}{(#3)/\value{stripes@TP}+\stripeoverlap}{\kern-\stripeoverlap}% This is the upper part, remember?
1649 \stepcounter{stripe@TP}%
1650 }%
1651 \stepcounter{tmpcnta@TP}%
1652 \ifthenelse{\value{stripes@TP}=\value{tmpcnta@TP}}% Only one stripe left to produce?
1653 {\hstripe@TP{1}{#2}{(#3)/\value{stripes@TP}}{}}% Just produce one stripe colored with the end color.
1654 {%
1655 \whiledo{\value{stripe@TP}<\value{stripes@TP}}% Produce the lower part of the gradient.
1656 {%
1657 \mkgradsecondfactor@TP{\tmp@TP}% Make the weight for \colorbetween.
1658 {(\value{stripe@TP}-\value{tmpcnta@TP}+1)/(\value{stripes@TP}-\value{tmpcnta@TP})}%
1659 \colorbetween[\tmp@TP]{stripecolor@TP}{endcolor@TP}{midcolor@TP}% Calculate stripe color.
1660 \stepcounter{stripe@TP}%
1661 \ifthenelse{\value{stripe@TP}=\value{stripes@TP}}% Last stripe?
1662 {\hstripe@TP{\tmp@TP}{#2}{(#3)/\value{stripes@TP}}{}}% Yes; make stripe w/o overlap.
1663 {% No; add kern to make stripes overlap.
1664 \hstripe@TP{\tmp@TP}{#2}{(#3)/\value{stripes@TP}+\stripeoverlap}{\kern-\stripeoverlap}%
1665 }%
1666 }% matches \whiledo{\value{stripe@TP}<\value{stripes@TP}}%
1667 }% matches second argument of \ifthenelse{\value{stripes@TP}=\value{tmpcnta@TP}}%
1668 }% matches \vbox{%
1669 }% matches \raisebox{#1}{%
1670 }% matches second argument of \ifthenelse{\value{stripes@TP}<2}%
1671 }% matches \newcommand{\@@@@dblvgradrule@TP}[3][0pt]%
1672 % \end{macrocode}
1673 % \end{macro}
1674 %
1675 % \begin{macro}{\hgradrule}
1676 % |\hgradrule[<stripes>][<startmodel>]{<startcolor>}|\\
1677 % | [<endmodel>]{<endcolor>}[<raise>]{<width>}{<height>}| creates a
1678 % rule-like object consisting of a horizontal color gradient composed of vertical stripes.
1679 %
1680 % Parameters are exactly as those for |\vgradrule| (replacing `top' by `left' and `bottom' by `right'). See there for
1681 % explanations.
1682 %
1683 % \begin{macrocode}
1684 \newcommand{\hgradrule}[1][]% Pick up first optional argument: [<stripes>].
1685 {%
1686 \let\firstgradprogression@TP=\rulefirstgradprogression% Use progression parameter for rules.
1687 \ifthenelse{\equal{#1}{}}% First optional argument given?
1688 {\setcounter{stripes@TP}{\rulestripes}}% No; use default value.
1689 {\setcounter{stripes@TP}{#1}}% Yes.
1690 \hgradrule@TP% Pick up [<startmodel>]{<startcolor>}.
1691 }
1692
1693 \newcommand{\hgradrule@TP}[2][]% Pick up next pair of arguments: [<startmodel>]{<startcolor>}.
1694 {%
1695 \ifthenelse{\equal{#1}{}}
1696 {\replacecolor{startcolor@TP}{#2}}
1697 {\definecolor{startcolor@TP}{#1}{#2}}%
1698 \@hgradrule@TP
1699 }
1700
1701 \newcommand{\@hgradrule@TP}[2][]
1702 {%
1703 \ifthenelse{\equal{#1}{}}
1704 {\replacecolor{endcolor@TP}{#2}}
1705 {\definecolor{endcolor@TP}{#1}{#2}}%
1706 \@@hgradrule@TP% Pick up rule arguments and proceed.
1707 }
1708
1709 \newcommand{\vstripe@TP}[4]% Helper command for making _one_ stripe. Can be overladed for making historams.
1710 {{\setcolor@TP{stripecolor@TP}\rule{#2}{#3}#4}}
1711
1712 \newcommand{\@@hgradrule@TP}[3][0pt]% Main part of \hgradrule.
1713 {%
1714 \ifthenelse{\value{stripes@TP}<2}% A `pathological case' which can happen in animations: If 0 or 1 stripes are
1715 % requested, a division by zero error would be produced by the gradient code.
1716 {\mbox{{\setcolor@TP{startcolor@TP}\rule[#1]{#2}{#3}}}}% In this case, just produce a colored rule.
1717 {%
1718 \raisebox{#1}% Evaluate the <raise> argument of the rule.
1719 {%
1720 \setcounter{stripe@TP}{0}% Initialize the number of the current stripe.
1721 \whiledo{\value{stripe@TP}<\value{stripes@TP}}
1722 {%
1723 \mkgradfirstfactor@TP{\tmp@TP}% Make the weight for \colorbetween, based on the number of the current stripe
1724 {\value{stripe@TP}/(\value{stripes@TP}-1)}% and the first gradient progression.
1725 \colorbetween[\tmp@TP]{stripecolor@TP}{endcolor@TP}{startcolor@TP}% Calculate stripe color.
1726 \stepcounter{stripe@TP}%
1727 \ifthenelse{\value{stripe@TP}=\value{stripes@TP}}% Last stripe?
1728 {\vstripe@TP{\tmp@TP}{(#2)/\value{stripes@TP}}{#3}{}}% Yes; make stripe w/o overlap.
1729 {% No; add a kern to make stripes overlap.
1730 \vstripe@TP{\tmp@TP}{(#2)/\value{stripes@TP}+\stripeoverlap}{#3}{\kern-\stripeoverlap}%
1731 }%
1732 }% matches \whiledo{\value{stripe@TP}<\value{stripes@TP}}{%
1733 }% matches \raisebox{#1}{%
1734 }% matches second argument of \ifthenelse{\value{stripes@TP}<2}%
1735 }% matches \newcommand{\@@hgradrule@TP}[3][0pt]{%
1736 % \end{macrocode}
1737 % \end{macro}
1738
1739 % \begin{macro}{\dblhgradrule}
1740 % |\dblhgradrule[<midpoint>][<stripes>][<startmodel>]|\\
1741 % | {<startcolor>}[<midmodel>]{<midcolor>}[<endmodel>]|\\
1742 % | {<endcolor>}[<raise>]{<width>}{<height>}|
1743 % creates a rule-like object consisting of a horizontal color gradient composed of vertical stripes.
1744 %
1745 % Parameters are exactly as those for |\dblvgradrule| (replacing `top' by `left' and `bottom' by `right'). See there for
1746 % explanations.
1747 %
1748 % \begin{macrocode}
1749 \newcommand{\dblhgradrule}[1][]% Pick up first optional argument: [<midpoint>].
1750 {%
1751 \let\firstgradprogression@TP=\rulefirstgradprogression% Use progression parameters for rules.
1752 \let\secondgradprogression@TP=\rulesecondgradprogression
1753 \ifthenelse{\equal{#1}{}}{\let\gradmidpoint@TP=\rulegradmidpoint}{\def\gradmidpoint@TP{#1}}%
1754 \dblhgradrule@TP
1755 }
1756
1757 \newcommand{\dblhgradrule@TP}[1][]% Pick up second optional argument: [<stripes>].
1758 {%
1759 \ifthenelse{\equal{#1}{}}{\setcounter{stripes@TP}{\rulestripes}}{\setcounter{stripes@TP}{#1}}%
1760 \@dblhgradrule@TP
1761 }
1762
1763 \newcommand{\@dblhgradrule@TP}[2][]% Pick up next pair of arguments: [<startmodel>]{<startcolor>}.
1764 {%
1765 \ifthenelse{\equal{#1}{}}{\replacecolor{startcolor@TP}{#2}}{\definecolor{startcolor@TP}{#1}{#2}}%
1766 \@@dblhgradrule@TP
1767 }
1768
1769 \newcommand{\@@dblhgradrule@TP}[2][]
1770 {%
1771 \ifthenelse{\equal{#1}{}}{\replacecolor{midcolor@TP}{#2}}{\definecolor{midcolor@TP}{#1}{#2}}%
1772 \@@@dblhgradrule@TP
1773 }
1774
1775 \newcommand{\@@@dblhgradrule@TP}[2][]
1776 {%
1777 \ifthenelse{\equal{#1}{}}
1778 {\replacecolor{endcolor@TP}{#2}}
1779 {\definecolor{endcolor@TP}{#1}{#2}}%
1780 \@@@@dblhgradrule@TP% Pick up rule arguments and proceed.
1781 }
1782
1783 \newcommand{\@@@@dblhgradrule@TP}[3][0pt]% Main part of \dblhgradrule.
1784 {%
1785 \ifthenelse{\value{stripes@TP}<2}% The gradient code is not equipped for making less than 2 stripes.
1786 {\mbox{{\setcolor@TP{midcolor@TP}\rule[#1]{#2}{#3}}}}% In this case, just produce a rule colored with the middle color.
1787 {%
1788 \raisebox{#1}% Evaluate the <raise> argument of the rule.
1789 {%
1790 \setcounter{stripe@TP}{0}% Initialize the number of the current stripe.
1791 \setcounter{tmpcnta@TP}% Number of the `middle' stripe.
1792 {\value{stripes@TP}*\real{\gradmidpoint@TP}}%
1793 \whiledo{\value{stripe@TP}<\value{tmpcnta@TP}}% Produce the left part of the gradient.
1794 {%
1795 \mkgradfirstfactor@TP{\tmp@TP}% Make the weight for \colorbetween, based on the number of the
1796 {\value{stripe@TP}/\value{tmpcnta@TP}}% current stripe and the first gradient progression.
1797 \colorbetween[\tmp@TP]{stripecolor@TP}{midcolor@TP}{startcolor@TP}% Calculate stripe color.
1798 \vstripe@TP{\tmp@TP}% Make stripe with overlap.
1799 {(#2)/\value{stripes@TP}+\stripeoverlap}{#3}{\kern-\stripeoverlap}% This is the left part, remember?
1800 \stepcounter{stripe@TP}%
1801 }%
1802 \stepcounter{tmpcnta@TP}%
1803 \ifthenelse{\value{stripes@TP}=\value{tmpcnta@TP}}% Only one stripe left to produce?
1804 {\vstripe@TP{1}{(#2)/\value{stripes@TP}}{#3}{}}% Just produce one stripe colored with the end color.
1805 {%
1806 \whiledo{\value{stripe@TP}<\value{stripes@TP}}% Produce the right part of the gradient.
1807 {%
1808 \mkgradsecondfactor@TP{\tmp@TP}% Make the weight for \colorbetween.
1809 {(\value{stripe@TP}-\value{tmpcnta@TP})/(\value{stripes@TP}-\value{tmpcnta@TP}-1)}%
1810 \colorbetween[\tmp@TP]{stripecolor@TP}{endcolor@TP}{midcolor@TP}% Calculate stripe color.
1811 \stepcounter{stripe@TP}%
1812 \ifthenelse{\value{stripe@TP}=\value{stripes@TP}}% Last stripe?
1813 {\vstripe@TP{\tmp@TP}{(#2)/\value{stripes@TP}}{#3}{}}% Yes; make stripe w/o overlap.
1814 {% Add kern to make stripes overlap.
1815 \vstripe@TP{\tmp@TP}{(#2)/\value{stripes@TP}+\stripeoverlap}{#3}{\kern-\stripeoverlap}%
1816 }%
1817 }% matches \whiledo{\value{stripe@TP}<\value{stripes@TP}}{%
1818 }% matches second argument of \ifthenelse{\value{stripes@TP}=\value{tmpcnta@TP}}%
1819 }% matches \raisebox{#1}{%
1820 }% matches second argument of \ifthenelse{\value{stripes@TP}<2}%
1821 }% matches \newcommand{\@@@@dblhgradrule@TP}[3][0pt]{%
1822 % \end{macrocode}
1823 % \end{macro}
1824 %
1825 % Clipbox stuff. The first part isn't used currently.
1826 % \begin{macrocode}
1827 % PDF:
1828 % \def\clipbox{\@ifnextchar[{\clipbox@}{\clipbox@[0pt]}}
1829 % \def\clipbox@[#1]#2{%
1830 % \begingroup
1831 % \setlength{\@tempdima}{#1}%
1832 % \setbox\@tempboxa=\hbox{%
1833 % \color@begingroup
1834 % #2%
1835 % \color@endgroup
1836 % }%
1837 % \leavevmode\hbox to \wd\@tempboxa{%
1838 % \@ifundefined{dimexpr}{%
1839 % \@defbp\x{-\@tempdima}%
1840 % \@tempdimc=\dp\@tempboxa
1841 % \advance\@tempdimc by \@tempdima
1842 % \@defbp\y{-\@tempdimc}%
1843 % \@tempdimc=\wd\@tempboxa
1844 % \advance\@tempdimc by 2\@tempdima
1845 % \@defbp\w{\@tempdimc}%
1846 % \@tempdimc=\dp\@tempboxa
1847 % \advance\@tempdimc by \ht\@tempboxa
1848 % \advance\@tempdimc by 2\@tempdima
1849 % \@defbp\h{\@tempdimc}%
1850 % \pdfliteral{%
1851 % q % gsave
1852 % \x\space\y\space\w\space\h\space re % rectangle
1853 % W n% make clip-path
1854 % }%
1855 % }{% e-TeX
1856 % \pdfliteral{%
1857 % q % gsave
1858 % \@dimtobp{-\@tempdima} % x
1859 % \@dimtobp{-\dp\@tempboxa-\@tempdima} % y
1860 % \@dimtobp{\wd\@tempboxa+2\@tempdima} % width
1861 % \@dimtobp{\dp\@tempboxa+\ht\@tempboxa+2\@tempdima} % height
1862 % re % rectangle
1863 % W n% make clip-path
1864 % }%
1865 % }%
1866 % \rlap{\unhbox\@tempboxa}%
1867 % \pdfliteral{%
1868 % Q% grestore
1869 % }%
1870 % \hss
1871 % }%
1872 % \endgroup
1873 % }
1874 % \begingroup\expandafter\expandafter\expandafter\endgroup
1875 % \expandafter\ifx\csname dimexpr\endcsname\relax
1876 % \def\@defbp#1#2{%
1877 % \setlength{\@tempdimb}{#2}%
1878 % \setlength{\@tempdimb}{.99626401\@tempdimb}%
1879 % \edef#1{\strip@pt\@tempdimb}%
1880 % }
1881 % \else
1882 % \def\@dimtobp#1{%
1883 % \strip@pt\dimexpr.99626401\dimexpr#1\relax\relax
1884 % }
1885 % \fi
1886 %
1887 % PS:
1888 % \def\clipbox{\@ifnextchar[{\clipbox@}{\clipbox@[0pt]}}
1889 % \def\clipbox@[#1]#2{%
1890 % \begingroup
1891 % \setlength{\@tempdima}{#1}%
1892 % \setbox\@tempboxa=\hbox{%
1893 % \color@begingroup
1894 % #2%
1895 % \color@endgroup
1896 % }%
1897 % \leavevmode\hbox to \wd\@tempboxa{%
1898 % \@ifundefined{dimexpr}{%
1899 % \@defpt\x{-\@tempdima}%
1900 % \@tempdimc=\ht\@tempboxa
1901 % \advance\@tempdimc by \@tempdima
1902 % \@defpt\y{-\@tempdimc}%
1903 % \@tempdimc=\wd\@tempboxa
1904 % \advance\@tempdimc by 2\@tempdima
1905 % \@defpt\w{\@tempdimc}%
1906 % \@tempdimc=\dp\@tempboxa
1907 % \advance\@tempdimc by \ht\@tempboxa
1908 % \advance\@tempdimc by 2\@tempdima
1909 % \@defpt\h{\@tempdimc}%
1910 % \special{ps:%
1911 % gsave %
1912 % SDict begin %
1913 % \x\space PTtoDVIPS \y\space PTtoDVIPS rmoveto %
1914 % currentpoint %
1915 % \w\space PTtoDVIPS \h\space PTtoDVIPS rectclip %
1916 % end%
1917 % }%
1918 % }{% e-TeX
1919 % \special{ps:%
1920 % gsave %
1921 % SDict begin %
1922 % \@dimtopt{-\@tempdima} PTtoDVIPS % x
1923 % \@dimtopt{-\ht\@tempboxa-\@tempdima} PTtoDVIPS % y
1924 % rmoveto currentpoint %
1925 % \@dimtopt{\wd\@tempboxa+2\@tempdima} PTtoDVIPS % width
1926 % \@dimtopt{\dp\@tempboxa+\ht\@tempboxa+2\@tempdima} %
1927 % PTtoDVIPS % height
1928 % rectclip %
1929 % end%
1930 % }%
1931 % }%
1932 % \rlap{\unhbox\@tempboxa}%
1933 % \special{ps:grestore}%
1934 % \hss
1935 % }%
1936 % \endgroup
1937 % }
1938 % \special{!%
1939 % /PTtoDVIPS{72.27 div Resolution mul}def%
1940 % % rectclip is a level 2 feature
1941 % /rectclip where{pop}{%
1942 % /rectclip{%
1943 % newpath %
1944 % 4 2 roll moveto %
1945 % exch dup 0 rlineto %
1946 % exch 0 exch rlineto %
1947 % neg 0 rlineto %
1948 % closepath %
1949 % clip %
1950 % newpath %
1951 % }bind def%
1952 % }%
1953 % ifelse%
1954 % }
1955 % \begingroup\expandafter\expandafter\expandafter\endgroup
1956 % \expandafter\ifx\csname dimexpr\endcsname\relax
1957 % \def\@defpt#1#2{%
1958 % \setlength{\@tempdimb}{#2}%
1959 % \edef#1{\strip@pt\@tempdimb}%
1960 % }
1961 % \else
1962 % \def\@dimtopt#1{%
1963 % \strip@pt\dimexpr#1\relax
1964 % }
1965 % \fi
1966
1967
1968 \ifpdf
1969 \providecommand{\clipbox}[2][\z@]
1970 {%
1971 \setlength{\@tempdima}{#1}%
1972 \setbox\@tempboxa=
1973 \hbox{\kern\@tempdima\vbox{\offinterlineskip\kern\@tempdima\hbox{#2}\kern\@tempdima}\kern\@tempdima}%
1974 \pdfxform\@tempboxa
1975 \leavevmode
1976 \hbox
1977 {%
1978 \kern-\@tempdima
1979 \vbox{\offinterlineskip\kern-\@tempdima\hbox{\pdfrefxform\pdflastxform}\kern-\@tempdima}%
1980 \kern-\@tempdima
1981 }%
1982 }
1983 \else
1984 \providecommand{\clipbox}[2][\z@]{\leavevmode\hbox{#2}}
1985 \fi
1986 % \end{macrocode}
1987 %
1988 % |\dgradslope| stuff.
1989 % \begin{macrocode}
1990 \newcommand{\dgradslope}{1,1}
1991
1992 \newcounter{dgradhslope@TP}
1993
1994 \newcounter{dgradvslope@TP}
1995
1996 \def\setdgradslope(#1,#2){\setcounter{dgradhslope@TP}{#1}\setcounter{dgradvslope@TP}{#2}}
1997 % \end{macrocode}
1998 %
1999 % |\dgradrule| stuff.
2000 % \begin{macrocode}
2001 \newcommand{\dgradrule}[1][]
2002 {%
2003 \ifthenelse{\equal{#1}{}}{\expandafter\setdgradslope\expandafter(\dgradslope)}{\setdgradslope(#1)}%
2004 \dgradrule@TP
2005 }
2006
2007 \newcommand{\dgradrule@TP}[2][]
2008 {%
2009 \ifthenelse{\equal{#1}{}}{\replacecolor{startcolor@TP}{#2}}{\definecolor{startcolor@TP}{#1}{#2}}%
2010 \@dgradrule@TP
2011 }
2012
2013 \newcommand{\@dgradrule@TP}[2][]
2014 {%
2015 \ifthenelse{\equal{#1}{}}{\replacecolor{endcolor@TP}{#2}}{\definecolor{endcolor@TP}{#1}{#2}}%
2016 \@@dgradrule@TP
2017 }
2018
2019 \newcommand{\dstripewd@TP}{.7pt}
2020
2021 \newcommand{\@@dgradrule@TP}[3][0pt]
2022 {%
2023 \raisebox{#1}
2024 {%
2025 \thicklines
2026 \setcounter{stripe@TP}{0}%
2027 \setcounter{tmpcnta@TP}{1*\ratio{#3}{\dstripewd@TP}}%
2028 \setcounter{stripes@TP}{1*\ratio{#3}{\dstripewd@TP}+1*\ratio{#2}{\dstripewd@TP}}%
2029 \@xarg\c@dgradhslope@TP\@yarg\c@dgradvslope@TP
2030 \makebox[\dstripewd@TP]
2031 {%
2032 \whiledo{\value{stripe@TP}<\value{tmpcnta@TP}}
2033 {%
2034 \mkfactor{\tmp@TP}{\value{stripe@TP}/(\value{stripes@TP}-1)}%
2035 \colorbetween[\tmp@TP]{stripecolor@TP}{endcolor@TP}{startcolor@TP}%
2036 \setlength{\@linelen}{\dstripewd@TP*\value{stripe@TP}}%
2037 \raisebox{\dstripewd@TP*(\value{tmpcnta@TP}-\value{stripe@TP})}
2038 {\makebox[0pt]{{\setcolor@TP{stripecolor@TP}\hbox to 0pt{\@sline\hss}}}}%
2039 \stepcounter{stripe@TP}%
2040 }%
2041 }%
2042 \whiledo{\value{stripe@TP}<\value{stripes@TP}}
2043 {%
2044 \mkfactor{\tmp@TP}{\value{stripe@TP}/(\value{stripes@TP}-1)}%
2045 \colorbetween[\tmp@TP]{stripecolor@TP}{endcolor@TP}{startcolor@TP}%
2046 \makebox[\dstripewd@TP]{{\setcolor@TP{stripecolor@TP}.}}%
2047 \stepcounter{stripe@TP}%
2048 }%
2049 }%
2050 }%
2051 % \end{macrocode}
2052 %
2053 % \subsubsection{Structured box backgrounds}
2054 %
2055 % \begin{macro}{\vgradbox}
2056 % |\vgradbox[<stripes>][<startmodel>]{<startcolor>}[<endmodel>]{<endcolor>}{<content>}| creates an mbox containing
2057 % |<content>|, which has a background made up of a vertical color gradient. In fact, the background exceeds the extent of
2058 % |<content>| by the value of |\fboxsep| on every side, just like the |\colorbox| command from the color package.
2059 %
2060 % The gradient background is constructed using the |\vgradrule| command; see the description of |\vgradrule| on the way the
2061 % gradient is constructed and on the meaning of the parameters |<stripes>|, |<startmodel>|, |<startcolor>|, |<endmodel>|,
2062 % |<endcolor>| and the additional parameter |\rulefirstgradprogression| which has the same meaning for |\vgradbox| as for
2063 % |\vgradrule|.
2064 %
2065 % \begin{macrocode}
2066 \newcommand{\vgradbox}[1][]% Pick up first optional argument: [<stripes>].
2067 {%
2068 \let\firstgradprogression@TP=\rulefirstgradprogression% Use progression parameter for rules.
2069 \ifthenelse{\equal{#1}{}}% First optional argument given?
2070 {\setcounter{stripes@TP}{\rulestripes}}% No; use default value.
2071 {\setcounter{stripes@TP}{#1}}% Yes.
2072 \vgradbox@TP% Pick up remaining optional arguments.
2073 }
2074
2075 \newcommand{\vgradbox@TP}[2][]
2076 {%
2077 \ifthenelse{\equal{#1}{}}{\replacecolor{startcolor@TP}{#2}}{\definecolor{startcolor@TP}{#1}{#2}}%
2078 \@vgradbox@TP
2079 }
2080
2081 \newcommand{\@vgradbox@TP}[2][]
2082 {%
2083 \ifthenelse{\equal{#1}{}}{\replacecolor{endcolor@TP}{#2}}{\definecolor{endcolor@TP}{#1}{#2}}%
2084 \@@gradbox@TP\@@vgradrule@TP% Make a generic background box with vertical gradient background.
2085 }
2086
2087 \newcommand{\@@gradbox@TP}[2]% Generic background box.
2088 {%
2089 \leavevmode% Make box behave like \mbox.
2090 \setbox\tempbox@TP
2091 \hbox{\kern\fboxsep{\set@color#2}\kern\fboxsep}% An \hbox containing <contents> plus additional white space.
2092 \rlap% Underlay box background with rule command passed as #1.
2093 {%
2094 #1[-\fboxsep-\dp\tempbox@TP]% Box depth augmented by `white' space.
2095 {\wd\tempbox@TP}% Space on the sides has already been added.
2096 {\ht\tempbox@TP+\dp\tempbox@TP+2\fboxsep}}% Total height.
2097 \box\tempbox@TP% Overlay box contents.
2098 }%
2099 % \end{macrocode}
2100 % \end{macro}
2101 %
2102 % \begin{macro}{\hgradbox}
2103 % |\hgradbox[<stripes>][<startmodel>]{<startcolor>}[<endmodel>]{<endcolor>}{<content>}| acts like |\vgradbox|, but creates
2104 % the background using |\hgradrule|. See comments above.
2105 %
2106 % \begin{macrocode}
2107 \newcommand{\hgradbox}[1][]
2108 {%
2109 \let\secondgradprogression@TP=\rulesecondgradprogression
2110 \ifthenelse{\equal{#1}{}}{\setcounter{stripes@TP}{\rulestripes}}{\setcounter{stripes@TP}{#1}}%
2111 \hgradbox@TP
2112 }
2113
2114 \newcommand{\hgradbox@TP}[2][]
2115 {%
2116 \ifthenelse{\equal{#1}{}}{\replacecolor{startcolor@TP}{#2}}{\definecolor{startcolor@TP}{#1}{#2}}%
2117 \@hgradbox@TP
2118 }
2119
2120 \newcommand{\@hgradbox@TP}[2][]
2121 {%
2122 \ifthenelse{\equal{#1}{}}{\replacecolor{endcolor@TP}{#2}}{\definecolor{endcolor@TP}{#1}{#2}}%
2123 \@@gradbox@TP\@@hgradrule@TP
2124 }
2125 % \end{macrocode}
2126 % \end{macro}
2127 %
2128 % \begin{macro}{\dblvgradbox}
2129 % |\dblvgradbox[<midpoint>][<stripes>][<startmodel>]|\\
2130 % | {<startcolor>}[<midmodel>]{<midcolor>}[<endmodel>]{<endcolor>}{<contents>}|
2131 % acts like |\vgradbox|, but creates the background using |\dblvgradrule| (hence the additional parameters). See comments
2132 % above (and the description of |\dblvgradrule| concerning the meaning of |\dblvgradrule| parameters).
2133 %
2134 % \begin{macrocode}
2135 \newcommand{\dblvgradbox}[1][]
2136 {%
2137 \let\firstgradprogression@TP=\rulefirstgradprogression% Use progression parameters for rules.
2138 \let\secondgradprogression@TP=\rulesecondgradprogression
2139 \ifthenelse{\equal{#1}{}}{\let\gradmidpoint@TP=\rulegradmidpoint}{\def\gradmidpoint@TP{#1}}%
2140 \dblvgradbox@TP
2141 }
2142
2143 \newcommand{\dblvgradbox@TP}[1][]
2144 {%
2145 \ifthenelse{\equal{#1}{}}{\setcounter{stripes@TP}{\rulestripes}}{\setcounter{stripes@TP}{#1}}%
2146 \@dblvgradbox@TP
2147 }
2148
2149 \newcommand{\@dblvgradbox@TP}[2][]
2150 {%
2151 \ifthenelse{\equal{#1}{}}{\replacecolor{startcolor@TP}{#2}}{\definecolor{startcolor@TP}{#1}{#2}}%
2152 \@@dblvgradbox@TP
2153 }
2154
2155 \newcommand{\@@dblvgradbox@TP}[2][]
2156 {%
2157 \ifthenelse{\equal{#1}{}}{\replacecolor{midcolor@TP}{#2}}{\definecolor{midcolor@TP}{#1}{#2}}%
2158 \@@@dblvgradbox@TP
2159 }
2160
2161 \newcommand{\@@@dblvgradbox@TP}[2][]
2162 {%
2163 \ifthenelse{\equal{#1}{}}{\replacecolor{endcolor@TP}{#2}}{\definecolor{endcolor@TP}{#1}{#2}}%
2164 \@@gradbox@TP\@@@@dblvgradrule@TP
2165 }
2166 % \end{macrocode}
2167 % \end{macro}
2168 %
2169 % \begin{macro}{\dblhgradbox}
2170 % |\dblhgradbox[<midpoint>][<stripes>][<startmodel>]|\\
2171 % | {<startcolor>}[<midmodel>]{<midcolor>}[<endmodel>]{<endcolor>}{<contents>}|
2172 % acts like |\dblvgradbox|, but creates the background using |\dblhgradrule|. See comments above.
2173 %
2174 % \begin{macrocode}
2175 \newcommand{\dblhgradbox}[1][]
2176 {%
2177 \let\firstgradprogression@TP=\rulefirstgradprogression
2178 \let\secondgradprogression@TP=\rulesecondgradprogression
2179 \ifthenelse{\equal{#1}{}}{\let\gradmidpoint@TP=\rulegradmidpoint}{\def\gradmidpoint@TP{#1}}%
2180 \dblhgradbox@TP
2181 }
2182
2183 \newcommand{\dblhgradbox@TP}[1][]
2184 {%
2185 \ifthenelse{\equal{#1}{}}{\setcounter{stripes@TP}{\rulestripes}}{\setcounter{stripes@TP}{#1}}%
2186 \@dblhgradbox@TP
2187 }
2188
2189 \newcommand{\@dblhgradbox@TP}[2][]
2190 {%
2191 \ifthenelse{\equal{#1}{}}{\replacecolor{startcolor@TP}{#2}}{\definecolor{startcolor@TP}{#1}{#2}}%
2192 \@@dblhgradbox@TP
2193 }
2194
2195 \newcommand{\@@dblhgradbox@TP}[2][]
2196 {%
2197 \ifthenelse{\equal{#1}{}}{\replacecolor{midcolor@TP}{#2}}{\definecolor{midcolor@TP}{#1}{#2}}%
2198 \@@@dblhgradbox@TP
2199 }
2200
2201 \newcommand{\@@@dblhgradbox@TP}[2][]
2202 {%
2203 \ifthenelse{\equal{#1}{}}{\replacecolor{endcolor@TP}{#2}}{\definecolor{endcolor@TP}{#1}{#2}}%
2204 \@@gradbox@TP\@@@@dblhgradrule@TP
2205 }
2206 % \end{macrocode}
2207 % \end{macro}
2208 %
2209 % \subsubsection{Structured page backgrounds}
2210 %
2211 % \begin{macro}{\backgroundstyle}
2212 % |\backgroundstyle[<options>]{<style>}| is the central command for structured page backgrounds. It works like |\pagestyle|
2213 % and other commands of this type. This means |<style>| is a symbolic name specifying the general method by which the page
2214 % background is constructed.
2215 % The detailed construction is influenced by parameters which can be set in |<options>|. If given, the optional parameter
2216 % |<options>| should contain a list of settings in ``keyval'' manner. The keyval method (which is used by the
2217 % |\includegraphics| command from the graphicx package, for instance) is based on associating a symbolic name with every
2218 % parameter. |<options>| is then a comma-separated list of parameter settings of the form |<name>=<value>|, where |<name>| is
2219 % the symbolic name of the parameter to be set and |<value>| is the value it is to be set to.
2220 % Not every |<style>| evaluates every parameter. In the following, a description of all styles, together with lists of the
2221 % parameters employed, is given. It is followed by a list of all parameters.
2222 % Note that some parameter names internally access the same parameter. For instance, parameters startcolor and
2223 % startcolordef both set the start color of a color gradient. In case of conflict, the last setting in the list
2224 % |<options>| will prevail. It is noted in the list of parameters which other parameters are overwritten.
2225 %
2226 % |<style>| may have one of the following values:
2227 %
2228 % \begin{longtable}{@{}lp{0.5\textwidth}}
2229 % none & No background. This means the page background is whatever it would be if |\backgroundstyle| wasn't used at all
2230 % (for instance, a plain area of color pagecolor if one of the color options has been given).
2231 % Parameters used: none. \\
2232 % plain & Plain background. This means the page background is whatever it would be if |\backgroundstyle| wasn't used at all
2233 % (for instance, a plain area of color pagecolor if one of the color options has been given). In addition to
2234 % background style ``none'', the background style ``plain'' does produce panel backgrounds. The colors and
2235 % dimensions of a ``top panel'', ``bottom panel'', ``left panel'', and ``right panel'' can be specified.
2236 %
2237 % Parameters used: hpanels, autopanels, toppanelcolor, bottompanelcolor, leftpanelcolor, rightpanelcolor,
2238 % toppanelcolordef, bottompanelcolordef, leftpanelcolordef, rightpanelcolordef,
2239 % toppanelheight, bottompanelheight, leftpanelwidth, rightpanelwidth.\\
2240 % vgradient & Vertical gradient. The page background is constructed using the |\vgradrule| command.
2241 % In addition to the usual parameters of gradient rules, the vgradient background style allows to leave
2242 % space for headers, footers, or panels. The colors and dimensions of a ``top panel'', ``bottom panel'',
2243 % ``left panel'', and ``right panel'' can be specified. The gradient rule fills the rectangular space left
2244 % between the specified panels.
2245 %
2246 % Parameters used: stripes, firstgradprogression, startcolor, startcolordef, endcolor, endcolordef,
2247 % hpanels, autopanels,
2248 % toppanelcolor, bottompanelcolor, leftpanelcolor, rightpanelcolor,
2249 % toppanelcolordef, bottompanelcolordef, leftpanelcolordef, rightpanelcolordef,
2250 % toppanelheight, bottompanelheight, leftpanelwidth, rightpanelwidth.\\
2251 % hgradient & Horizontal gradient. The page background is constructed using the |\hgradrule| command.
2252 % See the description of vgradient concerning panels.
2253 %
2254 % Parameters used: stripes, firstgradprogression, startcolor, startcolordef, endcolor, endcolordef,
2255 % hpanels, autopanels,
2256 % toppanelcolor, bottompanelcolor, leftpanelcolor, rightpanelcolor,
2257 % toppanelcolordef, bottompanelcolordef, leftpanelcolordef, rightpanelcolordef,
2258 % toppanelheight, bottompanelheight, leftpanelwidth, rightpanelwidth.\\
2259 % doublevgradient & `Double' vertical gradient. The page background is constructed using the |\dblvgradrule| command.
2260 % See the description of vgradient concerning panels.
2261 %
2262 % Parameters used: stripes, gradmidpoint, firstgradprogression, secondgradprogression,
2263 % startcolor, startcolordef, midcolor, midcolordef, endcolor, endcolordef,
2264 % hpanels, autopanels,
2265 % toppanelcolor, bottompanelcolor, leftpanelcolor, rightpanelcolor,
2266 % toppanelcolordef, bottompanelcolordef, leftpanelcolordef, rightpanelcolordef,
2267 % toppanelheight, bottompanelheight, leftpanelwidth, rightpanelwidth.\\
2268 % doublehgradient & `Double' horizontal gradient. The page background is constructed using the |\dblhgradrule| command.
2269 % See the description of vgradient concerning panels.
2270 %
2271 % Parameters used: stripes, gradmidpoint, firstgradprogression, secondgradprogression,
2272 % startcolor, startcolordef, midcolor, midcolordef, endcolor, endcolordef,
2273 % hpanels, autopanels,
2274 % toppanelcolor, bottompanelcolor, leftpanelcolor, rightpanelcolor,
2275 % toppanelcolordef, bottompanelcolordef, leftpanelcolordef, rightpanelcolordef,
2276 % toppanelheight, bottompanelheight, leftpanelwidth, rightpanelwidth.
2277 % \end{longtable}
2278 %
2279 % Now, a list of all parameters and their meaning. In the following,
2280 %
2281 % \begin{longtable}{@{}lp{0.5\textwidth}}
2282 % |<n>| & denotes a (calc expression for a) nonnegative integer\\
2283 % |<i>| & denotes a (calc expression for an) integer\\
2284 % |<r>| & denotes a fixed-point number\\
2285 % |<l>| & denotes a (calc expression for a) length\\
2286 % |<c>| & denotes the name of a defined color\\
2287 % |<cm>|& denotes a valid color model name (in the sense of the color package)\\
2288 % |<cd>|& denotes a valid color definition (in the sense of the color package) wrt a given |<cm>| parameter\\
2289 % |<t>| & denotes a `truth value' in the sense of the ifthen package: either true or false. As usual for keyval,
2290 % if |=<t>| is omitted, the default true is assumed.
2291 % \end{longtable}
2292 %
2293 % \begin{longtable}{@{}lp{0.5\textwidth}}
2294 % Parameter & Meaning\\
2295 %
2296 % |stripes=<n>| & Set the |<stripes>| parameter of gradient rules to |<n>|.
2297 % Default: |\bgndstripes|
2298 % Used by: vgradient, hgradient, doublevgradient, doublehgradient\\
2299 %
2300 % |gradmidpoint=<r>| & Set the |<midpoint>| parameter of double gradient rules to |<r>|.
2301 % Default: |\bgndgradmidpoint|
2302 % Used by: doublevgradient, doublehgradient\\
2303 %
2304 % |firstgradprogression=<i>| & Set the first gradient progression of gradient rules to |<i>|.
2305 % Default: |\bgndfirstgradprogression|
2306 % Used by: vgradient, hgradient, doublevgradient, doublehgradient\\
2307 %
2308 % |secondgradprogression=<i>| & Set the second gradient progression of double gradient rules to |<i>|.
2309 % Default: |\bgndsecondgradprogression|
2310 % Used by: doublevgradient, doublehgradient\\
2311 %
2312 % |startcolor=<c>| & Set the |<startcolor>| parameter of gradient rules to |<c>|.
2313 % Default: If neither startcolor nor startcolordef is given, the color bgndstartcolor is
2314 % used as |<startcolor>|.
2315 % Used by: vgradient, hgradient, doublevgradient, doublehgradient
2316 % Overwrites: startcolordef\\
2317 %
2318 % |startcolordef={<cm>}{<cd>}|& Set the |<startcolor>| parameter of gradient rules to color foo, which is obtained by
2319 % |\definecolor{foo}{<cm>}{<cd>}|. Note that the two pairs of curly braces are mandatory.
2320 % Default: If neither startcolor nor startcolordef is given, the color bgndstartcolor is
2321 % used as |<startcolor>|.
2322 % Used by: vgradient, hgradient, doublevgradient, doublehgradient
2323 % Overwrites: startcolor\\
2324 %
2325 % |endcolor=<c>| & Set the |<endcolor>| parameter of gradient rules to |<c>|.
2326 % Default: If neither endcolor nor endcolordef is given, the color bgndendcolor is
2327 % used as |<endcolor>|.
2328 % Used by: vgradient, hgradient, doublevgradient, doublehgradient
2329 % Overwrites: endcolordef\\
2330 %
2331 % |endcolordef={<cm>}{<cd>}| & Set the |<endcolor>| parameter of gradient rules to color foo, which is obtained by
2332 % |\definecolor{foo}{<cm>}{<cd>}|. Note that the two pairs of curly braces are mandatory.
2333 % Default: If neither endcolor nor endcolordef is given, the color bgndendcolor is
2334 % used as |<endcolor>|.
2335 % Used by: vgradient, hgradient, doublevgradient, doublehgradient
2336 % Overwrites: endcolor\\
2337 %
2338 % |midcolor=<c>| & Set the |<midcolor>| parameter of double gradient rules to |<c>|.
2339 % Default: If neither midcolor nor midcolordef is given, the color bgndmidcolor is
2340 % used as |<midcolor>|.
2341 % Used by: doublevgradient, doublehgradient
2342 % Overwrites: midcolordef\\
2343 %
2344 % |midcolordef={<cm>}{<cd>}| & Set the |<midcolor>| parameter of double gradient rules to color foo, which is obtained by
2345 % |\definecolor{foo}{<cm>}{<cd>}|. Note that the two pairs of curly braces are mandatory.
2346 % Default: If neither midcolor nor midcolordef is given, the color bgndmidcolor is
2347 % used as |<midcolor>|.
2348 % Used by: doublevgradient, doublehgradient
2349 % Overwrites: midcolor\\
2350 %
2351 % |hpanels=<t>| & Specifies the `direction' of panels produced. hpanels=true means the top and bottom
2352 % panel span the full width of the screen. In the space left in the middle, the left
2353 % panel, the background itself, and the right panel are displayed.
2354 % hpanels=false means the left and right panel span the full height of the screen. In the
2355 % space left in the middle, the top panel, the background itself, and the bottom panel are
2356 % displayed.
2357 % Default: hpanels=true is the default for plain, hgradient and
2358 % doublehgradient. hpanels=false is the default for vgradient and
2359 % doublevgradient.
2360 % Used by: plain, vgradient, hgradient, doublevgradient, doublehgradient\\
2361 %
2362 % |autopanels=<t>| & Specifies whether the default values of the parameters toppanelheight,
2363 % bottompanelheight, leftpanelwidth, rightpanelwidth should be calculated automatically
2364 % from the contents of declared panels.
2365 % The automatism used is analogous to that of |\DeclarePanel*|.
2366 % Note that for panel arrangement, both the width and the height of all declared panels
2367 % are overwritten. If you don't want this, calculate the panel parameters yourself and set
2368 % autopanels=false. In this case, the current panel dimensions of declared panels are used
2369 % as defaults for toppanelheight, bottompanelheight, leftpanelwidth, rightpanelwidth.
2370 % Default: true.
2371 % Used by: plain, vgradient, hgradient, doublevgradient, doublehgradient\\
2372 %
2373 % |toppanelheight=<l>| & \\
2374 % |bottompanelheight=<l>| & \\
2375 % |leftpanelwidth=<l>| & \\
2376 % |rightpanelwidth=<l>| & Set the height/width of the space left for the top/bottom/left/right panel to <l>.
2377 % Note that the remaining dimensions of panels, for instance the width of the top panel,
2378 % are always calculated automatically, depending on the setting of the hpanels parameter.
2379 % Default: If a respective panel has been defined using |\DeclarePanel|, the default used
2380 % depends on the setting of the autopanels parameter.
2381 % If autopanels=true, the correct dimension is calculated from the contents of
2382 % the panel. The respective one of |\toppanelheight|, |\bottompanelheight|,
2383 % |\leftpanelwidth|, |\rightpanelwidth| is overwritten with the result.
2384 % If autopanels=false, then the respective setting of |\toppanelheight|,
2385 % |\bottompanelheight|, |\leftpanelwidth|, |\rightpanelwidth| is taken as the default.
2386 % If a panel has not been declared, the appropriate one of |\bgndtoppanelheight|,
2387 % |\bgndbottompanelheight|, |\bgndleftpanelwidth|, |\bgndrightpanelwidth| is used as
2388 % default.
2389 % Used by: plain, vgradient, hgradient, doublevgradient, doublehgradient\\
2390 %
2391 % |toppanelcolor=<c>| & \\
2392 % |bottompanelcolor=<c>| & \\
2393 % |leftpanelcolor=<c>| & \\
2394 % |rightpanelcolor=<c>| & Set the color of the space left for the top/bottom/left/right panel to <c>.
2395 % Default: The standard colors toppanelcolor, bottompanelcolor, leftpanelcolor,
2396 % rightpanelcolor are used as defaults.
2397 % Used by: plain, vgradient, hgradient, doublevgradient, doublehgradient
2398 % Overwrites: toppanelcolordef bottompanelcolordef leftpanelcolordef rightpanelcolordef \\
2399 %
2400 % |toppanelcolordef={<cm>}{<cd>}| & \\
2401 % |bottompanelcolordef={<cm>}{<cd>}| & \\
2402 % |leftpanelcolordef={<cm>}{<cd>}| & \\
2403 % |rightpanelcolordef={<cm>}{<cd>}| &
2404 % Set the color of the space left for the top/bottom/left/right panel to color foo, which
2405 % is obtained by |\definecolor{foo}{<cm>}{<cd>}|. Note that the two pairs of curly braces
2406 % are mandatory.
2407 % Default: See the description of top/bottom/left/rightpanelcolor.
2408 % Used by: plain, vgradient, hgradient, doublevgradient, doublehgradient
2409 % Overwrites: toppanelcolor bottompanelcolor leftpanelcolor rightpanelcolor
2410 % \end{longtable}
2411 %
2412 % \begin{macrocode}
2413 \newcommand{\backgroundstyle}[2][]
2414 {%
2415 \replacecolor{startcolor@TP}{bgndstartcolor}% Initialize the internal counterparts
2416 \replacecolor{midcolor@TP}{bgndmidcolor}% of parameters to their default values.
2417 \replacecolor{endcolor@TP}{bgndendcolor}%
2418 \replacecolor{bgndtoppanelcolor@TP}{toppanelcolor}%
2419 \replacecolor{bgndbottompanelcolor@TP}{bottompanelcolor}%
2420 \replacecolor{bgndleftpanelcolor@TP}{leftpanelcolor}%
2421 \replacecolor{bgndrightpanelcolor@TP}{rightpanelcolor}%
2422 \let\firstgradprogression@TP=\bgndfirstgradprogression
2423 \let\secondgradprogression@TP=\bgndsecondgradprogression%
2424 \setcounter{stripes@TP}{\bgndstripes}%
2425 \let\gradmidpoint@TP=\bgndgradmidpoint
2426 \let\bgndtoppanelheight@TP=\empty% The panel dimensions depend on other parameters. If they are not
2427 \let\bgndbottompanelheight@TP=\empty% set directly, defaults are calculated after setting keyval
2428 \let\bgndleftpanelwidth@TP=\empty% parameters.
2429 \let\bgndrightpanelwidth@TP=\empty
2430 \let\hpanelsvalue@TP=\empty
2431 \setboolean{autopanels@TP}{true}%
2432 \csname set#2bgnd@TP\endcsname{#1}% Execute the style-specific command which defines the background box.
2433 }
2434 % \end{macrocode}
2435 % \end{macro}
2436 %
2437 % Background-specific default values.
2438 %
2439 % Default number of stripes for gradient page backgrounds.
2440 % \begin{macrocode}
2441 \newcommand{\bgndstripes}{10}
2442 % \end{macrocode}
2443 % Default position of the `middle' color of a double gradient.
2444 % \begin{macrocode}
2445 \newcommand{\bgndgradmidpoint}{.5}
2446 % \end{macrocode}
2447 % Default gradient progression for page backgrounds (single gradients or first part of double gradients).
2448 % \begin{macrocode}
2449 \newcommand{\bgndfirstgradprogression}{1}
2450 % \end{macrocode}
2451 % Default gradient progression for page backgrounds (second part of double gradients).
2452 % \begin{macrocode}
2453 \newcommand{\bgndsecondgradprogression}{1}
2454 % \end{macrocode}
2455 % Default height/width of the space left for the top/bottom/left/right panel, in case no panel in the respective
2456 % position has been declared. Otherwise, the defaults are taken from |\toppanelheight|, |\bottompanelheight|,
2457 % |\leftpanelwidth|, |\rightpanelwidth| or calculated automatically, depending on the setting of the autopanels parameter.
2458 % Note that the remaining dimensions of panels, for instance the width of the top panel, are always calculated
2459 % automatically, depending on the setting of the hpanels parameter.
2460 % \begin{macrocode}
2461 \newcommand{\bgndtoppanelheight}{0pt}
2462
2463 \newcommand{\bgndbottompanelheight}{0pt}
2464
2465 \newcommand{\bgndleftpanelwidth}{0pt}
2466
2467 \newcommand{\bgndrightpanelwidth}{0pt}
2468 % \end{macrocode}
2469 %
2470 % Internal names for parameter values.
2471 % \begin{macrocode}
2472 \newcommand{\bgndtoppanelheight@TP}{0pt}
2473
2474 \newcommand{\bgndtoppanelwidth@TP}{0pt}
2475
2476 \newcommand{\bgndbottompanelheight@TP}{0pt}
2477
2478 \newcommand{\bgndbottompanelwidth@TP}{0pt}
2479
2480 \newcommand{\bgndleftpanelheight@TP}{0pt}
2481
2482 \newcommand{\bgndleftpanelwidth@TP}{0pt}
2483
2484 \newcommand{\bgndrightpanelheight@TP}{0pt}
2485
2486 \newcommand{\bgndrightpanelwidth@TP}{0pt}
2487
2488 \newboolean{hpanels@TP}
2489
2490 \newboolean{autopanels@TP}
2491 % \end{macrocode}
2492 %
2493 % The following commands define the keys for setting the parameters using the keyval package.
2494 % \begin{macrocode}
2495 \define@key{bgnd@TP}{stripes}{\setcounter{stripes@TP}{#1}}
2496
2497
2498 \define@key{bgnd@TP}{startcolor}{\replacecolor{startcolor@TP}{#1}}
2499
2500 \define@key{bgnd@TP}{startcolordef}{\definecolor{startcolor@TP}#1}
2501
2502
2503 \define@key{bgnd@TP}{midcolor}{\replacecolor{midcolor@TP}{#1}}
2504
2505 \define@key{bgnd@TP}{midcolordef}{\definecolor{midcolor@TP}#1}
2506
2507
2508 \define@key{bgnd@TP}{endcolor}{\replacecolor{endcolor@TP}{#1}}
2509
2510 \define@key{bgnd@TP}{endcolordef}{\definecolor{endcolor@TP}#1}
2511
2512
2513 \define@key{bgnd@TP}{gradmidpoint}{\edef\gradmidpoint@TP{#1}}
2514
2515
2516 \define@key{bgnd@TP}{firstgradprogression}{\def\firstgradprogression@TP{#1}}
2517
2518 \define@key{bgnd@TP}{secondgradprogression}{\def\secondgradprogression@TP{#1}}
2519
2520
2521 \define@key{bgnd@TP}{hpanels}[true]{\def\hpanelsvalue@TP{#1}}
2522
2523 \define@key{bgnd@TP}{autopanels}[true]{\setboolean{autopanels@TP}{#1}}
2524
2525
2526 \define@key{bgnd@TP}{toppanelcolor}{\replacecolor{bgndtoppanelcolor@TP}{#1}}
2527
2528 \define@key{bgnd@TP}{toppanelcolordef}{\definecolor{bgndtoppanelcolor@TP}#1}
2529
2530
2531 \define@key{bgnd@TP}{bottompanelcolor}{\replacecolor{bgndbottompanelcolor@TP}{#1}}
2532
2533 \define@key{bgnd@TP}{bottompanelcolordef}{\definecolor{bgndbottompanelcolor@TP}#1}
2534
2535
2536 \define@key{bgnd@TP}{leftpanelcolor}{\replacecolor{bgndleftpanelcolor@TP}{#1}}
2537
2538 \define@key{bgnd@TP}{leftpanelcolordef}{\definecolor{bgndleftpanelcolor@TP}#1}
2539
2540
2541 \define@key{bgnd@TP}{rightpanelcolor}{\replacecolor{bgndrightpanelcolor@TP}{#1}}
2542
2543 \define@key{bgnd@TP}{rightpanelcolordef}{\definecolor{bgndrightpanelcolor@TP}#1}
2544
2545
2546 \define@key{bgnd@TP}{toppanelheight}{\mklength@TP{\bgndtoppanelheight@TP}{#1}}
2547
2548 \define@key{bgnd@TP}{bottompanelheight}{\mklength@TP{\bgndbottompanelheight@TP}{#1}}
2549
2550 \define@key{bgnd@TP}{leftpanelwidth}{\mklength@TP{\bgndleftpanelwidth@TP}{#1}}
2551
2552 \define@key{bgnd@TP}{rightpanelwidth}{\mklength@TP{\bgndrightpanelwidth@TP}{#1}}
2553 % \end{macrocode}
2554 %
2555 % \subsubsection{Implementation of \cs{backgroundstyle}}
2556 %
2557 % In this box, the constructed background is stored. This box is placed behind every page at |\shipout| time by the kernel
2558 % (see below).
2559 % \begin{macrocode}
2560 \newbox\bgndbox@TP
2561 \setbox\bgndbox@TP\null% Default: Empty.
2562 % \end{macrocode}
2563 % |\mkpanels@TP{<command>}| adds the panels to the main page background. The main page background should be produced by the
2564 % command |<command>|, which is given the width and height of the central area as arguments.
2565 % \begin{macrocode}
2566 \newcommand{\mkpanels@TP}[1]%
2567 {%
2568 \ifthenelse{\boolean{hpanels@TP}}% `horizontal' panels?
2569 {% Yes. Vertically align top panel, center area with left and right panels, and bottom panel.
2570 \vbox% A vbox with \offinterlineskip allows to align the
2571 {% horizontal panels with the `background center'.
2572 \offinterlineskip
2573 \ifthenelse{\lengthtest{\bgndtoppanelheight@TP=0pt}}% Should top panel be created?
2574 {}% No.
2575 {%
2576 \hbox{{%
2577 \setcolor@TP{bgndtoppanelcolor@TP}%
2578 \rule{\bgndtoppanelwidth@TP}{\bgndtoppanelheight@TP}% Make horizontal colored area.
2579 }}%
2580 }%
2581 \hbox% Make `background center'.
2582 {%
2583 \ifthenelse{\lengthtest{\bgndleftpanelwidth@TP=0pt}}% Should left panel be created?
2584 {}% No.
2585 {{%
2586 \setcolor@TP{bgndleftpanelcolor@TP}%
2587 \rule{\bgndleftpanelwidth@TP}{\bgndleftpanelheight@TP}% Make vertical colored area.
2588 }}%
2589 #1% Make main background object.
2590 {\bgndtoppanelwidth@TP-\bgndleftpanelwidth@TP-\bgndrightpanelwidth@TP}% Calculate remaining space in the center.
2591 {\bgndleftpanelheight@TP}%
2592 \ifthenelse{\lengthtest{\bgndrightpanelwidth@TP=0pt}}% Should right panel be created?
2593 {}% No.
2594 {{%
2595 \setcolor@TP{bgndrightpanelcolor@TP}%
2596 \rule{\bgndrightpanelwidth@TP}{\bgndrightpanelheight@TP}% Make vertical colored area.
2597 }}%
2598 }% matches \hbox{%
2599 \ifthenelse{\lengthtest{\bgndbottompanelheight@TP=0pt}}% Should bottom panel be created?
2600 {}% No.
2601 {%
2602 \hbox
2603 {{%
2604 \setcolor@TP{bgndbottompanelcolor@TP}%
2605 \rule{\bgndbottompanelwidth@TP}{\bgndbottompanelheight@TP}% Make horizontal colored area.
2606 }}%
2607 }%
2608 }% matches \vbox{%
2609 }% matches \ifthenelse{\boolean{hpanels@TP}}{%
2610 {% No. Horizontally align left panel, center area with top and bottom panels, and right panel.
2611 \ifthenelse{\lengthtest{\bgndleftpanelwidth@TP=0pt}}% Should left panel be created?
2612 {}% No.
2613 {{%
2614 \setcolor@TP{bgndleftpanelcolor@TP}%
2615 \rule{\bgndleftpanelwidth@TP}{\bgndleftpanelheight@TP}% Make vertical colored area.
2616 }}%
2617 \vbox% A vbox with \offinterlineskip allows to align
2618 {% the horizontal panels with the center object.
2619 \offinterlineskip
2620 \ifthenelse{\lengthtest{\bgndtoppanelheight@TP=0pt}}% Should top panel be created?
2621 {}% No.
2622 {%
2623 \hbox%
2624 {{%
2625 \setcolor@TP{bgndtoppanelcolor@TP}%
2626 \rule{\bgndtoppanelwidth@TP}{\bgndtoppanelheight@TP}% Make horizontal colored area.
2627 }}%
2628 }%
2629 \hbox% Make main background object.
2630 {%
2631 #1%
2632 {\bgndtoppanelwidth@TP}%
2633 {\bgndleftpanelheight@TP-\bgndtoppanelheight@TP-\bgndbottompanelheight@TP}% Calculate space in the center.
2634 }%
2635 \ifthenelse{\lengthtest{\bgndbottompanelheight@TP=0pt}}% Should bottom panel be created?
2636 {}% No.
2637 {%
2638 \hbox%
2639 {{%
2640 \setcolor@TP{bgndbottompanelcolor@TP}%
2641 \rule{\bgndbottompanelwidth@TP}{\bgndbottompanelheight@TP}% Make horizontal colored area.
2642 }}%
2643 }%
2644 }% matches \vbox{%
2645 \ifthenelse{\lengthtest{\bgndrightpanelwidth@TP=0pt}}% Should right panel be created?
2646 {}% No.
2647 {{%
2648 \setcolor@TP{bgndrightpanelcolor@TP}%
2649 \rule{\bgndrightpanelwidth@TP}{\bgndrightpanelheight@TP}% Make vertical colored area.
2650 }}%
2651 }% matches second argument of \ifthenelse{\boolean{hpanels@TP}}
2652 }% matches \newcommand{\mkpanels@TP}[1]{%
2653 % \end{macrocode}
2654 %
2655 % For those background styles which use panels, |\initpanels@TP{<hpanels>}| sets all panel-related parameters depending on
2656 % the options and defaults. <hpanels> gives the background style dependent default of the hpanels option.
2657 % \begin{macrocode}
2658 \newcommand{\initpanels@TP}[1]%
2659 {%
2660 \ifx\hpanelsvalue@TP\empty% Has the hpanels parameter been given?
2661 \setboolean{hpanels@TP}{#1}% No; use default.
2662 \else
2663 \setboolean{hpanels@TP}{\hpanelsvalue@TP}% Yes; use parameter setting.
2664 \fi
2665 \ifthenelse{\boolean{hpanels@TP}}% `horizontal' panel direction?
2666 {% Yes. Horizontal panels are `outer', vertical panels are `inner'.
2667 \let\bgndtoppanelwidth@TP=\TPpagewidth% Full width for horizontal panels.
2668 \let\bgndbottompanelwidth@TP=\TPpagewidth%
2669 \ifthenelse{\equal{\bgndtoppanelheight@TP}{}}% Has the top panel height been set?
2670 {% No. Guess default.
2671 \ifx\toppanelcontents@TP\empty% Is the panel defined?
2672 \mklength@TP{\bgndtoppanelheight@TP}{\bgndtoppanelheight}% Use background-specific default.
2673 \else
2674 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2675 {% Yes.
2676 \calcvdimen@TP{\bgndtoppanelheight@TP}{\bgndtoppanelwidth@TP}% Measure the height of panel contents.
2677 {\toppanelcontents@TP}%
2678 \let\toppanelheight=\bgndtoppanelheight@TP% Overwrite panel settings.
2679 \let\toppanelwidth=\bgndtoppanelwidth@TP%
2680 \def\toppanelshift{0pt}% Top panel spans the whole upper screen.
2681 }
2682 {% No
2683 \mklength@TP{\bgndtoppanelheight@TP}{\toppanelheight}% Use panel-specific default.
2684 }%
2685 \fi
2686 }% matches \ifthenelse{\equal{\bgndtoppanelheight@TP}{}}
2687 {% Yes.
2688 \let\toppanelheight=\bgndtoppanelheight@TP% Overwrite panel settings - use user-supplied value.
2689 }
2690 \ifthenelse{\equal{\bgndbottompanelheight@TP}{}}% Has the bottom panel height been set?
2691 {% No. Guess default.
2692 \ifx\bottompanelcontents@TP\empty% Is the bottom panel defined?
2693 \mklength@TP{\bgndbottompanelheight@TP}{\bgndbottompanelheight}% Use background-specific default.
2694 \else
2695 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2696 {% Yes.
2697 \calcvdimen@TP{\bgndbottompanelheight@TP}{\bgndbottompanelwidth@TP}% Measure the height of panel contents.
2698 {\bottompanelcontents@TP}%
2699 \let\bottompanelheight=\bgndbottompanelheight@TP% Overwrite panel settings.
2700 \let\bottompanelwidth=\bgndbottompanelwidth@TP%
2701 \def\bottompanelshift{0pt}% Bottom panel spans the whole upper screen.
2702 }
2703 {% No
2704 \mklength@TP{\bgndbottompanelheight@TP}{\bottompanelheight}% Use panel-specific default.
2705 }%
2706 \fi
2707 }% matches \ifthenelse{\equal{\bgndbottompanelheight@TP}{}}
2708 {% Yes.
2709 \let\bottompanelheight=\bgndbottompanelheight@TP% Overwrite panel settings - use user-supplied value.
2710 }
2711 \mklength@TP{\bgndleftpanelheight@TP}% Calculate remaining space in the center.
2712 {\TPpageheight-\bgndtoppanelheight@TP-\bgndbottompanelheight@TP}%
2713 \let\bgndrightpanelheight@TP=\bgndleftpanelheight@TP% Height of left and right panels is equal.
2714 \ifthenelse{\equal{\bgndleftpanelwidth@TP}{}}% Has the left panel width been set?
2715 {% No. Guess default.
2716 \ifx\leftpanelcontents@TP\empty% Is the panel defined?
2717 \mklength@TP{\bgndleftpanelwidth@TP}{\bgndleftpanelwidth}% Use background-specific default.
2718 \else
2719 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2720 {% Yes.
2721 \calchdimen@TP{\bgndleftpanelwidth@TP}{\bgndleftpanelheight@TP}% Measure the `optimal' width of panel contents.
2722 {\leftpanelcontents@TP}%
2723 \let\leftpanelheight=\bgndleftpanelheight@TP% Overwrite panel settings.
2724 \let\leftpanelwidth=\bgndleftpanelwidth@TP%
2725 \let\leftpanelraise=\bgndbottompanelheight@TP% Left panel is raised above bottom panel.
2726 }
2727 {% No
2728 \mklength@TP{\bgndleftpanelwidth@TP}{\leftpanelwidth}% Use panel-specific default.
2729 }%
2730 \fi
2731 }% matches \ifthenelse{\equal{\bgndleftpanelwidth@TP}{}}
2732 {% Yes.
2733 \let\leftpanelwidth=\bgndleftpanelwidth@TP% Overwrite panel settings - use user-supplied value.
2734 }
2735 \ifthenelse{\equal{\bgndrightpanelwidth@TP}{}}% Has the right panel width been set?
2736 {% No. Guess default.
2737 \ifx\rightpanelcontents@TP\empty% Is the panel defined?
2738 \mklength@TP{\bgndrightpanelwidth@TP}{\bgndrightpanelwidth}% Use background-specific default.
2739 \else
2740 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2741 {% Yes.
2742 \calchdimen@TP{\bgndrightpanelwidth@TP}{\bgndrightpanelheight@TP}% Measure `optimal' width of panel contents.
2743 {\rightpanelcontents@TP}%
2744 \let\rightpanelheight=\bgndrightpanelheight@TP% Overwrite panel settings.
2745 \let\rightpanelwidth=\bgndrightpanelwidth@TP%
2746 \let\rightpanelraise=\bgndbottompanelheight@TP% Right panel is raised above bottom panel.
2747 }
2748 {% No
2749 \mklength@TP{\bgndrightpanelwidth@TP}{\rightpanelwidth}% Use panel-specific default.
2750 }%
2751 \fi
2752 }% matches \ifthenelse{\equal{\bgndrightpanelwidth@TP}{}}
2753 {% Yes.
2754 \let\rightpanelwidth=\bgndrightpanelwidth@TP% Overwrite panel settings - use user-supplied value.
2755 }
2756 }% matches \ifthenelse{\boolean{hpanels@TP}}
2757 {% No. Vertical panels are `outer', horizontal panels are `inner'.
2758 \let\bgndleftpanelheight@TP=\TPpageheight% Full height for vertical panels.
2759 \let\bgndrightpanelheight@TP=\TPpageheight%
2760 \ifthenelse{\equal{\bgndleftpanelwidth@TP}{}}% Has the left panel width been set?
2761 {% No. Guess default.
2762 \ifx\leftpanelcontents@TP\empty% Is the panel defined?
2763 \mklength@TP{\bgndleftpanelwidth@TP}{\bgndleftpanelwidth}% Use background-specific default.
2764 \else
2765 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2766 {% Yes.
2767 \calchdimen@TP{\bgndleftpanelwidth@TP}{\bgndleftpanelheight@TP}% Measure the `optimal' width of panel contents.
2768 {\leftpanelcontents@TP}%
2769 \let\leftpanelheight=\bgndleftpanelheight@TP% Overwrite panel settings.
2770 \let\leftpanelwidth=\bgndleftpanelwidth@TP%
2771 \def\leftpanelraise{0pt}% Left panel spans the whole left part of the screen.
2772 }
2773 {% No
2774 \mklength@TP{\bgndleftpanelwidth@TP}{\leftpanelwidth}% Use panel-specific default.
2775 }%
2776 \fi
2777 }% matches \ifthenelse{\equal{\bgndleftpanelwidth@TP}{}}
2778 {% Yes.
2779 \let\leftpanelwidth=\bgndleftpanelwidth@TP% Overwrite panel settings - use user-supplied value.
2780 }
2781 \ifthenelse{\equal{\bgndrightpanelwidth@TP}{}}% Has the right panel width been set?
2782 {% No. Guess default.
2783 \ifx\rightpanelcontents@TP\empty% Is the panel defined?
2784 \mklength@TP{\bgndrightpanelwidth@TP}{\bgndrightpanelwidth}% Use background-specific default.
2785 \else
2786 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2787 {% Yes.
2788 \calchdimen@TP{\bgndrightpanelwidth@TP}{\bgndrightpanelheight@TP}% Measure `optimal' width of panel contents.
2789 {\rightpanelcontents@TP}%
2790 \let\rightpanelheight=\bgndrightpanelheight@TP% Overwrite panel settings.
2791 \let\rightpanelwidth=\bgndrightpanelwidth@TP%
2792 \def\rightpanelraise{0pt}% Right panel spans the whole left part of the screen.
2793 }
2794 {% No
2795 \mklength@TP{\bgndrightpanelwidth@TP}{\rightpanelwidth}% Use panel-specific default.
2796 }%
2797 \fi
2798 }% matches \ifthenelse{\equal{\bgndrightpanelwidth@TP}{}}
2799 {% Yes.
2800 \let\rightpanelwidth=\bgndrightpanelwidth@TP% Overwrite panel settings - use user-supplied value.
2801 }
2802 \mklength@TP{\bgndtoppanelwidth@TP}% Calculate remaining space in the center.
2803 {\TPpagewidth-\bgndleftpanelwidth@TP-\bgndrightpanelwidth@TP}%
2804 \let\bgndbottompanelwidth@TP=\bgndtoppanelwidth@TP% Width of top and bottom panels is equal.
2805 \ifthenelse{\equal{\bgndtoppanelheight@TP}{}}% Has the top panel height been set?
2806 {% No. Guess default.
2807 \ifx\toppanelcontents@TP\empty% Is the panel defined?
2808 \mklength@TP{\bgndtoppanelheight@TP}{\bgndtoppanelheight}% Use background-specific default.
2809 \else
2810 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2811 {% Yes.
2812 \calcvdimen@TP{\bgndtoppanelheight@TP}{\bgndtoppanelwidth@TP}% Measure the height of panel contents.
2813 {\toppanelcontents@TP}%
2814 \let\toppanelheight=\bgndtoppanelheight@TP% Overwrite panel settings.
2815 \let\toppanelwidth=\bgndtoppanelwidth@TP%
2816 \let\toppanelshift=\bgndleftpanelwidth@TP% Shift top panel to the right of left panel.
2817 }
2818 {% No
2819 \mklength@TP{\bgndtoppanelheight@TP}{\toppanelheight}% Use panel-specific default.
2820 }%
2821 \fi
2822 }% matches \ifthenelse{\equal{\bgndtoppanelheight@TP}{}}
2823 {% Yes.
2824 \let\toppanelheight=\bgndtoppanelheight@TP% Overwrite panel settings - use user-supplied value.
2825 }
2826 \ifthenelse{\equal{\bgndbottompanelheight@TP}{}}% Has the bottom panel height been set?
2827 {% No. Guess default.
2828 \ifx\bottompanelcontents@TP\empty% Is the panel defined?
2829 \mklength@TP{\bgndbottompanelheight@TP}{\bgndbottompanelheight}% Use background-specific default.
2830 \else
2831 \ifthenelse{\boolean{autopanels@TP}}% Calculate panel dimensions?
2832 {% Yes.
2833 \calcvdimen@TP{\bgndbottompanelheight@TP}{\bgndbottompanelwidth@TP}% Measure the height of panel contents.
2834 {\bottompanelcontents@TP}%
2835 \let\bottompanelheight=\bgndbottompanelheight@TP% Overwrite panel settings.
2836 \let\bottompanelwidth=\bgndbottompanelwidth@TP%
2837 \let\bottompanelshift=\bgndleftpanelwidth@TP% Shift bottom panel to the right of left panel.
2838 }
2839 {% No
2840 \mklength@TP{\bgndbottompanelheight@TP}{\bottompanelheight}% Use panel-specific default.
2841 }%
2842 \fi
2843 }% matches \ifthenelse{\equal{\bgndbottompanelheight@TP}{}}
2844 {% Yes.
2845 \let\bottompanelheight=\bgndbottompanelheight@TP% Overwrite panel settings - use user-supplied value.
2846 }
2847 }% matches second argument of \ifthenelse{\boolean{hpanels@TP}}
2848 }% matches \newcommand{\initpanels@TP}[1]{
2849 % \end{macrocode}
2850 %
2851 % Make an `invisible' rule.
2852 % \begin{macrocode}
2853 \newcommand{\phantomrule@TP}[2]{\rule{0pt}{#2}\rule{#1}{0pt}}
2854 % \end{macrocode}
2855 %
2856 % Implementations of individual background styles.
2857 % \begin{macrocode}
2858 \newcommand{\setnonebgnd@TP}[1]% Implementation of the background style ``none''.
2859 {\global\setbox\bgndbox@TP=\null}% Just produce an empty box.
2860
2861
2862 \newcommand{\setplainbgnd@TP}[1]% Implementation of the background style ``plain''.
2863 {%
2864 \setkeys{bgnd@TP}{#1}% Evaluate parameters.
2865 \initpanels@TP{true}% Initialize panel parameters.
2866 \global\setbox\bgndbox@TP=\hbox{\mkpanels@TP{\phantomrule@TP}}% Make panels only.
2867 }%
2868
2869
2870 \newcommand{\setvgradientbgnd@TP}[1]% Implementation of the background style ``vgradient''.
2871 {%
2872 \setkeys{bgnd@TP}{#1}% Evaluate parameters.
2873 \initpanels@TP{false}% Initialize panel parameters.
2874 \global\setbox\bgndbox@TP=\hbox{\mkpanels@TP{\@@vgradrule@TP}}% Make background box.
2875 }
2876
2877 \newcommand{\sethgradientbgnd@TP}[1]% Implementation of the background style ``hgradient''.
2878 {%
2879 \setkeys{bgnd@TP}{#1}% Evaluate parameters.
2880 \initpanels@TP{true}% Initialize panel parameters.
2881 \global\setbox\bgndbox@TP=\hbox{\mkpanels@TP{\@@hgradrule@TP}}% Make background box.
2882 }
2883
2884
2885 \newcommand{\setdoublevgradientbgnd@TP}[1]% Implementation of the background style ``doublevgradient''.
2886 {%
2887 \setkeys{bgnd@TP}{#1}% Evaluate parameters.
2888 \initpanels@TP{false}% Initialize panel parameters.
2889 \global\setbox\bgndbox@TP=\hbox{\mkpanels@TP{\@@@@dblvgradrule@TP}}% Make background box.
2890 }
2891
2892
2893 \newcommand{\setdoublehgradientbgnd@TP}[1]% Implementation of the background style ``doublehgradient''.
2894 {%
2895 \setkeys{bgnd@TP}{#1}% Evaluate parameters.
2896 \initpanels@TP{true}% Initialize panel parameters.
2897 \global\setbox\bgndbox@TP=\hbox{\mkpanels@TP{\@@@@dblhgradrule@TP}}% Make background box.
2898 }
2899 % \end{macrocode}
2900 %
2901 % |\hpagecolor[<start>]{<end>}| is provided here for compatibility with background.sty from PPower4. It sets a horizontal
2902 % gradient background. See the PPower4 documentation on the meaning of the arguments (which is quite confusing).
2903 % \begin{macrocode}
2904 \providecommand{\hpagecolor}[2][]
2905 {%
2906 \ifthenelse{\equal{#1}{}}
2907 {\colorbetween{ppendcolor}{#2}{white}\backgroundstyle[startcolor=#2,endcolor=ppendcolor]{hgradient}}
2908 {\backgroundstyle[startcolor=#1,endcolor=#2]{hgradient}}%
2909 }
2910 % \end{macrocode}
2911 %
2912 % |\vpagecolor[<start>]{<end>}| is provided here for compatibility with background.sty from PPower4. It sets a vertical
2913 % gradient background. See the PPower4 documentation on the meaning of the arguments (which is quite confusing).
2914 % \begin{macrocode}
2915 \providecommand{\vpagecolor}[2][]
2916 {%
2917 \ifthenelse{\equal{#1}{}}
2918 {\colorbetween{ppendcolor}{#2}{white}\backgroundstyle[startcolor=#2,endcolor=ppendcolor]{vgradient}}
2919 {\backgroundstyle[startcolor=#1,endcolor=#2]{vgradient}}%
2920 }
2921 % \end{macrocode}
2922 %
2923 % \subsection{Panels}
2924 %
2925 % The following code is rather preliminary and provides only the very basics for constructing panels. If you're using a
2926 % document class or package which allows to do this or know how to achieve it using fancy headers, don't even consider
2927 % using the following.
2928 %
2929 % Some configurable panel parameters.
2930 %
2931 % Margin around panels (space [on all sides] between beginning of background and panel contents).
2932 % \begin{macrocode}
2933 \mklength@TP{\panelmargin}{\fboxsep}
2934 % \end{macrocode}
2935 % Dimensions of top panel. Note that parts or all of these dimensions might be overwritten by |\DeclarePanel*| or
2936 % using |\backgroundstyle| with specific settings.
2937 % \begin{macrocode}
2938 \newcommand{\toppanelwidth}{\TPpagewidth}% Width.
2939 \newcommand{\toppanelheight}{\TPpageheight/5}% Height.
2940 \newcommand{\toppanelshift}{0pt}% Space between left screen edge and left edge of top panel.
2941 % \end{macrocode}
2942 % Dimensions of bottom panel.
2943 % \begin{macrocode}
2944 \newcommand{\bottompanelwidth}{\TPpagewidth}% Width.
2945 \newcommand{\bottompanelheight}{\TPpageheight/5}% Height.
2946 \newcommand{\bottompanelshift}{0pt}% Space between left screen edge and left edge of bottom panel.
2947 % \end{macrocode}
2948 % Dimensions of left panel.
2949 % \begin{macrocode}
2950 \newcommand{\leftpanelwidth}{\TPpagewidth/5}% Width.
2951 \newcommand{\leftpanelheight}{\TPpageheight}% Height.
2952 \newcommand{\leftpanelraise}{0pt}% Space between bottom screen edge and bottom edge of left panel.
2953 % \end{macrocode}
2954 % Dimensions of right panel.
2955 % \begin{macrocode}
2956 \newcommand{\rightpanelwidth}{\TPpagewidth/5}% Width.
2957 \newcommand{\rightpanelheight}{\TPpageheight}% Height.
2958 \newcommand{\rightpanelraise}{0pt}% Space between bottom screen edge and bottom edge of left panel.
2959 % \end{macrocode}
2960 %
2961 % Some internal panel parameters.
2962 %
2963 % Storage for panel contents.
2964 % \begin{macrocode}
2965 \newcommand*{\toppanelcontents@TP}{}
2966 \newcommand*{\bottompanelcontents@TP}{}
2967 \newcommand*{\leftpanelcontents@TP}{}
2968 \newcommand*{\rightpanelcontents@TP}{}
2969 % \end{macrocode}
2970 %
2971 %
2972 % \subsubsection{Panel-specific user level commands}
2973 % \begin{macro}{\DeclarePanel}
2974 % |\DeclarePanel[<name>]{<pos>}{<contents>}| declares the contents |<contents>| of the panel at position |<pos>|.
2975 % Afterwards, on every page the panel contents are set in a parbox of dimensions and position specified by
2976 % |<pos>panelwidth|, |<pos>panelheight|, |\panelmargin| and |<pos>panelshift| for top and bottom panels and |<pos>panelraise| for
2977 % left and right panels. The parbox is constructed anew on every page, so all changes influencing panel contents or
2978 % parameters (like a |\thepage| in the panel contents) are respected.
2979 %
2980 % The panel contents are set in color |<pos>paneltextcolor|. There is another standard color |<pos>panelcolor|, which is
2981 % however not activated by |\DeclarePanel| but by selecting an appropriate background style.
2982 % Note that pages are constructed as follows: first the page background, then the panels, and then the page
2983 % contents. Hence, panels overwrite the background and the page contents overwrite the panels. The user is supposed to
2984 % make sure themselves that there is enough space left on the page for the panels (document class specific settings).
2985 % The panel declaration is global. A panel can be `undeclared' by using |\DeclarePanel{<pos>}{}|.
2986 %
2987 % There is a starred version which will (try to) automatically calculate the `flexible' dimension of each panel. For top
2988 % and bottom panels this is the height, for left and right panels this is the width. Make sure the panel contents are
2989 % `valid' at the time |\DeclarePanel*| is called so the calculation can be carried out in a meaningful way.
2990 % While the automatic calculation of the height of top and bottom panels is trivial (using |\settoheight|), there is a
2991 % sophisticated procedure for calculating a `good' width for the parbox containing the panel. Owing to limitations set
2992 % by TeX, there are certain limits to the sophistication of the procedure. For instance, any `whatsits' (specials (like
2993 % color changes), file accesses (like |\label|), or hyper anchors) or rules which are inserted directly in the vertical
2994 % list of the parbox `block' the analysis, so the procedure can't `see' past them (starting at the bottom of the box)
2995 % when analysing the contents of the parbox. The user should make sure such items are set in horizontal mode (by using
2996 % |\leavevmode| or enclosing stuff in boxes). Furthermore, only overfull and underfull hboxes which occur while setting
2997 % the parbox are considered when judging which width is `best'. This will reliably make the width large enough to
2998 % contain `wide' objects like tabulars, logos and buttons, but might not give optimal results for justified text.
2999 % vboxes occurring directly in the vbox are ignored.
3000 % Note further that hboxes with fixed width (made by |\hbox| to...) which occur directly in the vbox may disturb the
3001 % procedure, because the fixed width cannot be recovered. These hboxes will be reformatted with the width of the vbox,
3002 % generating an extremely large badness, unsettling the calculation of maximum badness. To avoid this such hboxes should
3003 % be either contained in a vbox or set in horizontal mode with appropriate glue at the end.
3004 %
3005 % If the optional argument <name> is given, the panel contents and (calculated) size will also be stored under the given
3006 % name, to be restored later with |\restorepanels|. This is nice for switching between different sets of panels.
3007 % \begin{macrocode}
3008 \newcommand{\DeclarePanel}{\@ifstar\auto@declarepanel@TP\declarepanel@TP}
3009
3010 \newcommand{\declarepanel@TP}[3][]% Non-starred version of \DeclarePanel.
3011 {%
3012 \expandafter\gdef\csname #2panelcontents@TP\endcsname{#3}% Just store panel contents.
3013 \ifthenelse{\equal{#1}{}}{}{\csname store#2panel@TP\endcsname{#1}}% If <name> was given, store panel parameters away.
3014 }%
3015
3016 % Store away top panel parameters.
3017 \newcommand{\storetoppanel@TP}[1]
3018 {%
3019 \expandafter\global\expandafter\let\csname toppanelcontents@TP@#1\endcsname\toppanelcontents@TP% Contents.
3020 \expandafter\global\expandafter\let\csname toppanelwidth@TP@#1\endcsname\toppanelwidth@TP% Width.
3021 \expandafter\global\expandafter\let\csname toppanelheight@TP@#1\endcsname\toppanelheight@TP% Height.
3022 \expandafter\global\expandafter\let\csname toppanelshift@TP@#1\endcsname\toppanelshift@TP% Raise.
3023 }
3024
3025 % Store away bottom panel parameters.
3026 \newcommand{\storebottompanel@TP}[1]
3027 {%
3028 \expandafter\global\expandafter\let\csname bottompanelcontents@TP@#1\endcsname\bottompanelcontents@TP%
3029 \expandafter\global\expandafter\let\csname bottompanelwidth@TP@#1\endcsname\bottompanelwidth@TP%
3030 \expandafter\global\expandafter\let\csname bottompanelheight@TP@#1\endcsname\bottompanelheight@TP%
3031 \expandafter\global\expandafter\let\csname bottompanelshift@TP@#1\endcsname\bottompanelshift@TP%
3032 }
3033
3034 % Store away left panel parameters.
3035 \newcommand{\storeleftpanel@TP}[1]
3036 {%
3037 \expandafter\global\expandafter\let\csname leftpanelcontents@TP@#1\endcsname\leftpanelcontents@TP%
3038 \expandafter\global\expandafter\let\csname leftpanelwidth@TP@#1\endcsname\leftpanelwidth@TP%
3039 \expandafter\global\expandafter\let\csname leftpanelheight@TP@#1\endcsname\leftpanelheight@TP%
3040 \expandafter\global\expandafter\let\csname leftpanelraise@TP@#1\endcsname\leftpanelraise@TP%
3041 }
3042
3043 % Store away right panel parameters.
3044 \newcommand{\storerightpanel@TP}[1]
3045 {%
3046 \expandafter\global\expandafter\let\csname rightpanelcontents@TP@#1\endcsname\rightpanelcontents@TP%
3047 \expandafter\global\expandafter\let\csname rightpanelwidth@TP@#1\endcsname\rightpanelwidth@TP%
3048 \expandafter\global\expandafter\let\csname rightpanelheight@TP@#1\endcsname\rightpanelheight@TP%
3049 \expandafter\global\expandafter\let\csname rightpanelraise@TP@#1\endcsname\rightpanelraise@TP%
3050 }
3051
3052
3053 \newcommand{\auto@declarepanel@TP}[2]% Starred version of \DeclarePanel.
3054 {\csname calc#1dimen@TP\endcsname{#2}\declarepanel@TP{#1}{#2}} % Calculate `optimal' dimension and store contents.
3055
3056 % Restore panel parameters stored away under a given name.
3057 \newcommand{\restorepanels}[1]
3058 {%
3059 \@ifundefined{toppanelcontents@TP@#1}{\global\let\toppanelcontents@TP\empty}
3060 {%
3061 \expandafter\global\expandafter\let\expandafter\toppanelcontents@TP\csname toppanelcontents@TP@#1\endcsname
3062 \expandafter\global\expandafter\let\expandafter\toppanelwidth@TP\csname toppanelwidth@TP@#1\endcsname
3063 \expandafter\global\expandafter\let\expandafter\toppanelheight@TP\csname toppanelheight@TP@#1\endcsname
3064 \expandafter\global\expandafter\let\expandafter\toppanelshift@TP\csname toppanelshift@TP@#1\endcsname
3065 }%
3066 \@ifundefined{bottompanelcontents@TP@#1}{\global\let\bottompanelcontents@TP\empty}
3067 {%
3068 \expandafter\global\expandafter\let\expandafter\bottompanelcontents@TP\csname bottompanelcontents@TP@#1\endcsname
3069 \expandafter\global\expandafter\let\expandafter\bottompanelwidth@TP\csname bottompanelwidth@TP@#1\endcsname
3070 \expandafter\global\expandafter\let\expandafter\bottompanelheight@TP\csname bottompanelheight@TP@#1\endcsname
3071 \expandafter\global\expandafter\let\expandafter\bottompanelshift@TP\csname bottompanelshift@TP@#1\endcsname
3072 }%
3073 \@ifundefined{leftpanelcontents@TP@#1}{\global\let\leftpanelcontents@TP\empty}
3074 {%
3075 \expandafter\global\expandafter\let\expandafter\leftpanelcontents@TP\csname leftpanelcontents@TP@#1\endcsname
3076 \expandafter\global\expandafter\let\expandafter\leftpanelwidth@TP\csname leftpanelwidth@TP@#1\endcsname
3077 \expandafter\global\expandafter\let\expandafter\leftpanelheight@TP\csname leftpanelheight@TP@#1\endcsname
3078 \expandafter\global\expandafter\let\expandafter\leftpanelraise@TP\csname leftpanelraise@TP@#1\endcsname
3079 }%
3080 \@ifundefined{rightpanelcontents@TP@#1}{\global\let\rightpanelcontents@TP\empty}
3081 {%
3082 \expandafter\global\expandafter\let\expandafter\rightpanelcontents@TP\csname rightpanelcontents@TP@#1\endcsname
3083 \expandafter\global\expandafter\let\expandafter\rightpanelwidth@TP\csname rightpanelwidth@TP@#1\endcsname
3084 \expandafter\global\expandafter\let\expandafter\rightpanelheight@TP\csname rightpanelheight@TP@#1\endcsname
3085 \expandafter\global\expandafter\let\expandafter\rightpanelraise@TP\csname rightpanelraise@TP@#1\endcsname
3086 }%
3087 }
3088 % \end{macrocode}
3089 % \end{macro}
3090 %
3091 % \subsubsection{Implementation of automatic dimension calculation}
3092 %
3093 % Interface to the horizontal and vertical calculation procedures. The first argument is being recalculated, the second
3094 % and third ones are parameters.
3095 % \begin{macrocode}
3096 \newcommand{\calctopdimen@TP}[1]{\calcvdimen@TP{\toppanelheight}{\toppanelwidth}{#1}}
3097 \newcommand{\calcbottomdimen@TP}[1]{\calcvdimen@TP{\bottompanelheight}{\bottompanelwidth}{#1}}
3098 \newcommand{\calcleftdimen@TP}[1]{\calchdimen@TP{\leftpanelwidth}{\leftpanelheight}{#1}}%
3099 \newcommand{\calcrightdimen@TP}[1]{\calchdimen@TP{\rightpanelwidth}{\rightpanelheight}{#1}}%
3100 % \end{macrocode}
3101 % Remove any contents which could mess up the box analysis.
3102 % \begin{macrocode}
3103 \newcommand{\panel@sanitize@TP}
3104 {%
3105 \let\hyperlink=\@secondoftwo
3106 \let\Acrobatmenu=\@secondoftwo
3107 }
3108 % \end{macrocode}
3109 % Calculate height of `horizontal' panel.
3110 % \begin{macrocode}
3111 \newcommand{\calcvdimen@TP}[3]
3112 {%
3113 \setbox\tempbox@TP=\hbox{\panel@sanitize@TP\@@mk@panel@TP{#2}{}{toppaneltextcolor}{#3}}% Set panel into a dummy box.
3114 \mklength@TP{#1}{\ht\tempbox@TP+\dp\tempbox@TP}% % Measure total height.
3115 }
3116 % \end{macrocode}
3117 % Calculate `optimal' width of `vertical panel.
3118 % \begin{macrocode}
3119 \newcommand{\calchdimen@TP}[3]
3120 {%
3121 \optwidth@TP{#1}{#2-\panelmargin*2}% Calculate `optimal' width of a parbox. Panel margins are respected.
3122 {.5\textwidth-\panelmargin*2}{\panelalignment#3}% .5\textwidth is the hardcoded absolute maximum width.
3123 \mklength@TP{#1}{#1+\panelmargin*2}%
3124 }
3125 % \end{macrocode}
3126 % User-configurable: Which `resolution' should be used when searching for `best' width?
3127 % \begin{macrocode}
3128 \newcommand{\optwidthsteps}{100}
3129 % \end{macrocode}
3130 % User-configurable: Which badness should be tolerated as `perfect' (stopping the search for a better one).
3131 % \begin{macrocode}
3132 \newcommand{\optwidthlinetolerance}{200}
3133 % \end{macrocode}
3134 %
3135 % Internal parameter: Badness of the parbox currently under consideration.
3136 % \begin{macrocode}
3137 \let\maxbadness@TP=\@tempcnta
3138 % \end{macrocode}
3139 % A hook to disable some commands which would be in the way while measuring things.
3140 % \begin{macrocode}
3141 \def\optwidthdisablecommands@TP
3142 {%
3143 \let\Hy@colorlink\@firstofone
3144 \let\Hy@endcolorlink\relax
3145 }
3146 % \end{macrocode}
3147 % Calculate `best' width of a parbox. The current algorithm will set the textual contents into parboxes of increasing
3148 % width, starting from 0pt and ending with the maximum width given, in |\optwidthsteps| steps. The `badness' of every
3149 % parbox is measured. If it is below the threshold defined by |\optwidthlinetolerance|, the process is stopped and the
3150 % found width accepted. If this doesn't happen, the width of the parbox with the least badness is returned.
3151 % \begin{macrocode}
3152 \newcommand{\optwidth@TP}[4]
3153 {%
3154 \setcounter{tmpcnta@TP}{0}% Initialize `probe counter' for box width.
3155 \let\best@cnt@TP=\empty% Initialize number of best `probe' so far.
3156 \def\bestbadness@TP{1000000}% Initialize badness of best `probe'.
3157 \setboolean{carryon@TP}{true}% Flag for breaking out of loop.
3158 \setlength{\tempdimb@TP}{#2}% Store maximal box height.
3159 \whiledo
3160 {\value{tmpcnta@TP}<\optwidthsteps\and\boolean{carryon@TP}}% Probes done or break of loop?
3161 {%
3162 \stepcounter{tmpcnta@TP}% Start next probe.
3163 \setbox\@tempboxa=\hbox% The trick with vbox/lastbox is to get the vbox
3164 {% produced by \parbox `immediately' into a box register.
3165 \optwidthdisablecommands@TP% Turn off some nasties not needed when measuring.
3166 \parbox[b]{(#3)/\optwidthsteps*\value{tmpcnta@TP}}% Make the next parbox.
3167 {\hfuzz\maxdimen\hbadness\@M\relax#4}%
3168 \global\setbox\tempbox@TP=\lastbox% ... and assign \tempbox@TP to it.
3169 }%
3170 \setlength{\tempdima@TP}{\ht\tempbox@TP+\dp\tempbox@TP}% Measure total height.
3171 \ifthenelse{\lengthtest{\tempdima@TP>\tempdimb@TP}}% If it exceeds the maximum height given, the box isn't
3172 {}% acceptable anyway.
3173 {%
3174 \calcmaxbadness@TP{\maxbadness@TP}{\tempbox@TP}% Calculate `worst badness' of any hbox appearing in parbox.
3175 \ifthenelse{\not\maxbadness@TP>\optwidthlinetolerance}% Below Threshold?
3176 {% Yes. Accept this width.
3177 \edef\best@cnt@TP{\thetmpcnta@TP}% Store this probe number.
3178 \setboolean{carryon@TP}{false}% Break loop.
3179 }
3180 {% No. Carry on.
3181 \ifthenelse{\maxbadness@TP<\bestbadness@TP}% Below lowest badness found so far?
3182 {% Yes. Store probe number.
3183 \edef\bestbadness@TP{\number\maxbadness@TP}% Store badness value.
3184 \edef\best@cnt@TP{\thetmpcnta@TP}% Store probe number.
3185 }
3186 {}% No. Try next probe.
3187 }% matches second argument of \ifthenelse{\not\maxbadness@TP>\optwidthlinetolerance}%
3188 }% matches second argument of \ifthenelse{\lengthtest{\tempdima@TP>\tempdimb@TP}}%
3189 }% matches \whiledo{\value{tmpcnta@TP}<\optwidthsteps\and\boolean{carryon@TP}}{%
3190 \ifx\best@cnt@TP\empty% Was _any_ badness below the initialization value found?
3191 \mklength@TP{#1}{#3}% No; return max width.
3192 \else
3193 \mklength@TP{#1}{(#3)/\optwidthsteps*\best@cnt@TP}% Yes; return width of best probe.
3194 \fi
3195 }% matches \newcommand{\optwidth@TP}[4]{%
3196 % \end{macrocode}
3197 %
3198 % Calculate maximal badness of any hbox occurring in a vbox.
3199 % \begin{macrocode}
3200 \newcommand{\calcmaxbadness@TP}[2]
3201 {%
3202 \let\@resultcnt@TP=#1% Here we store the result.
3203 \global\@resultcnt@TP=\z@\relax% Just in case no hbox occurs...
3204 \setlength{\@tempdima}{\wd#2}% This is the width to which every hbox is stretched for finding its badness.
3205 \setbox\@tempboxa=\vbox% A dummy vbox for recursively analysing the vbox contents using \lastbox
3206 {%
3207 \hfuzz\maxdimen\hbadness\@M
3208 \unvbox#2% `free' the contents of the vbox.
3209 \measureboxes@TP% Analyse `tail to head' using \lastbox.
3210 }%
3211 }
3212 % \end{macrocode}
3213 %
3214 % Recursively analyse vertical list using |\lastbox|, to find maximum badness of any contained hbox.
3215 % \begin{macrocode}
3216 \newcommand{\measureboxes@TP}%
3217 {%
3218 \unskip\unpenalty\unkern% This is a kluge for TeX, because there is no certain way of finding out whether there's a
3219 \unskip\unpenalty\unkern% penalty, glue or kern on the vertical list. \lastpenalty will give its value, but a
3220 \unskip\unpenalty\unkern% value of 0 might mean there was none or there was one of value 0.
3221 \unskip\unpenalty\unkern% This is different in eTeX. I might make a switch to a smarter solution.
3222 \unskip\unpenalty\unkern
3223 \unskip\unpenalty\unkern
3224 \unskip\unpenalty\unkern
3225 \unskip\unpenalty\unkern
3226 \unskip\unpenalty\unkern
3227 \unskip\unpenalty\unkern
3228 \setbox\@tempboxa=\lastbox% Grab last box.
3229 \ifhbox\@tempboxa% Was this an hbox?
3230 \setbox0=\hb@xt@\@tempdima{\unhbox\@tempboxa}% Yes. Reformat with given width.
3231 \ifnum\badness>\@resultcnt@TP% Badness larger than largest recorded badness?
3232 \global\@resultcnt@TP=\badness% Yes. Memorize.
3233 \fi
3234 \expandafter\measureboxes@TP% Recursive call.
3235 \else
3236 \ifvbox\@tempboxa% Was this a vbox?
3237 \expandafter\expandafter\expandafter\measureboxes@TP% Ignore, but execute recursive call.
3238 \fi
3239 \fi
3240 }
3241 % \end{macrocode}
3242 %
3243 %
3244 % \subsubsection{Actually typeset panels}
3245 % \begin{macrocode}
3246 \newcommand{\mk@toppanel@TP}% top panel
3247 {%
3248 \ifx\toppanelcontents@TP\empty% top panel specified?
3249 \else% Yes; create box with appropriate dimensions, background color and contents.
3250 \@mk@panel@TP{\toppanelwidth}{\toppanelheight}{toppaneltextcolor}{\toppanelcontents@TP}%
3251 \fi
3252 }
3253
3254 \newcommand{\mk@bottompanel@TP}% bottom panel
3255 {%
3256 \ifx\bottompanelcontents@TP\empty% bottom panel specified?
3257 \else% Yes; create box with appropriate dimensions, background color and contents.
3258 \@mk@panel@TP{\bottompanelwidth}{\bottompanelheight}{bottompaneltextcolor}{\bottompanelcontents@TP}%
3259 \fi
3260 }
3261
3262 \newcommand{\mk@leftpanel@TP}% left panel
3263 {%
3264 \ifx\leftpanelcontents@TP\empty% left panel specified?
3265 \else% Yes; create box with appropriate dimensions, background color and contents.
3266 \@mk@panel@TP{\leftpanelwidth}{\leftpanelheight}{leftpaneltextcolor}{\leftpanelcontents@TP}%
3267 \fi
3268 }
3269
3270 \newcommand{\mk@rightpanel@TP}% right panel
3271 {%
3272 \ifx\rightpanelcontents@TP\empty% right panel specified?
3273 \else% Yes; create box with appropriate dimensions, text color and contents.
3274 \@mk@panel@TP{\rightpanelwidth}{\rightpanelheight}{rightpaneltextcolor}{\rightpanelcontents@TP}%
3275 \fi
3276 }
3277
3278
3279 \newcommand{\@mk@panel@TP}[2]% Generate `standard' parbox parameters for panels.
3280 {%
3281 \@@mk@panel@TP{#1}{[#2-\panelmargin*2][s]}%
3282 }
3283
3284
3285 \@ifclassloaded{powersem}
3286 {%
3287 \newcommand{\panelalignment}{\sem@ptsize{\slide@ptsize}\large\normalsize}%
3288 }
3289 {%
3290 \newcommand{\panelalignment}% Justification for panels. This setting allows a certain amount of
3291 {\setlength{\rightskip}{0pt plus 20pt}}% `right-raggedness'. Leave empty for standard parbox formatting.
3292 }
3293
3294 % Make a panel box.
3295 \newcommand{\@@mk@panel@TP}[4]
3296 {%
3297 \vbox
3298 {%
3299 \offinterlineskip
3300 \kern\panelmargin% Top margin.
3301 \hbox
3302 {{%
3303 \ifthenelse{\boolean{instepwise@TP}}% Inside \stepwise, colors mat have been dimmed, leaking out to panels.
3304 {\usecolorset{stwcolors}}{}% Restore them, just in case.
3305 \color{#3}% Set panel text color.
3306 \kern\panelmargin% Left margin.
3307 \parbox[b]#2{#1-\panelmargin*2}% The parbox with the main panel contents.
3308 {%
3309 \normalfont
3310 \panelalignment#4%
3311 \hrule\@height\z@% The hrule makes sure the total height of this box can be measured appropriately.
3312 }%
3313 \kern\panelmargin% Right margin.
3314 }}%
3315 \kern\panelmargin% Bottom margin.
3316 }%
3317 }
3318 % \end{macrocode}
3319 %
3320 % \subsection{Navigation helpers}
3321 %
3322 % The following code is rather preliminary and provides only the very basics for making navigation buttons and such. If
3323 % you're using a package which allows to do this, don't even consider using the following.
3324 %
3325 % Some configurable button parameters.
3326 %
3327 % Space between button label and border.
3328 % \begin{macrocode}
3329 \newcommand{\buttonsep}{\fboxsep}
3330 % \end{macrocode}
3331 % Width of button frame.
3332 % \begin{macrocode}
3333 \newcommand{\buttonrule}{0pt}
3334 % \end{macrocode}
3335 % Horizontal displacement of button shadow.
3336 % \begin{macrocode}
3337 \newcommand{\buttonshadowhshift}{.3\fboxsep}
3338 % \end{macrocode}
3339 % Vertical displacement of button shadow.
3340 % \begin{macrocode}
3341 \newcommand{\buttonshadowvshift}{-.3\fboxsep}
3342 % \end{macrocode}
3343 %
3344 % Button-specific user level commands.
3345 %
3346 % \begin{macro}{\button}
3347 % |\button[<width>][<height>][<depth>][<alignment>]{<navcommand>}{<text>}| creates a button labelled |<text>| which executes
3348 % |<navcommand>| when pressed.
3349 % |<navcommand>| can be for instance |\Acrobatmenu{<command>}| or |\hyperlink{<target>}| (note that <navcommand> should take
3350 % one (more) argument specifying the sensitive area which is provided by |\button|).
3351 % If given, the optional parameters |<width>|, |<height>|, and |<depth>| give the width, height and depth, respectively, of
3352 % the framed area comprising the button (excluding the shadow, but including the frame). Default are the `real' width,
3353 % height and depth, respectively, of |<text>|, plus allowance for the frame.
3354 % If given, the optional parameter |<alignment>| (one of l,c,r) gives the alignment of |<text>| inside the button box (makes
3355 % sense only if |<width>| is given).
3356 % \begin{macrocode}
3357 \newcommand{\button}[1][0pt]% Collect first optional parameter.
3358 {%
3359 \mklength@TP\bt@width@TP{#1}% Store optional argument.
3360 \button@TP
3361 }
3362
3363 \newcommand{\button@TP}[1][0pt]% Collect second optional parameter.
3364 {%
3365 \mklength@TP\bt@height@TP{#1}% Store optional argument.
3366 \@button@TP
3367 }
3368
3369 \newcommand{\@button@TP}[1][0pt]% Collect third optional parameter.
3370 {%
3371 \mklength@TP\bt@depth@TP{#1}% Store optional argument.
3372 \@@button@TP
3373 }
3374
3375 \newcommand{\@@button@TP}[3][c]% Collect fourth optional and two mandatory parameters and proceed.
3376 {%
3377 \ifthenelse{\lengthtest{\bt@width@TP=0pt}}% <width> given?
3378 {\mklength@TP{\bt@width@TP}{\widthof{#3}}}% No. Calculate width of <text>.
3379 {\mklength@TP{\bt@width@TP}{\bt@width@TP-\buttonsep*2-\buttonrule*2}}% Yes. Calculate area left for <text>.
3380 \ifthenelse{\lengthtest{\bt@height@TP=0pt}}% <height> given?
3381 {\mklength@TP{\bt@height@TP}{\heightof{#3}}}% No. Calculate height of <text>.
3382 {\mklength@TP{\bt@height@TP}{\bt@height@TP-\buttonsep-\buttonrule}}% Yes. Calculate area left for <text>.
3383 \ifthenelse{\lengthtest{\bt@depth@TP=0pt}}% <depth> given?
3384 {\mklength@TP{\bt@depth@TP}{\depthof{#3}}}% No. Calculate depth of <text>.
3385 {\mklength@TP{\bt@depth@TP}{\bt@depth@TP-\buttonsep-\buttonrule}}% Yes. Calculate area left for <text>.
3386 \leavevmode% \rlap creates a `raw' hbox. So we get into horizontal mode.
3387 \rlap% Make shadow.
3388 {%
3389 \hspace*{\buttonshadowhshift}% Horizontal displacement.
3390 \raisebox{\buttonshadowvshift}% Vertical displacement.
3391 {%
3392 {% Inner group for correct color handling.
3393 \setcolor@TP{buttonshadowcolor}% Button shadow color.
3394 \rule% Create colored rectangular patch of appropriate dimensions.
3395 [-\bt@depth@TP-\buttonsep-\buttonrule]
3396 {\bt@width@TP+\buttonsep*2+\buttonrule*2}
3397 {\bt@height@TP+\bt@depth@TP+\buttonsep*2+\buttonrule*2}%
3398 }% matches inner group
3399 }% matches \raisebox{\buttonshadowvshift}{%
3400 }% matches \rlap{%
3401 \edef\o@fboxrule@TP{\the\fboxrule}% Preserve original definitions of \fbox parameters.
3402 \edef\o@fboxsep@TP{\the\fboxsep}%
3403 #2% Execute <navcommand>.
3404 {%
3405 \setlength{\fboxrule}{\buttonrule}% Set \fbox parameters for button frame.
3406 \setlength{\fboxsep}{\buttonsep}%
3407 \fcolorbox{buttonframecolor}{buttoncolor}% Create button frame with the right colors.
3408 {%
3409 \makebox[\bt@width@TP][#1]% Create box of correct width to contain <text>.
3410 {%
3411 \raisebox{0pt}[\bt@height@TP][\bt@depth@TP]% Create box of correct height and depth.
3412 {%
3413 \setlength{\fboxrule}{\o@fboxrule@TP}\setlength{\fboxsep}{\o@fboxsep@TP}% Restore fbox parameters.
3414 \setcolor@TP{buttontextcolor}#3% Produce <text>.
3415 }% matches \raisebox{0pt}[\bt@height@TP][\bt@depth@TP]{%
3416 }% matches \makebox[\bt@width@TP][#1]{%
3417 }% matches \fcolorbox{buttonframecolor}{buttoncolor}{%
3418 }% matches argument of <navcommand>.
3419 }% matches \newcommand{\@@button@TP}[3][c]{%
3420 % \end{macrocode}
3421 % \end{macro}
3422 %
3423 % Some predefined buttons.
3424 %
3425 % Size of predefined button symbols.
3426 % \begin{macrocode}
3427 \newcommand{\buttonsymbolsize}{\footnotesize}
3428 % \end{macrocode}
3429 % Define predefined button symbols.
3430 % \begin{macrocode}
3431 \@ifpackageloaded{amssymb}% AMS symbols available?
3432 {% Yes. Use `black' symbols.
3433 \newcommand{\buttonleftarrowsymbol}{{\buttonsymbolsize\boldmath\origmath{\blacktriangleleft}}}% `left' arrow.
3434 \newcommand{\buttonrightarrowsymbol}{{\buttonsymbolsize\boldmath\origmath{\blacktriangleright}}}% `right' arrow.
3435 \newcommand{\buttonbackarrowsymbol}{{\buttonsymbolsize\boldmath\origmath{\vartriangleleft}}}% `back' arrow.
3436 }
3437 {% No. Use replacements from standard set.
3438 \newcommand{\buttonleftarrowsymbol}{{\buttonsymbolsize\boldmath\origmath{\lhd}}}% `left' arrow.
3439 \newcommand{\buttonrightarrowsymbol}{{\buttonsymbolsize\boldmath\origmath{\rhd}}}% `right' arrow.
3440 \newcommand{\buttonbackarrowsymbol}{{\buttonsymbolsize\boldmath\origmath{\leftarrow}}}% `back' arrow.
3441 }
3442 % \end{macrocode}
3443 % Width of predefined buttons.
3444 % \begin{macrocode}
3445 \newcommand{\stdbuttonwidth}{\widthof{\buttonrightarrowsymbol\buttonrightarrowsymbol\buttonrightarrowsymbol}+4pt}
3446 % \end{macrocode}
3447 % Customizeable default: How to find the number of the current page?
3448 % \begin{macrocode}
3449 \newcommand{\currentpagevalue}{\value{page}}
3450 % \end{macrocode}
3451 %
3452 % Predefined button: last subpage of previous page.
3453 % \begin{macrocode}
3454 \newcommand{\backpagebutton}[1][\stdbuttonwidth]
3455 {%
3456 \button[#1]{\setcounter{tmpcnta@TP}{\currentpagevalue-1}\hyperlink{page.\thetmpcnta@TP}}
3457 {\buttonleftarrowsymbol\buttonleftarrowsymbol}%
3458 }
3459 % \end{macrocode}
3460 % Predefined button: previous step.
3461 % \begin{macrocode}
3462 \newcommand{\backstepbutton}[1][\stdbuttonwidth]
3463 {%
3464 \button[#1]{\Acrobatmenu{PrevPage}}
3465 {\buttonleftarrowsymbol}%
3466 }
3467 % \end{macrocode}
3468 % Predefined button: `undo action' (go back to whatever was before last action).
3469 % \begin{macrocode}
3470 \newcommand{\gobackbutton}[1][\stdbuttonwidth]
3471 {%
3472 \button[#1]{\Acrobatmenu{GoBack}}
3473 {\buttonbackarrowsymbol}%
3474 }
3475 % \end{macrocode}
3476 % Predefined button: next step.
3477 % \begin{macrocode}
3478 \newcommand{\nextstepbutton}[1][\stdbuttonwidth]
3479 {%
3480 \button[#1]{\Acrobatmenu{NextPage}}
3481 {\buttonrightarrowsymbol}%
3482 }
3483 % \end{macrocode}
3484 % Predefined button: first subpage of next page.
3485 % \begin{macrocode}
3486 \newcommand{\nextpagebutton}[1][\stdbuttonwidth]
3487 {%
3488 \button[#1]{\setcounter{tmpcnta@TP}{\currentpagevalue+1}\hyperlink{firstpage.\thetmpcnta@TP}}
3489 {\buttonrightarrowsymbol\buttonrightarrowsymbol}%
3490 }
3491 % \end{macrocode}
3492 % Predefined button: last subpage of next page.
3493 % \begin{macrocode}
3494 \newcommand{\nextfullpagebutton}[1][\stdbuttonwidth]
3495 {%
3496 \button[#1]{\setcounter{tmpcnta@TP}{\currentpagevalue+1}\hyperlink{page.\thetmpcnta@TP}}
3497 {\buttonrightarrowsymbol\buttonrightarrowsymbol\buttonrightarrowsymbol}%
3498 }
3499 % \end{macrocode}
3500 % Predefined button: toggle fullscreen mode.
3501 % \begin{macrocode}
3502 \newcommand{\fullscreenbutton}[1][\stdbuttonwidth]
3503 {%
3504 \button[#1]{\Acrobatmenu{FullScreen}}
3505 {\buttonrightarrowsymbol\buttonleftarrowsymbol}%
3506 }
3507 % \end{macrocode}
3508 %
3509 % \subsection{Set acrobat reader's page transition mode}
3510 %
3511 % Most of the following is snarfed from an email message of Marc van Dongen to the ppower4 mailing list on Thu, 7 Oct
3512 % 1999.
3513 % Thanks to Marc for his permission to include his code into this package.
3514 % \begin{macro}{\pagetransition}
3515 % |\pagetransition{<setting>}| is a generic command for setting the page transition with hyperref's |\hypersetup|. The
3516 % command is defined to a noop in case hyperref is not loaded.
3517 % \begin{macrocode}
3518 \ifthenelse{\boolean{display}}% Are dynamic features enabled?
3519 {% Yes.
3520 \newcommand{\pagetransition}[1]% Definition for preamble.
3521 {%
3522 \@ifpackageloaded{hyperref}% Can we use \hypersetup?
3523 {% Yes.
3524 \hypersetup{pdfpagetransition={#1}}% Set page transition with \hypersetup.
3525 }
3526 {% No. In this case, we can't set the page transition.
3527 \PackageWarning{texpower}
3528 {Package hyperref not loaded.\MessageBreak Page transition not set}%
3529 }%
3530 }% matches \newcommand{\pagetransition}[1]{%
3531 \AtBeginDocument% Definition for document body.
3532 {%
3533 \@ifpackageloaded{hyperref}% Can we use \hypersetup?
3534 {% Yes.
3535 \hypersetup{pdfpagetransition={}}% Make pagetransition setting (consistently) local to groups.
3536 \renewcommand{\pagetransition}[1]{\hypersetup{pdfpagetransition={#1}}}%
3537 }
3538 {% No. Disable page transitions.
3539 \PackageWarning{texpower}
3540 {Package hyperref not loaded.\MessageBreak Page transitions disabled}%
3541 \let\pagetransition=\@gobble
3542 }%
3543 }% matches \AtBeginDocument{%
3544 }% matches \ifthenelse{\boolean{display}}{%
3545 {\let\pagetransition=\@gobble}% No. Disable page transitions.
3546 % \end{macrocode}
3547 % \end{macro}
3548 % Some standard page transitions.
3549 % \begin{macrocode}
3550 \newcommand{\pageTransitionSplitHO}{\pagetransition{Split /Dm /H /M /O}}% Split Horizontally to the outside.
3551
3552 \newcommand{\pageTransitionSplitHI}{\pagetransition{Split /Dm /H /M /I}}% Split Horizontally to the inside.
3553
3554 \newcommand{\pageTransitionSplitVO}{\pagetransition{Split /Dm /V /M /O}}% Split Vertically to the outside.
3555
3556 \newcommand{\pageTransitionSplitVI}{\pagetransition{Split /Dm /V /M /I}}% Split Vertically to the inside.
3557
3558 \newcommand{\pageTransitionBlindsH}{\pagetransition{Blinds /Dm /H}}% Horizontal Blinds.
3559
3560 \newcommand{\pageTransitionBlindsV}{\pagetransition{Blinds /Dm /V}}% Vertical Blinds.
3561
3562 \newcommand{\pageTransitionBoxO}{\pagetransition{Box /M /O}}% Growing Box.
3563
3564 \newcommand{\pageTransitionBoxI}{\pagetransition{Box /M /I}}% Shrinking Box.
3565
3566 % argument must be number fom 0 to 360
3567 \newcommand{\pageTransitionWipe}[1]{\pagetransition{Wipe /Di #1}}% Wipe from one edge of the page to the facing edge.
3568
3569 \newcommand{\pageTransitionDissolve}{\pagetransition{Dissolve}}% Dissolve.
3570
3571 % argument must be number fom 0 to 360
3572 \newcommand{\pageTransitionGlitter}[1]{\pagetransition{Glitter /Di #1}}% Glitter from one edge to the facing edge.
3573
3574 \newcommand{\pageTransitionReplace}{\pagetransition{Replace}}% Simple Replace (the default).
3575 % \end{macrocode}
3576 %
3577 % \subsection{Set acrobat reader's automatic page advancing feature}
3578 %
3579 % |\pageDuration{<d>}| will force pages to be advanced automatically after |<d>| seconds when in full screen mode. The
3580 % effect starts on the current page and is undone by a group end or the command |\stopAdvancing|. |<d>| should be a
3581 % (fixed-point) number.
3582 %
3583 % Note a very strange behaviour of acrobat and acroread v4.05 and onwards: Automatic advancing is disabled unless
3584 % explicitly enabled by the ``advance every n seconds'' setting in the full screen dialogue. But in this case, all
3585 % pages not having any page duration setting will be advanced after |<n>| seconds. As another trap, at least in some
3586 % versions of acroread and acrobat, the maximum for |<n>| when set in the dialogue is 60 seconds. To make matters even
3587 % worse, there seems to be a (quite arbitrary) even for duration setting of pages: 546 seconds (about nine minutes).
3588 % This leaves you with the following options if you want to use automated advancing in your presentations (for animation
3589 % effects, say):
3590 %
3591 % \begin{enumerate}
3592 % \item You're using a version of acrobat or acroread predating 4.05 (or any other version where this misbehaviour
3593 % miraculously isn't present): All is well, nothing to do.
3594 %
3595 % \item You're using a `buggy' version where more than 60 seconds can be set as a value for |<n>| in the full screen dialogue
3596 % (I'm not sure whether such a beast exists; maybe both `features' coincide): Just activate automatic advancing in the
3597 % full screen dialogue and set an `infinite' number of seconds (3600, say). This value is masked by an explicit setting
3598 % using |\pageDuration|, so animations will still work.
3599 %
3600 % \item You're using a `buggy' version with a maximum dialogue setting of 60, but you're comfortable with your presentation
3601 % always advancing automatically at least every 60 seconds: Set |<n>| to 60 and proceed as above.
3602 %
3603 % \item You're using a `buggy' version with a maximum dialogue setting of 60 and you're comfortable with your presentation
3604 % always advancing automatically at least every 546 seconds (9.1 minutes): Give the package option ``nineminutes'' to
3605 % texpower. This will put an explicit duration setting of 546 seconds on every page (overridden by explicit settings
3606 % using |\pageDuration|). Set the advancing time in the full screen dialogue to anything; it will be ignored because every
3607 % page has an explicit setting.
3608 %
3609 % \item You're using a `buggy' version with a maximum dialogue setting of 60, you'd like your presentation to advance more
3610 % slowly than every 546 seconds and your version of acroread or acrobat miraculously doesn't have the upper bound of 546
3611 % seconds (which I've empirically discovered with acrobat 5.0 on Win NT): Put |\renewcommand{\infinitepageduration}{3600}|
3612 % in your preamble and see what happens. If the value is too high, acroread will go into fast forward mode or do other
3613 % strange things. Otherwise: Lucky you.
3614 %
3615 % \item You're using a `buggy' version with a maximum dialogue setting of 60, you'd like your presentation to advance more
3616 % slowly than every 546 seconds and your version of acroread or acrobat also has the upper bound of 546 seconds: In this
3617 % case you're out of luck. Of course you can try to get the guys at adobe to clean up this whole mess. Good luck with
3618 % that!
3619 % \end{enumerate}
3620 %
3621 % If |\infinitepageduration| is set to empty, then a page duration setting will appear only where |\pageDuration| was
3622 % used. Otherwise, every page without explicit setting gets a page duration of |\infinitepageduration|.
3623 % \begin{macrocode}
3624 \newcommand{\infinitepageduration}{}% Default: No page duration setting on every page.
3625
3626 \ifthenelse{\boolean{nineminutes@TP}}% If the option nineminutes is given, every page without explicit setting
3627 {\renewcommand{\infinitepageduration}{546}}{}% gets a setting of 546 seconds (9.1 minutes).
3628 % \end{macrocode}
3629 % Implementation of |\pageDuration|.
3630 % \begin{macrocode}
3631 \ifthenelse{\boolean{display}}% Are dynamic features enabled?
3632 {% Yes.
3633 \newcommand{\pageDuration}[1]% Definition for preamble.
3634 {%
3635 \@ifpackageloaded{hyperref}% Can we use \hypersetup?
3636 {% Yes.
3637 \hypersetup{pdfpageduration={#1}}% Set page duration with \hypersetup.
3638 }%
3639 {% No. In this case, we can't set the page duration.
3640 \PackageWarning{texpower}
3641 {Package hyperref not loaded.\MessageBreak Page duration not set}%
3642 }%
3643 }% matches \newcommand{\pageDuration}[1]{%
3644 \AtBeginDocument% Make sure this also works if texpower is loaded before hyperref.
3645 {%
3646 \@ifpackageloaded{hyperref}% Can we use \hypersetup?
3647 {% Yes.
3648 \edef\next{\noexpand\hypersetup{pdfpageduration={\infinitepageduration}}}%
3649 \next% Set default page duration.
3650 \renewcommand{\pageDuration}[1]{\hypersetup{pdfpageduration={#1}}}% Set page duration with \hypersetup.
3651 }%
3652 {% No. In this case, we can't set the page duration.
3653 \PackageWarning{texpower}
3654 {Package hyperref not loaded.\MessageBreak Page duration disabled}%
3655 \let\pageDuration=\@gobble
3656 }%
3657 }% matches \AtBeginDocument{%
3658 }% matches \ifthenelse{\boolean{display}}{%
3659 {\let\pageDuration=\@gobble}% No. Disable page duration.
3660 % \end{macrocode}
3661 % |\stopAdvancing| undoes any setting effected by |\pageDuration|.
3662 % \begin{macrocode}
3663 \newcommand{\stopAdvancing}
3664 {\edef\next{\noexpand\pageDuration{\infinitepageduration}}\next}% Reset to default page duration.
3665 % \end{macrocode}
3666 %
3667 % \subsection{TeXPower kernel}
3668 %
3669 % This area contains the `low level' implementation of TeXPowers central functions. Mainly, (La)TeX's |\shipout| and
3670 % |\output| routines are overloaded, adding some necessary functionality (duplication of page contents for incremental
3671 % page building; display of backgrounds and panels).
3672 % Also, the user command |\pause| is implemented here, using the kernel functions for saving and restoring page contents.
3673 %
3674 % The code for overloading the output routine is derived from Klaus Guntermanns texpause package which can be obtained
3675 % from the PPower4 Web site
3676 %
3677 % |http://www-sp.iti.informatik.tu-darmstadt.de/software/ppower4/|
3678 %
3679 % Thanks to Heiko Oberdiek for his suggestion how |\leaders| can be used to disable processing of whatsits in the
3680 % duplicated text.
3681 %
3682 % The code for overloading |\shipout| is derived from everyshi.sty with permission by Martin Schroeder.
3683 %
3684 % \subsubsection{Overload \cs{shipout}}
3685 %
3686 % Overloading is done at the beginning of the document just in case some other package messes with |\shipout|.
3687 % \begin{macrocode}
3688 \AtBeginDocument{\shipoutinit@TP}%
3689 % \end{macrocode}
3690 % Replace |\shipout| by own definition.
3691 % \begin{macrocode}
3692 \newcommand*{\shipoutinit@TP}
3693 {%
3694 \let\o@shipout@TP=\shipout% Memorize previous definition.
3695 \let\shipout\shipout@TP% Replace by own one.
3696 }%
3697 % \end{macrocode}
3698 % Our own version of |\shipout| takes the offered box and passes it to another routine for further inspection.
3699 % \begin{macrocode}
3700 \newcommand{\shipout@TP}
3701 {%
3702 \afterassignment\shipout@test@TP
3703 \global\setbox\@cclv= %
3704 }%
3705 % \end{macrocode}
3706 % If |\shipout| is called with an argument of the form |\box<n>|, then the box will have indeed been assigned to |\@cclv| at
3707 % the time |\shipout@test@TP| is called. In this case, |\shipout@output@TP| is called immediately. If |\shipout| is called
3708 % with an argument of the form |\vbox{...}|, then |\shipout@test@TP| is called at the beginning of the box definition,
3709 % \textbf{before} the box is assigned (this is a feature of |\afterassignment|). In this case, the call of
3710 % |\shipout@output@TP| is moved \textbf{after} the box definition using |\afetrgroup|, so that |\@cclv| is correctly
3711 % defined at the time |\shipout@output@TP| is executed.
3712 % \begin{macrocode}
3713 \newcommand{\shipout@test@TP}
3714 {%
3715 \ifvoid\@cclv\relax% Is the box assigned yet?
3716 \aftergroup\shipout@output@TP% No; defer execution of \shipout@output@TP.
3717 \else
3718 \shipout@output@TP% Yes; execute \shipout@output@TP immediately.
3719 \fi%
3720 }%
3721 % \end{macrocode}
3722 % The main part of our redefinition of |\shipout|.
3723 % \begin{macrocode}
3724 \newcommand{\shipout@output@TP}
3725 {%
3726 \shipout@hook@TP% Here, our own stuff is executed, manipulating \@cclv.
3727 \o@shipout@TP\box\@cclv% Execute original shipout routine.
3728 }%
3729 % \end{macrocode}
3730 %
3731 % \subsubsection{The kernel functions to be executed at \cs{shipout}}
3732 %
3733 % |\AtShipout{<code>}| will save |<code>| in a special place where it is executed at the time of the next |\shipout| (and
3734 % then deleted). Needless to say it should not produce any output. This is mainly for placing anchors in a controlled way
3735 % even inside incremental builds.
3736 % \begin{macrocode}
3737 \newcommand{\AtShipout}[1]
3738 {\expandafter\gdef\expandafter\at@shipout@once@TP\expandafter{\at@shipout@once@TP#1}}% Add argument to container.
3739 % \end{macrocode}
3740 % The container for |<code>| stored away by |\AtShipout|. This is placed on the page by the next |\shipout| and then deleted.
3741 % \begin{macrocode}
3742 \newcommand{\at@shipout@once@TP}{}
3743 % \end{macrocode}
3744 % Save the original definition of |\hyper@@anchor|.
3745 % \begin{macrocode}
3746 \AtBeginDocument{\global\let\o@hyper@@anchor\hyper@@anchor}
3747 % \end{macrocode}
3748 % The following makes sure that a hyper target |firstpage.<n>| is placed on the \textbf{first} subpage of every page.
3749 % \begin{macrocode}
3750 \@ifpackageloaded{hyperref}% Is hyperref loaded?
3751 {% Yes. Prepare hook.
3752 \newcommand{\do@insert@firstanchor@TP}% This is executed on the first subpage of every page.
3753 {\hypertarget{firstpage.\number\currentpagevalue}{}}% Create target.
3754 }
3755 {\newcommand{\do@insert@firstanchor@TP}{}}% No. Leave hook empty.
3756 % \end{macrocode}
3757 % This is executed on every subpage which is \textbf{not} the first one.
3758 % \begin{macrocode}
3759 \newcommand{\dont@insert@firstanchor@TP}{}%
3760 % \end{macrocode}
3761 % This is the hook itself which is executed on every page.
3762 % \begin{macrocode}
3763 \newcommand{\insert@firstanchor@TP}{\do@insert@firstanchor@TP}%
3764 % \end{macrocode}
3765 %
3766 % The hook executed at every call of |\shipout|. It executes the following tasks:
3767 % \begin{enumerate}
3768 % \item Filter out whatsits on duplicate pages.
3769 % \item Put page background at the `lowest' layer.
3770 % \item Put panels at the `second lowest' layer.
3771 % \item Execute |\AtShipout| code and place hypertarget |firstpage.<n>|.
3772 % \item Put |\box\@cclv| at `top' layer.
3773 % \end{enumerate}
3774 % \begin{macrocode}
3775 \newcommand{\shipout@hook@TP}
3776 {%
3777 \filterpage@TP% Filter out whatsits on duplicate pages.
3778 \setbox\@cclv=% Create `real' page box (which is later shipped out).
3779 \hbox{%
3780 \set@typeset@protect
3781 \raise\ht\@cclv\rlap% Place background box.
3782 {%
3783 \vtop to \TPpageheight
3784 {%
3785 \offinterlineskip
3786 \hrule\@height\z@\relax
3787 \kern -1truein\relax
3788 \kern -\voffset\relax
3789 \moveleft 1truein\hbox{\kern-\hoffset\copy\bgndbox@TP}%
3790 \vss
3791 \kern 1truein\relax
3792 \kern\voffset\relax
3793 }%
3794 }%
3795 \raise\ht\@cclv\rlap% Place `vertical' panels.
3796 {%
3797 \vtop to \TPpageheight
3798 {%
3799 \offinterlineskip
3800 \hrule\@height\z@\relax
3801 \kern -1truein\relax
3802 \kern -\voffset\relax
3803 \moveleft 1truein\hb@xt@\TPpagewidth
3804 {%
3805 \kern-\hoffset\raise\leftpanelraise\hbox{\mk@leftpanel@TP}%
3806 \hfill
3807 \raise\rightpanelraise\hbox{\mk@rightpanel@TP}%
3808 \kern\hoffset
3809 }%
3810 \vss
3811 \kern 1truein\relax
3812 \kern\voffset\relax
3813 }%
3814 }%
3815 \raise\ht\@cclv\rlap% Place `horizontal' panels.
3816 {%
3817 \vtop to \TPpageheight
3818 {%
3819 \offinterlineskip
3820 \hrule\@height\z@\relax
3821 \kern -1truein\relax
3822 \kern -\voffset\relax
3823 \moveleft 1truein\hbox{\kern-\hoffset\kern\toppanelshift\mk@toppanel@TP}%
3824 \vfill
3825 \moveleft 1truein\hbox{\kern-\hoffset\kern\bottompanelshift\mk@bottompanel@TP}%
3826 \kern 1truein\relax
3827 \kern\voffset\relax
3828 }%
3829 }%
3830 \raise\ht\@cclv\rlap
3831 {%
3832 \let\hyper@@anchor\o@hyper@@anchor% Reactivate hyper anchors.
3833 \insert@firstanchor@TP% Execute hook for creating target firstpage.<n>
3834 \ifshippingduplicate% Will further subpages follow?
3835 \global\let\insert@firstanchor@TP=\dont@insert@firstanchor@TP% Deactivate hook for next page.
3836 \else
3837 \global\let\insert@firstanchor@TP=\do@insert@firstanchor@TP% Reactivate hook for next page.
3838 \fi
3839 \at@shipout@once@TP% Execute code stored away by \AtShipout.
3840 }%
3841 \global\let\at@shipout@once@TP=\empty% Clear \AtShipout container.
3842 \box\@cclv
3843 }%
3844 }
3845 % \end{macrocode}
3846 %
3847 % \subsubsection{Implementation of `fixcolorstack' option}
3848 %
3849 % The problem is this: dvips (and some other tools) maintains a color stack when converting dvi to ps. Its function is
3850 % to always be able to correctly switch back to the previously used color even if there is a page break (and according
3851 % typesetting of headers etc) inbetween switching to another color and switching back.
3852 % This has many advantages (pdftex, for instance, which doesn't maintain a color stack, always has problems to restore
3853 % the correct text color after a page break).
3854 % In connection with TeXPower, however, this leads to problems. For controlling the color stack, push and pop commands
3855 % are inserted into the dvi using specials. At typesetting time, these specials are stored in the vertical list. When
3856 % page contents are copied, it might be that the copy contains an unequal number of push and pop commands, which will
3857 % make dvips's color stack go out of sync.
3858 % To remedy this, texpower maintains a `counter stack' which should contain all color stack commands issued on the
3859 % current page. Whenever a copied page is shipped out, appropriate color stack correction commands are issued to balance
3860 % the stack.
3861 % As this is necessary only for drivers implementing a color stack, the option is disabled for some drivers.
3862 % \begin{macrocode}
3863 \def\colorcorrections@TP{\relax}% The `counter stack' of color correction codes, reset at every \shipout.
3864
3865 \AtBeginDocument% Make sure to catch color.sty even if it's loaded after texpower.
3866 {%
3867 \ifthenelse{\boolean{fixcolorstack@TP}}% Was the fixcolorstack option given?
3868 {%
3869 \@ifundefined{VTeXversion}% Using vtex?
3870 {% No. Go on.
3871 \ifthenelse{\boolean{pdf}}% Producing pdf with pdftex?
3872 {% Yes. Color stack fixing unnecessary.
3873 \PackageWarning{texpower}
3874 {pdftex doesn't need color stack correction.\MessageBreak Option fixcolorstack disabled.}%
3875 }
3876 {% No. We need to add corrections for the color stack...
3877 \@ifpackageloaded{color}% ... but only if color.sty is loaded at all.
3878 {%
3879 \expandafter\def\expandafter\shipout@hook@TP\expandafter% Extend \shipout hook ...
3880 {\shipout@hook@TP\clearcolorcorrections@TP}% ... by a command to clear counter stack.
3881 %
3882 \newcommand{\clearcolorcorrections@TP}% The counter stack is cleared...
3883 {% ... on all `final' shipouts.
3884 \ifshippingduplicate
3885 \else
3886 \gdef\colorcorrections@TP{\relax}%
3887 \fi
3888 }
3889 % \end{macrocode}
3890 % Pray to god all drivers will support the following hacks...
3891 %
3892 % Save `original' definition of |\set@color|. Our redefinition of |\reset@color| needs to know which color is
3893 % being reset, so we add this as an argument. As it would be inconvenient to add a lot of tokens with
3894 % |\aftergroup|, we wrap everything in a control sequence.
3895 % \begin{macrocode}
3896 \expandafter\def\expandafter\o@set@color@TP\expandafter%
3897 {%
3898 \set@color% This is the `real' original definition.
3899 \expandafter\aftergroup\csname\current@color\endcsname% Add definition of \current@color.
3900 }%
3901
3902 \let\o@reset@color@TP=\reset@color% Save original definition of \reset@color.
3903 % \end{macrocode}
3904 % We need one command to `just push' a color on the stack. Pushing is done by |\set@color| in a driver-specific
3905 % way. But |\set@color| also creates an instance of |\reset@color| using |\aftergroup|. This instance is gobbled by
3906 % this hack, hopefully leaving only the driver-specific code to push a color. Of course, this will break
3907 % spectacularly if |\set@color| doesn't have the form |{<do something>\aftergroup\reset@color}|.
3908 % \begin{macrocode}
3909 \def\remove@resetcolor@TP#1\aftergroup\reset@color%
3910 {\def\pushcolor@TP##1{{\def\current@color{##1}#1}}}%
3911 %
3912 \expandafter\remove@resetcolor@TP\set@color
3913 % \end{macrocode}
3914 % |\reset@color| gets the color definition in the form of a control sequence (because of |\aftergroup|, see
3915 % above). We have to `unwrap' it before pushing.
3916 % \begin{macrocode}
3917 \def\pushcolorname@TP#1%
3918 {%
3919 \begingroup \escapechar\m@ne\xdef\@gtempa{\string#1}\endgroup% Get the coded tokens back (without \ ).
3920 \expandafter\pushcolor@TP\expandafter{\@gtempa}% ... and execute push.
3921 }%
3922 % \end{macrocode}
3923 % Our own definition of |\set@color| adds a |\reset@color| command for the color just set to |\colorcorrections@TP|.
3924 % \begin{macrocode}
3925 \def\set@color%
3926 {%
3927 \o@set@color@TP% `Original' definition of \set@color.
3928 \expandafter\@temptokena\expandafter{\colorcorrections@TP}% Add \o@reset@color@TP command at the front
3929 \xdef\colorcorrections@TP{\noexpand\o@reset@color@TP\the\@temptokena}% ... of \colorcorrections@TP.
3930 }
3931
3932 \def\reset@color#1% \reset@color now receives the name of the color.
3933 {%
3934 \expandafter\addpushtoccor@TP\colorcorrections@TP\@nil{#1}% Add a push command for this color to the front
3935 % of \colorcorrections@TP.
3936 \o@reset@color@TP% `Original' definition of \reset@color.
3937 }%
3938
3939 \def\addpushtoccor@TP#1#2\@nil#3% Add a push command for some color to the front of \colorcorrections@TP.
3940 {%
3941 \ifx\o@reset@color@TP#1% For efficiency, a push immediately followed by a reset cancel out.
3942 \gdef\colorcorrections@TP{#2}%
3943 \else
3944 \gdef\colorcorrections@TP{\pushcolorname@TP{#3}#1#2}% Otherwise, add the push to \colorcorrections@TP.
3945 \fi
3946 }%
3947 }% matches \@ifpackageloaded{color}
3948 {}% No changes needed if color.sty is not loaded.
3949 }% matches second argument of \ifthenelse{\boolean{pdf}}
3950 }% matches \@ifundefined{VTeXversion}
3951 {% Yes. Color stack fixing unnecessary.
3952 \PackageWarning{texpower}
3953 {vtex doesn't need color stack correction.\MessageBreak Option fixcolorstack disabled.}%
3954 }%
3955 }% matches \ifthenelse{\boolean{fixcolorstack@TP}}
3956 {}%
3957 }% matches \AtBeginDocument
3958 % \end{macrocode}
3959 %
3960 % \subsubsection{Kernel functions for overloading \cs{output}}
3961 %
3962 % This is the `inner kernel' which lies behind all dynamic effects.
3963 %
3964 % Some user level parameters.
3965 %
3966 % This flag can be evaluated at |\output| (resp. |\shipout|) time and tells whether the page being shipped out is a
3967 % duplicate page.
3968 % \begin{macrocode}
3969 \newif\ifshippingduplicate
3970 % \end{macrocode}
3971 % The command used to shipout a duplicate page.
3972 % \begin{macrocode}
3973 \providecommand{\TPeject}{\newpage}
3974 % \end{macrocode}
3975 %
3976 % Some internal registers to store away things.
3977 %
3978 % Contents of the page so far. These have to be duplicated on every subpage.
3979 % \begin{macrocode}
3980 \newbox\mempageconts@TP
3981 % \end{macrocode}
3982 % Footnotes on the page being duplicated. These have to be duplicated also.
3983 % \begin{macrocode}
3984 \newinsert\memfootins@TP
3985 % \end{macrocode}
3986 % Original definition of output routine.
3987 % \begin{macrocode}
3988 \newtoks\memoutput@TP
3989 % \end{macrocode}
3990 %
3991 % Save current page contents to a box.
3992 %
3993 % Which counters are to be restored to their original value after |\pause|?
3994 % \begin{macrocode}
3995 \def\cl@@ckptpause@TP{\@elt{page}}
3996 % \end{macrocode}
3997 % Save values of counters from |\cl@@ckptpause@TP| so that they can be restored with |\restorepausecounters@TP|.
3998 % \begin{macrocode}
3999 \def\savepausecounters@TP{%
4000 \begingroup
4001 \def\@elt##1{\global\csname c@##1\endcsname\the\csname c@##1\endcsname}%
4002 \xdef\restorepausecounters@TP{\cl@@ckptpause@TP}%
4003 \endgroup
4004 }
4005 % \end{macrocode}
4006 % User-level command to add a counter name to |\cl@@ckptpause@TP|.
4007 % \begin{macrocode}
4008 \newcommand{\pausesafecounter}[1]%
4009 {\expandafter\def\expandafter\cl@@ckptpause@TP\expandafter{\cl@@ckptpause@TP\@elt{#1}}}
4010 % \end{macrocode}
4011 % Setting |\pausesafecounter| for common classes
4012 % \begin{macrocode}
4013 \@ifclassloaded{seminar}{\pausesafecounter{slide}}{}
4014 % \end{macrocode}
4015 % Making some commands stepwise-aware (if we are in display modus) so we avoid duplicates
4016 % when not using the old aggressive/robust filtering of whatsits.
4017 % \begin{macrocode}
4018 \ifthenelse{\boolean{display}}{%
4019 \AtBeginDocument{\@ifpackageloaded{hyperref}{%
4020 \let\hyper@anchor@TP=\hyper@anchor
4021 \long\def\hyper@@anchor#1#2{%
4022 %%% \ifthenelse{\boolean{instepwise@TP}}%
4023 \ifthenelse{\boolean{instepwise@TP} \AND \NOT \boolean{oldfiltering@TP}}%
4024 {\ifthenelse{\NOT \boolean{instep@TP}}%
4025 {\ifthenelse{\value{step}=\value{firststep}}{\@hyper@@anchor#1\relax#2\relax}{}}%
4026 {\ifthenelse{\boolean{active} \AND \boolean{firstactivation}}%
4027 {\@hyper@@anchor#1\relax#2\relax}{}}% End \ifthenelse{\boolean{active} ...
4028 }% End \ifthenelse{\NOT \boolean{instep@TP}}
4029 {\@hyper@@anchor#1\relax#2\relax}% End \ifthenelse{\boolean{instepwise@TP}}
4030 }
4031 \let\hyper@anchorstart@TP=\hyper@anchorstart
4032 \def\hyper@anchorstart#1{%
4033 \ifthenelse{\boolean{instepwise@TP} \AND \NOT \boolean{oldfiltering@TP}}%
4034 {\ifthenelse{\NOT \boolean{instep@TP}}%
4035 {\ifthenelse{\value{step}=\value{firststep}}{\hyper@anchorstart@TP{#1}}{}}%
4036 {\ifthenelse{\boolean{active} \AND \boolean{firstactivation}}%
4037 {\hyper@anchorstart@TP{#1}}{}}% End \ifthenelse{\boolean{active} ...
4038 }% End \ifthenelse{\NOT \boolean{instep@TP}}
4039 {\hyper@anchorstart@TP{#1}}% End \ifthenelse{\boolean{instepwise@TP}}
4040 }
4041 }{}}% End \AtBeginDocument{\@ifpackageloaded{hyperref}{
4042 % Changing \protected@write to avoid duplicates in aux-file
4043 \let\protected@write@TP=\protected@write
4044 \long\def\protected@write#1#2#3{%
4045 \ifthenelse{\boolean{instepwise@TP} \AND \NOT \boolean{oldfiltering@TP}}%
4046 {\ifthenelse{\NOT \boolean{instep@TP}}%
4047 {\ifthenelse{\value{step}=\value{firststep}}{\protected@write@TP{#1}{#2}{#3}}{}}%
4048 {\ifthenelse{\boolean{active} \AND \boolean{firstactivation}}%
4049 {\protected@write@TP{#1}{#2}{#3}}{}}% End \ifthenelse{\boolean{active} ...
4050 }% End \ifthenelse{\NOT \boolean{instep@TP}}
4051 {\protected@write@TP{#1}{#2}{#3}}% End \ifthenelse{\boolean{instepwise@TP}}
4052 }%
4053 }{}% End \ifthenelse{\boolean{display}}
4054 % \end{macrocode}
4055 % Save the current page contents to the box |\mempageconts@TP| by overloading and triggering |\output|. Footnotes are also
4056 % saved. The saved page contents are used by |\pause| and all |\stepwise| variants for making duplicates of page contents.
4057 % \begin{macrocode}
4058 \def\save@TP
4059 {%
4060 \par% Always end current paragraph.
4061 \global\setbox\mempageconts@TP=\copy\voidb@x% Initialise \mempageconts@TP (suggested by Ross Moore).
4062 \savepausecounters@TP% Save counters.
4063 \memoutput@TP=\output% Make backup copy of output routine.
4064 \output={\global\setbox\mempageconts@TP=\box\@cclv}% Copy current page contents.
4065 \eject% Trigger now.
4066 \global\setbox\memfootins@TP=\copy\footins% Save footnotes.
4067 \global\skip\memfootins@TP=\skip\footins
4068 \global\count\memfootins@TP=\count\footins
4069 \global\dimen\memfootins@TP=\dimen\footins
4070 \output=\memoutput@TP% Restore output routine.
4071 }
4072 % \end{macrocode}
4073 %
4074 % \subsubsection{Kernel functions for re-inserting page contents}
4075 %
4076 % Used by |\pause| and also by variants of |\stepwise|.
4077 %
4078 % Filter file and anchor whatsits out of a duplicate page. Called by |\shipout@hook@TP|. Does nothing by default.
4079 % \begin{macrocode}
4080 \let\filterpage@TP\relax
4081 % \end{macrocode}
4082 % Interpretation of |\filterpage@TP| for duplicate pages. Assigned by |\outputduplicate@TP|.
4083 % \begin{macrocode}
4084 \newcommand{\filterwhatsits@TP}{%
4085 \ifthenelse{\boolean{oldfiltering@TP}}%
4086 {\global\setbox\@cclv=\hbox{\leaders\copy\@cclv\hskip\wd\@cclv}}% Old aggressive/robust filtering
4087 {}% No filtering - handled by \insertfilterwhatsits@TP and stepwise aware commands.
4088 }
4089 \newcommand{\insertfilterwhatsits@TP}{%
4090 \global\setbox\tempbox@TP=\hbox{\leaders\copy\tempbox@TP\hskip\wd\tempbox@TP}%
4091 }
4092 % \end{macrocode}
4093 % Insert saved page contents for the first time.
4094 % \begin{macrocode}
4095 \newcommand{\insertfirstduplicate@TP}
4096 {\unvcopy\mempageconts@TP}% Just output the vbox's contents.
4097 % \end{macrocode}
4098 %
4099 % Execute color correction stack accumulated when the fixcolor option is given.
4100 % \begin{macrocode}
4101 \newcommand{\do@colorcorrections@TP}
4102 {%
4103 {%
4104 \colorcorrections@TP% Execute color correction stack.
4105 \gdef\colorcorrections@TP{\relax}% Re-initialize for next round.
4106 }%
4107 }
4108 % \end{macrocode}
4109 %
4110 % Insert saved page contents for the second time (and all further times).
4111 % \begin{macrocode}
4112 \newcommand{\insertsecondduplicate@TP}
4113 {%
4114 \do@colorcorrections@TP% Execute color correction stack.
4115 \global\setbox\footins=\copy\memfootins@TP% Restore footnotes.
4116 \global\skip\footins=\skip\memfootins@TP
4117 \global\count\footins=\count\memfootins@TP
4118 \global\dimen\footins=\dimen\memfootins@TP
4119 \ifthenelse{\boolean{oldfiltering@TP}}%
4120 {\unvcopy\mempageconts@TP}%
4121 {\setbox\tempbox@TP=\vbox{\unvcopy\mempageconts@TP}%
4122 \insertfilterwhatsits@TP
4123 \copy\tempbox@TP%
4124 }
4125 }
4126 % \end{macrocode}
4127 %
4128 % Ship out a duplicated page.
4129 % \begin{macrocode}
4130 \newcommand{\outputduplicate@TP}
4131 {%
4132 \shippingduplicatetrue% This switch can be evaluated in panels or headers/footers.
4133 \global\let\filterpage@TP\filterwhatsits@TP% Filter out file whatsits when shipping out.
4134 \global\let\o@hyper@@anchor@TP\hyper@@anchor% Save definition of hyperref command for hyper anchors.
4135 \global\let\hyper@@anchor\@gobble% Disable hyper anchors on duplicate pages to avoid duplicate page anchors.
4136 \TPeject% Shipout page.
4137 \global\let\hyper@@anchor\o@hyper@@anchor@TP% Restore definition of hyperref command for hyper anchors.
4138 \global\let\filterpage@TP\relax% Disable whatsit filtering.
4139 \shippingduplicatefalse% Unset switch.
4140 }%
4141 % \end{macrocode}
4142 %
4143 % \subsubsection{Implementation of \cs{pause}}
4144 %
4145 % |\pause| ends the current paragraph, ships out the current page, starts a new page and copies whatever was on the
4146 % current page onto the new page, where typesetting is resumed. This will create the effect of a `pause' in the
4147 % presentation, i.e. the presentation stops because the current page ends at the point where the |\pause| command occurred
4148 % and is resumed at this point when the presenter switches to the next page.
4149 %
4150 % \begin{macrocode}
4151 \providecommand\pause% If pause.sty is loaded, the existing definition of \pause is not overwritten.
4152 {%
4153 \save@TP% Save contents of the page...
4154 \insertfirstduplicate@TP% ... and insert again.
4155 \ifthenelse{\boolean{display}}% Are dynamic features enabled?
4156 {% Yes.
4157 \outputduplicate@TP% Output page.
4158 \restorepausecounters@TP% Restore counters (page number).
4159 \insertsecondduplicate@TP% Reinsert saved contents.
4160 }
4161 {}%
4162 }%
4163 % \end{macrocode}
4164 %
4165 % \subsubsection{Implementing \cs{stepwise} and all functions surrounding it}
4166 %
4167 % General usage: |\stepwise{<contents>}|
4168 %
4169 % As of itself, |\stepwise| doesn't do very much. If |<contents>| contains one or more constructs of the form
4170 % |\step{<stepcontents>}|, the following happens:
4171 % \begin{enumerate}
4172 % \item The current paragraph is ended.
4173 %
4174 % \item The current contents of the page are saved (as with |\pause|).
4175 %
4176 % \item As many pages as there are |\step| commands in |<contents>| are produced.
4177 % Every page starts with what was on the current page when |\stepwise| started.
4178 % The first page also contains everything in |<contents>| which is not in |<stepcontents>| for any |\step| command.
4179 % The second page additionally contains the |<stepcontents>| for the first |\step| command, and so on, until all
4180 % |<stepcontents>| are displayed.
4181 %
4182 % \item When all |<stepcontents>| are displayed, |\stepwise| ends and typesetting is resumed (still on the current page).
4183 % \end{enumerate}
4184 %
4185 % This will create the effect that the |\step| commands are executed `step by step'.
4186 %
4187 % For a more detailed description of |\stepwise|, |\step| and their options, see below.
4188 %
4189 % Most of the registers, macros and environments defined in the following are part of the user interface, so no @s.
4190 %
4191 % \subsubsection{Command administration}
4192 %
4193 % \begin{macrocode}
4194 \newcommand{\@onlyinstepwise@TP}[1]
4195 {%
4196 \providecommand#1%
4197 {%
4198 \PackageError{texpower}%
4199 {Command \string#1 can be used only inside \string\stepwise}
4200 {%
4201 Commands like \string\step, \string\switch,
4202 \string\multistep\space or \string\overlays\MessageBreak
4203 can be used only inside the argument of a \string\stepwise\space variant.
4204 }%
4205 }%
4206 }
4207 % \end{macrocode}
4208 %
4209 % \subsubsection{Registers}
4210 %
4211 % The total number of |\step| commands occurring in |<contents>|.
4212 % \begin{macrocode}
4213 \newcounter{totalsteps}
4214 % \end{macrocode}
4215 % The number at which the counter step starts counting. Can be set in the optional argument of |\stepwise|.
4216 % \begin{macrocode}
4217 \newcounter{firststep}
4218 % \end{macrocode}
4219 % The number of the step currently being performed.
4220 % \begin{macrocode}
4221 \newcounter{step}
4222 % \end{macrocode}
4223 % The number of the current |\step| command (only useful inside |<stepcontents>|).
4224 % \begin{macrocode}
4225 \newcounter{stepcommand}
4226 % \end{macrocode}
4227 % The total number of |\step| commands which have been activated so far (this can differ from
4228 % |\value{step}| if the order of |\step| commands is changed via the optional argument of |\step|).
4229 % \begin{macrocode}
4230 \newcounter{stepsperformed}
4231 % \end{macrocode}
4232 % Is this |\step| command currently active for the first time? (only useful inside |<stepcontents>|).
4233 % \begin{macrocode}
4234 \newboolean{firstactivation}
4235 % \end{macrocode}
4236 % Is this |\step| command currently active? (only useful inside |<stepcontents>|).
4237 % \begin{macrocode}
4238 \newboolean{active}
4239 % \end{macrocode}
4240 %
4241 % \subsubsection{Custom commands for displaying step contents}
4242 % Some of them are selected by the switches |\boxedsteps| and |\nonboxedsteps|.
4243 %
4244 % Display |<stepcontents>| in a box.
4245 % \begin{macrocode}
4246 \newcommand{\displayboxed}
4247 {%
4248 \ifmmode % We need to distinguish between math and text mode.
4249 \expandafter\mathpalette\expandafter\math@db@TP % In math mode, the style has to be respected.
4250 \else
4251 \expandafter\text@db@TP
4252 \fi
4253 }
4254 \newcommand{\text@db@TP}[1]{\mbox{#1}} % In text mode, we just use an \mbox.
4255 \newcommand{\math@db@TP}[2]{\mbox{$\m@th#1{#2}$}} % In math mode, the style (#1) is inserted by \mathpalette.
4256 % \end{macrocode}
4257 %
4258 % Display |<stepcontents>| `as is'.
4259 % \begin{macrocode}
4260 \let\displayidentical=\@iden
4261 % \end{macrocode}
4262 %
4263 % \subsubsection[Custom commands for `hiding' stepcontents ...]%
4264 % {Custom commands for `hiding' stepcontents at the time
4265 % the corresponding \cs{step} is not active.}
4266 % Hiding stuff is not as easy as it seems...
4267 % Often, it is desirable that an appropriate amount of `space' is left where something is hidden, in case something
4268 % visible follows or the hidden stuff is part of an alignment structure. Even if this is not the case, completely
4269 % ignoring hidden text containing further |\step|'s can disturb the accounting of |\stepwise|, because |\step| numbers become
4270 % unaligned.
4271 % On the other hand, a lot of things which might be hidden (solitary |&|'s if the hidden text is part of an alignment
4272 % structure, for instance) execute an implicit group closing and don't like it at all to be enclosed in boxes, for
4273 % instance.
4274 % Because of these conflicting constraints, several methods for hiding content are provided. It is up to the user to
4275 % select the one most appropriate for each type of content, or to use the suggestions below as inspiration for own
4276 % definitions.
4277 %
4278 % Hide |<stepcontents>|, but display an appropriate amount of white space in the form of an appropriately dimensioned,
4279 % empty box.
4280 % \begin{macrocode}
4281 \newcommand{\hidephantom}[1]
4282 {%
4283 {% a group makes redefinitions local
4284 \leavevmode\phantom{#1}%
4285 % \end{macrocode}
4286 % |\phantom| normally produces an |\hbox|. |\leavevmode| makes it behave like |\mbox|.
4287 % \begin{macrocode}
4288 }%
4289 }
4290 % \end{macrocode}
4291 % Ignore |<stepcontents>| completely.
4292 % \begin{macrocode}
4293 \newcommand{\hideignore}[1]{}
4294 % \end{macrocode}
4295 %
4296 % Sometimes, ignoring |<stepcontents>| completely can lead to confusion of |\stepwise|'s accounting when |<stepcontents>|
4297 % contains further |\step| commands. |\hidesmartignore| produces no output, but executes |<stepcontents>| (in a box). Note
4298 % that this will lead to errors if for instance |<stepcontents>| contains a tabular character |&| from an alignment
4299 % structure.
4300 % \begin{macrocode}
4301 \newcommand{\hidesmartignore}[1]{\setbox\tempbox@TP=\vbox{#1}}
4302 % \end{macrocode}
4303 %
4304 % The command |\hidetext| makes its argument `invisible', but without putting it into a box, thus preserving line
4305 % breaks.
4306 % |\hidetext| needs the soul package to work. If it is not loaded, |\hidetext| is defined to be equal to |\hideboxed|.
4307 % Because of restrictions implied by the soul package, |\hidetext| is quite picky about the `regularity' of its
4308 % argument. That is, a lot of things will break when in the argument of |\hidetext|. See the documentation of the
4309 % soul package for hints how to prevent this.
4310 %
4311 % To allow soul to be loaded after texpower, we use |\AtBeginDocument|.
4312 % \begin{macrocode}
4313 \AtBeginDocument%
4314 {%
4315 \@ifpackageloaded{soul}{%
4316 \@ifpackagelater{soul}{2002/05/28}{
4317 \DeclareRobustCommand*\hidetext{%
4318 % \end{macrocode}
4319 % To prevent \cs{phantom} from inserting an hbox into the vertical list.
4320 % \begin{macrocode}
4321 \leavevmode
4322 \SOUL@setup
4323 % \end{macrocode}
4324 % Make current token `invisible'.
4325 % \begin{macrocode}
4326 \def\SOUL@everytoken{\phantom{\the\SOUL@token\SOUL@setkern\SOUL@charkern}}
4327 \def\SOUL@everyhyphen
4328 {%
4329 \discretionary
4330 {%
4331 \unkern
4332 % \end{macrocode}
4333 % Output an `invisible' hyphen if needed.
4334 % \begin{macrocode}
4335 \phantom{\SOUL@setkern\SOUL@hyphkern\char\hyphenchar\font}%
4336 }{}{}%
4337 }%
4338 \SOUL@%
4339 }%
4340 }{
4341 % \end{macrocode}
4342 % Too old soul package - encourage people to update.
4343 % \begin{macrocode}
4344 \PackageInfo{texpower}
4345 {Package soul too old.\MessageBreak Command \string\hidetext\space disabled}%
4346 % \end{macrocode}
4347 % Using \cs{hidephantom} which is a sorry excuse for \cs{hidetext}.
4348 % \begin{macrocode}
4349 \let\hidetext=\hidephantom
4350 }%
4351 }{
4352 \PackageInfo{texpower}
4353 {Package soul not loaded.\MessageBreak Command \string\hidetext\space disabled}%
4354 \let\hidetext=\hidephantom
4355 }%
4356 }
4357 % \end{macrocode}
4358 %
4359 % Helper command to switch to `dimmed' textcolor or mathcolor (if in math mode and colormath option is set).
4360 % \begin{macrocode}
4361 \ifthenelse{\boolean{colormath@TP}}{%
4362 \newcommand{\commitcolor@TP}
4363 % \end{macrocode}
4364 % Switch to mathcolor if in math mode, to textcolor otherwise.
4365 % \begin{macrocode}
4366 {\textcolor{\ifmmode mathcolor\else textcolor\fi}}
4367 }{
4368 \newcommand{\commitcolor@TP}{\textcolor{textcolor}}
4369 }
4370 % \end{macrocode}
4371 %
4372 % The command |\hidedimmed| doesn't really make its argument `invisible'. Instead, it dims all colors so the argument
4373 % `fades' into the background.
4374 % \begin{macrocode}
4375 \ifthenelse{\boolean{TPcolor}}{
4376 \newcommand{\hidedimmed}[1]{%
4377 % \end{macrocode}
4378 % Adding a group to make the color changes local.
4379 % \begin{macrocode}
4380 {
4381 % \end{macrocode}
4382 % Just in case we currently are in dimmed mode.
4383 % \begin{macrocode}
4384 \ifthenelse{\boolean{instepwise@TP}}{\usecolorset{stwcolors}}{}%
4385 \dimcolors
4386 \commitcolor@TP{#1}
4387 }
4388 }
4389 }{
4390 \let\hidedimmed=\displayidentical
4391 }
4392 % \end{macrocode}
4393 %
4394 % The command |\hidevanish| makes its argument `invisible' by switching to the background color. Of course, this only
4395 % works if the background is uniformly colored. If we don't use colors, we just use \cs{hidephantom}.
4396 % \begin{macrocode}
4397 \ifthenelse{\boolean{TPcolor}}{
4398 \newcommand{\hidevanish}[1]{\textcolor{\vanishcolor}{\vanishcolors#1}}
4399 }{
4400 \let\hidevanish=\hidephantom
4401 }
4402 % \end{macrocode}
4403 %
4404 % \subsubsection{Displaying and hiding of step contents}
4405 %
4406 % The displaying and hiding of |<stepcontents>| is controlled by the commands |\displaystepcontents| and
4407 % |\hidestepcontents|. The following switches define these to be either the boxed or the `as is' versions defined above.
4408 % \begin{macrocode}
4409 \newcommand{\boxedsteps} % Use boxed versions.
4410 {\let\displaystepcontents=\displayboxed\let\hidestepcontents=\hidephantom}
4411
4412 \newcommand{\nonboxedsteps} % Use nonboxed versions.
4413 {\let\displaystepcontents=\displayidentical\let\hidestepcontents=\hideignore}
4414 % \end{macrocode}
4415 % The default is to use the nonboxed versions. This can be changed in the optional argument of |\stepwise|.
4416 % \begin{macrocode}
4417 \nonboxedsteps
4418 % \end{macrocode}
4419 %
4420 % There is another command named |\activatestep| which controls what happens when a |\step| command is activated for the
4421 % first time. This is defined to do nothing by default.
4422 % \begin{macrocode}
4423 \let\activatestep=\displayidentical
4424 % \end{macrocode}
4425 %
4426 % The length |\highlightboxsep| gives the width of the frame around the box created by |\highlightboxed|.
4427 % \begin{macrocode}
4428 \newlength{\highlightboxsep}
4429 \setlength{\highlightboxsep}{.5\fboxsep}
4430 % \end{macrocode}
4431 %
4432 % |\highlightboxed{<text>}| puts |<text>| into an |\mbox| with coloured background if the colorhighlight option is set, and
4433 % into an |\fbox| otherwise. As this is meant as an interpretation of |\activatestep|, it is made sure that the resulting
4434 % box has the same dimensions as the argument (the outer frame may overlap surrounding text).
4435 % \begin{macrocode}
4436 \DeclareRobustCommand{\highlightboxed}
4437 {%
4438 \ifmmode% Check for math mode.
4439 \expandafter\mathpalette\expandafter\math@hb@TP% Math mode version needs to respect current style.
4440 \else
4441 \expandafter\text@hb@TP% Text mode version.
4442 \fi
4443 }
4444 % \end{macrocode}
4445 % Math mode version of |\highlightboxed|.
4446 % \begin{macrocode}
4447 \newcommand{\math@hb@TP}[2]{\text@hb@TP{$\m@th#1{#2}$}}
4448 % \end{macrocode}
4449 % The text mode version of |\highlightboxed| does the `real' work.
4450 % \begin{macrocode}
4451 \ifthenelse{\boolean{colorhighlight@TP}}% Color highlighting enabled?
4452 {% Yes; use a box with colored background.
4453 \newcommand{\text@hb@TP}[1]
4454 {%
4455 \makebox[\width-2\highlightboxsep]% Make the frame stick out at the sides.
4456 {%
4457 \setlength{\fboxsep}{\highlightboxsep}% Set frame size.
4458 \raisebox{0pt}[\height-\fboxsep][\depth-\fboxsep]% Make the frame stick out above and below.
4459 {\colorbox{highlightcolor}{#1}}% Make colored box containing <text>.
4460 }%
4461 }%
4462 }% matches \ifthenelse{\boolean{colorhighlight@TP}}
4463 {% No; use an \fbox.
4464 \newcommand{\text@hb@TP}[1]
4465 {%
4466 \makebox[\width-2\highlightboxsep-2\fboxrule]% Make the frame stick out at the sides.
4467 {%
4468 \setlength{\fboxsep}{\highlightboxsep}% Set frame size.
4469 \raisebox{0pt}[\height-\fboxsep-\fboxrule][\depth-\fboxsep-\fboxrule]% Make the frame stick out above and below.
4470 {\fbox{#1}}%% Make an fbox containing <text>.
4471 }%
4472 }%
4473 }% matches second argument of \ifthenelse{\boolean{colorhighlight@TP}}
4474 % \end{macrocode}
4475 %
4476 % |\highlighttext| is the counterpart of |\highlightboxed| for arbitrary text. It puts its argument on a colored background
4477 % without putting it into a box (i.e. line breaks and hyphenation still work) if the colorhighlight option is set, and
4478 % underlines otherwise. As this is meant as an interpretation of |\activatestep|, it is made sure that the resulting text
4479 % has the same dimensions as the argument (the outer frame may overlap surrounding text).
4480 % |\highlighttext| needs the soul package to work. If it is not loaded, |\highlighttext| is defined to do nothing.
4481 % Because of restrictions implied by the soul package, |\highlighttext| is quite picky about the `regularity' of its
4482 % argument. That is, a lot of things will break when in the argument of |\highlighttext|. See the documentation of the
4483 % soul package for hints how to prevent this.
4484 %
4485 % To allow soul to be loaded after texpower, we use |\AtBeginDocument|.
4486 % \begin{macrocode}
4487 \AtBeginDocument%
4488 {%
4489 \@ifpackageloaded{soul}% Can we use the soul package?
4490 {%
4491 \@ifpackagelater{soul}{2002/05/28}% Correct version?
4492 {% Yes. Let's define the necessary macros.
4493 \ifthenelse{\boolean{colorhighlight@TP}}% Color highlighting enabled?
4494 {% Yes; use a colored background.
4495 % This is implemented as an application of soul (modifying the code for underline). See the documentation of the
4496 % soul package for details on soul.
4497 \newlength{\SOUL@boxheight@TP}% Height of colored patch.
4498 \newlength{\SOUL@boxtotalheight@TP}% Total height of colored patch.
4499 \newlength{\SOUL@boxdepth@TP}% Depth of colored patch.
4500 \DeclareRobustCommand*\highlighttext
4501 {%
4502 \leavevmode% To prevent \smash from inserting an hbox into the vertical list.
4503 \SOUL@ulsetup% Underline initialization.
4504 \def\SOUL@preamble
4505 {%
4506 \setlength{\SOUL@boxdepth@TP}% \SOUL@uldepth is below the depth of any letter.
4507 {\SOUL@uldepth+\highlightboxsep}%
4508 \def\SOUL@uldepth{-\SOUL@boxheight@TP}% For correctly positioning the rule.
4509 \setlength{\SOUL@boxheight@TP}{\heightof{/}+\highlightboxsep}% Calculate `good' height.
4510 \setlength{\SOUL@boxtotalheight@TP}{\SOUL@boxdepth@TP+\SOUL@boxheight@TP}% Calculate total height.
4511 \def\SOUL@ulthickness{\SOUL@boxtotalheight@TP}% The thickness of the rule is the total height of the box.
4512 \smash% Make the left border of the colored patch.
4513 {%
4514 \llap{\color{highlightcolor}\rule[-\SOUL@boxdepth@TP]{\highlightboxsep}{\SOUL@boxtotalheight@TP}}%
4515 }%
4516 \SOUL@ulpreamble% Underline preamble.
4517 }%
4518 \def\SOUL@everytoken
4519 {%
4520 {%
4521 \setbox\tempbox@TP\hbox{\the\SOUL@token\SOUL@setkern\SOUL@charkern}%
4522 \dimen@ii\wd\tempbox@TP
4523 \smash{\rlap{\color{highlightcolor}\SOUL@ulleaders\hskip\dimen@ii}}%
4524 \unhbox\tempbox@TP%
4525 \smash{\rlap{\color{highlightcolor}\rule[-\SOUL@boxdepth@TP]{\highlightboxsep}{\SOUL@boxtotalheight@TP}}}%
4526 }%
4527 }%
4528 \def\SOUL@everyspace
4529 {%
4530 \cleaders\hbox{\smash{\color{highlightcolor}\rule[-\SOUL@boxdepth@TP]{1pt}{\SOUL@boxtotalheight@TP}}}%
4531 \hskip\spaceskip
4532 \smash{\llap{\color{highlightcolor}\rule[-\SOUL@boxdepth@TP]{\highlightboxsep}{\SOUL@boxtotalheight@TP}}}%
4533 }%
4534 \def\SOUL@everyhyphen
4535 {%
4536 \discretionary
4537 {\unkern
4538 \setbox4\hbox{\SOUL@setkern\SOUL@hyphkern\char\hyphenchar\font}%
4539 \smash{\rlap{\color{highlightcolor}\SOUL@ulleaders\hskip\wd4}}%
4540 \box4%
4541 \smash{\rlap{\color{highlightcolor}\rule[-\SOUL@boxdepth@TP]{\highlightboxsep}{\SOUL@boxtotalheight@TP}}}%
4542 }%
4543 {\smash{\llap{\color{highlightcolor}\rule[-\SOUL@boxdepth@TP]{\highlightboxsep}{\SOUL@boxtotalheight@TP}}}}%
4544 {}%
4545 }%
4546 \let\SOUL@everysyllable\empty
4547 \SOUL@%
4548 }%
4549 }% matches \ifthenelse{\boolean{colorhighlight@TP}}%
4550 {% No. Underline.
4551 \DeclareRobustCommand*\highlighttext
4552 {%
4553 \SOUL@ulsetup% We modify SOUL's standard definition of underlining, making sure
4554 \def\SOUL@everysyllable% the result uses no more space than the non-underlined text.
4555 {%
4556 {%
4557 \let\o@rlap@TP=\rlap
4558 \def\rlap####1{\setbox\@tempboxa\box\z@\smash{\o@rlap@TP{####1}}\setbox\z@\box\@tempboxa}%
4559 \SOUL@uleverysyllable
4560 }%
4561 }%
4562 \def\SOUL@everyspace
4563 {\cleaders\hbox{\smash{\vrule\@depth\SOUL@uldp\@height\SOUL@ulht\@width.5pt}}\hskip\spaceskip}%
4564 \def\SOUL@everyhyphen{\discretionary
4565 {\unkern
4566 \setbox4\hbox{\SOUL@setkern\SOUL@hyphkern\char\hyphenchar\font}%
4567 \smash{\rlap{\SOUL@ulleaders\hskip\wd4}\box4}}{}%
4568 {}}%
4569 \SOUL@%
4570 }%
4571 }% matches second argument of \ifthenelse{\boolean{colorhighlight@TP}}%
4572 }%
4573 {% No. Encourage people to update.
4574 \PackageInfo{texpower}
4575 {Package soul too old.\MessageBreak Command \string\highlighttext\space disabled}%
4576 \let\highlighttext=\@iden%
4577 }%
4578 }% matches \@ifpackageloaded{soul}
4579 {% No. In this case, there is no useful definition for \highlighttext.
4580 \PackageInfo{texpower}
4581 {Package soul not loaded.\MessageBreak Command \string\highlighttext\space disabled}%
4582 \let\highlighttext=\@iden
4583 }% matches second argument of \@ifpackageloaded{soul}
4584 }% matches \AtBeginDocument%
4585 % \end{macrocode}
4586 %
4587 % The command |\highlightenhanced| enhances all colors so the argument `stands out'.
4588 % \begin{macrocode}
4589 \ifthenelse{\boolean{TPcolor}}% Can we use colors at all?
4590 {% Yes.
4591 \newcommand{\highlightenhanced}[1]% Make argument appear in `enhanced' colors.
4592 {%
4593 {% A group makes the color changes local.
4594 \ifthenelse{\boolean{instepwise@TP}}{\usecolorset{stwcolors}}{}% Just in case we currently are in enhanced mode...
4595 \enhancecolors% Enhance colors.
4596 \commitcolor@TP{#1}% Switch on enhanced color.
4597 }%
4598 }%
4599 }
4600 {\let\highlightenhanced=\displayidentical}% No. Disable this command.
4601 % \end{macrocode}
4602 %
4603 % \subsubsection{Implementation of \cs{step}, \cs{switch} and relatives}
4604 %
4605 % |\step| takes two optional arguments for influencing the mode of activation, like this:
4606 %
4607 % |\step[<activatefirst>][<whenactive>]{<stepcontents>}|
4608 %
4609 % Both |<activatefirst>| and |<whenactive>| should be conditions in the syntax of the |\ifthenelse| command.
4610 %
4611 % |<activatefirst>| checks whether this |\step| is to be activated for the first time. The default value is
4612 % |\value{step}=\value{stepcommand}|. By using |\value{step}=<n>|, this |\step| can be forced to appear as the n'th one.
4613 %
4614 % |<whenactive>| checks whether this |\step| is to be considered active at all. The default behaviour is to check whether
4615 % this |\step| has been activated before (this is saved internally for every step).
4616 %
4617 % Both optional arguments allow two syntctical forms:
4618 % \begin{enumerate}
4619 % \item enclosed in square brackets |[...]| like explained above.
4620 %
4621 % \item enclosed in braces |(...)|.
4622 % In this case, |<activatefirst>| and |<whenactive>| are not treated as conditions in the sense
4623 % of |\ifthenelse|, but as conditionals like those used internally by \LaTeX. That means, |<activatefirst>| (when enclosed
4624 % in braces) can contain arbitrary \TeX code which then takes two arguments and expands to one of them, depending on
4625 % whether the condition is fulfilled or not fulfilled. For instance, |\step[<activatefirst>]{<stepcontents>}| could be
4626 % replaced by |\step(\ifthenelse{<activatefirst>}){<stepcontents>}|.
4627 % \end{enumerate}
4628 %
4629 % Internally, the default for the treatment of |<whenactive>| is |(\if@first@TP@true)|, where |\if@first@TP@true| is an
4630 % internal condition checking whether this |\step| has been activated before.
4631 %
4632 % If you wish to give the second optional argument but not the first, just write |\step[][<whenactive>]...|
4633 %
4634 % There are the following variants of |\step|. In all cases, the treatment of optional arguments for controlling
4635 % activation are the same as for |\step|:
4636 %
4637 % |\bstep[<activatefirst>][<whenactive>]{<stepcontents>}| Like |\step|, but is always boxed.
4638 %
4639 % |\switch[<activatefirst>][<whenactive>]{<from>}{<to>}| Instead of hiding and displaying |<stepcontents>|, switch from
4640 % |<from>| to |<to>|.
4641 %
4642 % |\vstep[<activatefirst>][<whenactive>]| Doesn't take an argument, but switches to `invisible' color.
4643 %
4644 % |\dstep[<activatefirst>][<whenactive>]| Doesn't take an argument, but switches to dimmed colors.
4645 %
4646 % |\steponce[<activatefirst>]{<stepcontents>}| Like |\step|, but goes inactive again in the subsequent step.
4647 %
4648 % The following variants act like their counterparts, but appear at the same time as the previous |\step| (or variant).
4649 %
4650 % |\restep[<activatefirst>][<whenactive>]{<stepcontents>}|
4651 %
4652 % |\rebstep[<activatefirst>][<whenactive>]{<stepcontents>}|
4653 %
4654 % |\reswitch[<activatefirst>][<whenactive>]{<from>}{<to>}|
4655 %
4656 % |\revstep[<activatefirst>][<whenactive>]|
4657 %
4658 % |\redstep[<activatefirst>][<whenactive>]|
4659 %
4660 % Optional argument handling.
4661 %
4662 % |\pickup@s@optargs@TP| reads the optional arguments of |\step| (or |\switch|, or relatives) and then calls |\@do@s@TP|.
4663 % \begin{macrocode}
4664 \newcommand{\pickup@s@optargs@TP}
4665 {%
4666 \@ifnextchar[%] Check for first optional argument in [...] syntax.
4667 {\f@brackstep@TP}%
4668 {%
4669 \@ifnextchar(%) Check for first optional argument in (...) syntax.
4670 {\f@parenstep@TP}
4671 {\f@brackstep@TP[]}% No optional argument given; call with empty argument in [...] syntax (default).
4672 }%
4673 }
4674
4675 \def\f@brackstep@TP[#1]% First optional argument was given in [...] syntax.
4676 {%
4677 \def\tmp@TP{#1}%
4678 \ifx\tmp@TP\empty% Optional argument empty?
4679 \def\f@step@TPcheck{\ifthenelse{\value{step}=\value{stepcommand}}}% Yes; use default.
4680 \else
4681 \def\f@step@TPcheck{\ifthenelse{#1}}% No; condition is defined via \ifthenelse.
4682 \fi
4683 \f@step@TP% Go on and check for second optional argument.
4684 }
4685
4686 \def\f@parenstep@TP(#1)% First optional argument was given in (...) syntax.
4687 {%
4688 \def\f@step@TPcheck{#1}% Save condition (given as argument).
4689 \f@step@TP% Go on and check for second optional argument.
4690 }
4691
4692 \newcommand{\f@step@TP}% Pick up the second optional argument.
4693 {%
4694 \@ifnextchar[%] Check for second optional argument in [...] syntax.
4695 {\s@brackstep@TP}
4696 {%
4697 \@ifnextchar(%) Check for second optional argument in (...) syntax.
4698 {\s@parenstep@TP}
4699 {\s@parenstep@TP(\if@first@TP@true)}% No second optional argument given;
4700 }% call with \if@first@TP@true in (...) syntax (default).
4701 }
4702
4703 \def\s@brackstep@TP[#1]% Second optional argument was given in [...] syntax.
4704 {%
4705 \def\s@step@TPcheck{\ifthenelse{#1}}% Condition is defined via \ifthenelse.
4706 \@do@s@TP% Go on.
4707 }
4708
4709 \def\s@parenstep@TP(#1)% Second optional argument was given in (...) syntax.
4710 {%
4711 \def\s@step@TPcheck{#1}% Save condition (given as argument).
4712 \@do@s@TP% Go on.
4713 }
4714 % \end{macrocode}
4715 %
4716 % The following are needed to switch between the `switch behaviour' and the `step behaviour' of |\@@switch@TP|, which
4717 % implements the functionality of both |\switch| and |\step|.
4718 % \begin{macrocode}
4719 \newcommand{\deactivate@inner@TP}% \switch behaviour.
4720 {%
4721 % \end{macrocode}
4722 % Both |\inner@display@TP| and |\inner@hide@TP| just expand to their argument.
4723 % \begin{macrocode}
4724 \let\inner@display@TP=\displayidentical%
4725 \let\inner@hide@TP=\displayidentical%
4726 }
4727
4728 \newcommand{\activate@inner@TP}% \step behaviour.
4729 {%
4730 % \end{macrocode}
4731 % Use the user interface macros |\displaystepcontents| and |\hidestepcontents|.
4732 % \begin{macrocode}
4733 \let\inner@display@TP=\displaystepcontents%
4734 \let\inner@hide@TP=\hidestepcontents%
4735 }
4736 % \end{macrocode}
4737 %
4738 % Implementation of |\step|.
4739 %
4740 % \begin{macrocode}
4741 \@onlyinstepwise@TP\step
4742 % \end{macrocode}
4743 % |\proper@step@TP| is the `real' implementation of |\step|. Most of the time, |\step| is defined to execute
4744 % |\proper@step@TP|.
4745 % \begin{macrocode}
4746 \newcommand{\proper@step@TP}{\let\@do@s@TP=\@step@TP\pickup@s@optargs@TP}
4747 % \end{macrocode}
4748 % |\@step@TP| implements the functionality of |\step| by calling |\@@switch@TP|, which points to |\@switch@TP| most
4749 % of the time.
4750 % \begin{macrocode}
4751 \newcommand{\@step@TP}[1]{\activate@inner@TP\@@switch@TP{#1}{#1}}
4752 % \end{macrocode}
4753 % Inside, |\@step@TP| executes |\@@switch@TP|, which is the implementation of the |\switch| command (see below).
4754 %
4755 % Implementation of |\switch|.
4756 %
4757 % \begin{macrocode}
4758 \@onlyinstepwise@TP\switch
4759 % \end{macrocode}
4760 % |\switch| works exactly like |\step|, but it takes \textbf{two} mandatory arguments and selects the first
4761 % if `not active', the second if `active'.
4762 %
4763 % |\proper@switch@TP| is the `real' implementation of |\switch|. Most of the time, |\switch| is defined to execute
4764 % |\proper@switch@TP|.
4765 % \begin{macrocode}
4766 \newcommand{\proper@switch@TP}{\deactivate@inner@TP\let\@do@s@TP=\@@switch@TP\pickup@s@optargs@TP}
4767 % \end{macrocode}
4768 %
4769 % |\if@first@TP@true| checks whether the |\switch| command number |\value{stepcommand}| has already been activated in this
4770 % |\stepwise| session and selects one of its arguments accordingly.
4771 % \begin{macrocode}
4772 \newcommand{\if@first@TP@true}[2]%
4773 {%
4774 \expandafter % \first@TP@<n> is set to \@undefined if \switch command number <n> has not yet been
4775 \ifx\csname first@TP@\the\c@stepcommand\endcsname\empty% activated and \empty otherwise.
4776 #1%
4777 \else
4778 #2%
4779 \fi
4780 }
4781 % \end{macrocode}
4782 %
4783 % |\switch| shouldn't change the status quo in AMSLaTeX's measuring pass in typesetting aligned formulae. To guarantee
4784 % this, we check whether AMSLaTeX is measuring with AMSLaTeX's |\ifmeasuring@|. When AMSLaTeX is not loaded, we provide
4785 % this check ourselves.
4786 % \begin{macrocode}
4787 \@ifundefined{ifmeasuring@}{\newif\ifmeasuring@}{}
4788 % \end{macrocode}
4789 %
4790 % |\@switch@TP| implements the functionality of |\switch|. Most of the time, |\@@switch@TP| (which is called after checking
4791 % for optional arguments) is defined to execute |\@switch@TP|.
4792 % \begin{macrocode}
4793 \newcommand{\@switch@TP}[2]
4794 {%
4795 \global\advance\c@stepcommand by 1\relax% This execution of \switch is counted.
4796 \setboolean{instep@TP}{true}% Set indicator.
4797 %
4798 % If the verbose option is set, type out some accounting information which can be used for debugging.
4799 \ifthenelse{\boolean{verbose@TP}}
4800 {%
4801 \PackageInfo{texpower}
4802 {Step: \the\c@step, Stepcommand: \the\c@stepcommand,\MessageBreak Stepsperformed: \the\c@stepsperformed}%
4803 }
4804 {}%
4805 %
4806 \f@step@TPcheck% Is this step to be activated? \f@step@TPcheck is defined by the first optional argument of \switch.
4807 {% Yes.
4808 \if@first@TP@true{}% For non-unique conditions given as optional argument or when \reswitch is used, it might happen
4809 {% that \first@TP@\value{stepcommand} is already set. In this case, don't advance the counter stepsperformed.
4810 \ifmeasuring@\else% Do nothing in AMSLaTeX's measuring pass for aligned equations.
4811 \global\expandafter\let\csname first@TP@\the\c@stepcommand\endcsname=\empty% Set \first@TP@\value{stepcommand}
4812 \fi
4813 \global\advance\c@stepsperformed by 1\relax% Advance the counter for `real' first activations.
4814 \gdef\current@step@TP{#2}%
4815 }%
4816 \setboolean{firstactivation}{true}% This switch can be tested in <stepcontents>, but also in <whenactive>.
4817 }
4818 {% No.
4819 \setboolean{firstactivation}{false}% This switch can be tested in <stepcontents>, but also in <whenactive>.
4820 }% End of \f@step@TPcheck
4821 %
4822 \let\o@afterstep@TP=\afterstep% We need to save the current definition of \afterstep.
4823 %
4824 \s@step@TPcheck% Is this step active? \s@step@TPcheck is defined by the second optional argument of \switch.
4825 {% Yes.
4826 \setboolean{active}{true}% Make this fact known to the user.
4827 \ifthenelse{\boolean{firstactivation}}
4828 {\inner@display@TP{\activatestep{#2}}}% `First' display of <stepcontents>.
4829 {\inner@display@TP{#2}}% Display <stepcontents>.
4830 }
4831 {% No.
4832 \setboolean{active}{false}% Make this fact known to the user.
4833 \let\afterstep=\@gobble% Don't execute \afterstep here.
4834 \ifthenelse{\boolean{firstactivation}}
4835 {\inner@hide@TP{\activatestep{#1}}}% Hide <stepcontents>, but with `first activation'.
4836 {\inner@hide@TP{#1}}% Hide <stepcontents>.
4837 }% End of \s@step@TPcheck
4838 %
4839 \let\afterstep=\o@afterstep@TP% Restore the definition of \afterstep.
4840 \setboolean{instep@TP}{false}% Set indicator.
4841 }% End of the definition of \@switch@TP.
4842 % \end{macrocode}
4843 %
4844 % |\restep| is identical with |\step|, but is displayed at the same time as the previous |\step|.
4845 % \begin{macrocode}
4846 \@onlyinstepwise@TP\restep
4847
4848 \newcommand{\proper@restep@TP}
4849 {%
4850 \global\advance\c@stepcommand by -1% This is done by simply counting \value{stepcommand} backwards.
4851 \proper@step@TP% Go on with \step.
4852 }
4853 % \end{macrocode}
4854 %
4855 % |\reswitch| is identical with |\switch|, but is displayed at the same time as the previous |\switch|.
4856 % \begin{macrocode}
4857 \@onlyinstepwise@TP\reswitch
4858
4859 \newcommand{\proper@reswitch@TP}
4860 {%
4861 \global\advance\c@stepcommand by -1% This is done by simply counting \value{stepcommand} backwards.
4862 \proper@switch@TP% Go on with \switch.
4863 }
4864 % \end{macrocode}
4865 %
4866 % |\bstep| is a variant of |\step| which is always boxed.
4867 % \begin{macrocode}
4868 \@onlyinstepwise@TP\bstep
4869
4870 \newcommand{\proper@bstep@TP}{\let\@do@s@TP=\@bstep@TP\pickup@s@optargs@TP}
4871 % \end{macrocode}
4872 % |\@bstep@TP| implements the functionality of |\bstep| by calling |\boxedsteps| and |\@step@TP|.
4873 % \begin{macrocode}
4874 \newcommand{\@bstep@TP}[1]{{\boxedsteps\@step@TP{#1}}}
4875 % \end{macrocode}
4876 %
4877 % |\rebstep| is identical with |\bstep|, but is displayed at the same time as the previous |\bstep|.
4878 % \begin{macrocode}
4879 \@onlyinstepwise@TP\rebstep
4880
4881 \newcommand{\proper@rebstep@TP}
4882 {%
4883 \global\advance\c@stepcommand by -1% This is done by simply counting \value{stepcommand} backwards.
4884 \proper@bstep@TP% Go on with \bstep.
4885 }
4886 % \end{macrocode}
4887 %
4888 % |\dstep| is a variant of |\step| which takes \textbf{no} argument, but switches colors to `dimmed'.
4889 %
4890 % Helper command to switch to `dimmed' textcolor or mathcolor (if in math mode and colormath option is set).
4891 % \begin{macrocode}
4892 \ifthenelse{\boolean{colormath@TP}}% Should we color math?
4893 {% Yes.
4894 \newcommand{\commitcolors@TP}
4895 {\color{\ifmmode mathcolor\else textcolor\fi}}% Switch to mathcolor if in math mode, to textcolor otherwise.
4896 }
4897 {% No.
4898 \newcommand{\commitcolors@TP}{\color{textcolor}}% Switch to textcolor.
4899 }
4900
4901 \@onlyinstepwise@TP\dstep
4902
4903 \newcommand{\proper@dstep@TP}{\deactivate@inner@TP\let\@do@s@TP=\@dstep@TP\pickup@s@optargs@TP}
4904
4905 \ifthenelse{\boolean{TPcolor}}% Can we use colors at all?
4906 {% Yes.
4907 \newcommand{\@dstep@TP}{\@@switch@TP{\dimcolors\commitcolors@TP}{\set@color}}
4908 }
4909 {\newcommand{\@dstep@TP}{\@@switch@TP{}{}}}% No. Disable this command.
4910 % \end{macrocode}
4911 %
4912 % |\redstep| is identical with |\dstep|, but is displayed at the same time as the previous |\dstep|.
4913 % \begin{macrocode}
4914 \@onlyinstepwise@TP\redstep
4915
4916 \newcommand{\proper@redstep@TP}
4917 {%
4918 \global\advance\c@stepcommand by -1% This is done by simply counting \value{stepcommand} backwards.
4919 \proper@dstep@TP% Go on with \dstep.
4920 }
4921 % \end{macrocode}
4922 %
4923 % |\vstep| is a variant of |\step| which takes \textbf{no} argument, but switches all colors to |\vanishcolor|.
4924 % \begin{macrocode}
4925 \@onlyinstepwise@TP\vstep
4926
4927 \newcommand{\proper@vstep@TP}{\deactivate@inner@TP\let\@do@s@TP=\@vstep@TP\pickup@s@optargs@TP}
4928
4929 \ifthenelse{\boolean{TPcolor}}% Can we use colors at all?
4930 {% Yes.
4931 \newcommand{\@vstep@TP}{\@@switch@TP{\vanishcolors\color{textcolor}}{\set@color}}
4932 }
4933 {\newcommand{\@vstep@TP}{\@@switch@TP{}{}}}% No. Disable this command.
4934 % \end{macrocode}
4935 %
4936 % |\revstep| is identical with |\vstep|, but is displayed at the same time as the previous |\vstep|.
4937 % \begin{macrocode}
4938 \@onlyinstepwise@TP\revstep
4939
4940 \newcommand{\proper@revstep@TP}
4941 {%
4942 \global\advance\c@stepcommand by -1% This is done by simply counting \value{stepcommand} backwards.
4943 \proper@vstep@TP% Go on with \vstep.
4944 }
4945 % \end{macrocode}
4946 %
4947 % |\steponce[<activatefirst>]{<stepcontents>}| is a variant of |\step| which is active only at the time of activation and
4948 % goes inactive again in the subsequent step.
4949 % \begin{macrocode}
4950 \@onlyinstepwise@TP\steponce
4951
4952 \newcommand{\proper@steponce@TP}
4953 {\@ifnextchar[{\brack@steponce@TP}{\@steponce@TP}}% Optional argument in square brackets?
4954
4955 \newcommand{\@steponce@TP}
4956 {%
4957 \@ifnextchar(%% Optional argument in parentheses?
4958 {\paren@steponce@TP}%
4959 {\brack@steponce@TP[]}% [] is the default if no optional argument is given.
4960 }
4961
4962 \def\brack@steponce@TP[#1]%
4963 {%
4964 \def\optarg@so@TP{[#1]}% Store optional argument for later re-insertion.
4965 \@@steponce@TP% Proceed.
4966 }%
4967
4968 \def\paren@steponce@TP(#1){\def\optarg@so@TP{(#1)}\@@steponce@TP}
4969 % \end{macrocode}
4970 % Main body of |\steponce|.
4971 % \begin{macrocode}
4972 \newcommand{\@@steponce@TP}[1]{\expandafter\step\optarg@so@TP[\boolean{firstactivation}]{#1}}
4973 % \end{macrocode}
4974 %
4975 % |\multistep*[<activatefirst>]{<n>}{<stepcontents>}| is a shorthand macro for executing several steps successively. In
4976 % fact, it would better be called |\multiswitch|, because its functionality is based on |\switch|, it only acts like a
4977 % (simplified) |\step| command which is executed `several times'.
4978 % |\multistep[<activatefirst>]{<n>}{<stepcontents>}| expands to a sequence of |<n>| commands of the form
4979 % |\switch[<activatefirst>][\boolean{firstactivation}]{}{<stepcontents>}|
4980 % with the effect that |<stepcontents>| is executed |<n>| times at different iterations of |\stepwise|. Note that
4981 % |[<activatefirst>]| can also have the form |(<activatefirst>)|, as usual for |\switch|.
4982 % Because of the second optional argument |[\boolean{firstactivation}]|, only one instance of |<stepcontents>| is displayed
4983 % at a time.
4984 % Inside |<stepcontents>|, a counter substep can be evaluated which tells the number of the current instance.
4985 % In the starred form, the optional argument |[\boolean{firstactivation}]| is left out for the very last instance, so the
4986 % last instance of |<stepcontents>| stays visible.
4987 %
4988 % New counter for the number of the current substep.
4989 % \begin{macrocode}
4990 \newcounter{substep}
4991 % \end{macrocode}
4992 % User interface for |\multistep|.
4993 % \begin{macrocode}
4994 \@onlyinstepwise@TP\multistep
4995
4996 \newcommand{\proper@multistep@TP}
4997 {%
4998 \let\ns@ms@TP=\normalstep@ms@TP% Placeholder for `every step but the last one'.
4999 \let\nshook@ms@TP=\relax% These hooks are used by \movie.
5000 \let\lshook@ms@TP=\relax
5001 \@ifstar% Starred version?
5002 {%
5003 \let\ls@ms@TP=\laststep@ms@TP% Last step acts differently.
5004 \multistep@TP% Collect optional argument and proceed.
5005 }
5006 {%
5007 \let\ls@ms@TP=\normalstep@ms@TP% Last step acts like all other steps.
5008 \multistep@TP% Collect optional argument and proceed.
5009 }%
5010 }
5011
5012 \newcommand{\multistep@TP}% Collect optional argument.
5013 {\@ifnextchar[{\brack@multistep@TP}{\@multistep@TP}}% Optional argument in square brackets?
5014
5015 \newcommand{\@multistep@TP}
5016 {%
5017 \@ifnextchar(%% Optional argument in parentheses?
5018 {\paren@multistep@TP}%
5019 {\brack@multistep@TP[]}% [] is the default if no optional argument is given.
5020 }
5021
5022 \def\brack@multistep@TP[#1]%
5023 {%
5024 \def\optarg@ms@TP{[#1]}% Store optional argument for later re-insertion.
5025 \@@multistep@TP% Proceed.
5026 }%
5027
5028 \def\paren@multistep@TP(#1){\def\optarg@ms@TP{(#1)}\@@multistep@TP}
5029
5030 % \end{macrocode}
5031 % Execute one step.
5032 % \begin{macrocode}
5033 \newcommand{\normalstep@ms@TP}[1]
5034 {%
5035 \expandafter\switch\optarg@ms@TP% Re-insert optional argument.
5036 [\boolean{firstactivation}]{}{#1}% `normal' steps appear only once.
5037 }
5038
5039 \newcommand{\laststep@ms@TP}[1]
5040 {\expandafter\switch\optarg@ms@TP{}{#1}}% In the starred version, the last step doesn't disappear.
5041 % \end{macrocode}
5042 % Main body of |\multistep|.
5043 % \begin{macrocode}
5044 \newcommand{\@@multistep@TP}[2]
5045 {%
5046 \setcounter{substep}{0}% Initialize substep counter.
5047 \whiledo{\value{substep}<#1}% Iterate <n> times.
5048 {%
5049 \stepcounter{substep}%
5050 \ifthenelse{\value{substep}=#1}% Last step?
5051 {\ls@ms@TP{\lshook@ms@TP#2}}% Execute single step (together with \movie hooks).
5052 {\ns@ms@TP{\nshook@ms@TP#2}}%
5053 }%
5054 }
5055 % \end{macrocode}
5056 %
5057 % |\movie*[<activatefirst>]{<n>}{<dur>}[<stop>]{<stepcontents>}| works like |\multistep|, but between |\steps|, pages are
5058 % advanced automatically every |<dur>| seconds.
5059 % The additional optional argument |<stop>| gives the code (default: |\stopAdvancing|) which stops the animation.
5060 % User interface for |\movie|.
5061 % \begin{macrocode}
5062 \@onlyinstepwise@TP\movie
5063
5064 \newcommand{\proper@movie@TP}
5065 {%
5066 \let\ns@ms@TP=\normalstep@ms@TP% Placeholder for `every step but the last one'.
5067 \def\nshook@ms@TP{\afterstep{\pageDuration{\dur@ms@TP}}}% Page duration to be used between steps.
5068 \def\lshook@ms@TP{\afterstep{\end@ms@TP}}% Page duration setting after last step.
5069 \@ifstar% Starred version?
5070 {%
5071 \let\ls@ms@TP=\laststep@ms@TP% Last step acts differently.
5072 \movie@TP% Collect optional argument and proceed.
5073 }
5074 {%
5075 \let\ls@ms@TP=\normalstep@ms@TP% Last step acts like all other steps.
5076 \movie@TP% Collect optional argument and proceed.
5077 }%
5078 }
5079
5080 \newcommand{\movie@TP}% Collect optional argument.
5081 {\@ifnextchar[{\brack@movie@TP}{\@movie@TP}}% Optional argument in square brackets?
5082
5083 \newcommand{\@movie@TP}
5084 {\@ifnextchar({\paren@movie@TP}{\brack@movie@TP[]}}% Optional argument in parentheses?
5085
5086 \def\brack@movie@TP[#1]{\def\optarg@ms@TP{[#1]}\@@movie@TP}% Store optional argument and proceed.
5087 \def\paren@movie@TP(#1){\def\optarg@ms@TP{(#1)}\@@movie@TP}
5088
5089 \newcommand{\@@movie@TP}[2]% Collect <n> and <dur> arguments.
5090 {\gdef\dur@ms@TP{#2}\gdef\nosteps@ms@TP{#1}\@@@movie@TP}
5091
5092 \newcommand{\@@@movie@TP}[1][\stopAdvancing]% Collect second optional argument and call body of \multistep.
5093 {\gdef\end@ms@TP{#1}\@@multistep@TP{\nosteps@ms@TP}}
5094 % \end{macrocode}
5095 %
5096 % |\overlays[<activatefirst>]{<n>}{<stepcontents>}| is another shorthand macro for executing several steps
5097 % successively. In contrast to |\multistep|, it doesn't print things \textbf{after} each other, but \textbf{over}
5098 % each other. Obviously, there is no need for a starred version.
5099 % |\overlays[<activatefirst>]{<n>}{<stepcontents>}| expands to a sequence of |<n>| commands of the form
5100 % |\switch[<activatefirst>]{}{\rlap{<stepcontents>}}|
5101 % with the effect that |<stepcontents>| is executed |<n>| times at different iterations of |\stepwise|, and all results are
5102 % overlaid over each other. Note that |[<activatefirst>]| can also have the form |(<activatefirst>)|, as usual for |\switch|.
5103 % Inside |<stepcontents>|, a counter substep can be evaluated which tells the number of the current instance.
5104 % User interface for |\overlays|.
5105 % \begin{macrocode}
5106 \@onlyinstepwise@TP\overlays
5107
5108 \providecommand{\proper@overlays@TP}
5109 {\@ifnextchar[{\brack@overlays@TP}{\@overlays@TP}}% Optional argument in square brackets?
5110
5111 \newcommand{\@overlays@TP}
5112 {%
5113 \@ifnextchar(%% Optional argument in parentheses?
5114 {\paren@overlays@TP}%
5115 {\brack@overlays@TP[]}% [] is the default if no optional argument is given.
5116 }
5117
5118 \def\brack@overlays@TP[#1]%
5119 {%
5120 \def\optarg@ov@TP{[#1]}% Store optional argument for later re-insertion.
5121 \@@overlays@TP% Proceed.
5122 }%
5123
5124 \def\paren@overlays@TP(#1){\def\optarg@ov@TP{(#1)}\@@overlays@TP}
5125 % \end{macrocode}
5126 % Main body of |\overlays|.
5127 % \begin{macrocode}
5128 \newcommand{\@@overlays@TP}[2]
5129 {%
5130 \setcounter{substep}{1}% Initialize substep counter.
5131 \leavevmode% Make sure that \rlap doesn't insert anything in the vertical list.
5132 \whiledo{\value{substep}<#1}% Iterate <n-1> times (since we start at 1).
5133 {%
5134 \expandafter\switch\optarg@ov@TP{}{\ifthenelse{\boolean{firstactivation}}{\mbox{#2}}{\rlap{#2}}}%
5135 \stepcounter{substep}%
5136 }%
5137 \expandafter\switch\optarg@ov@TP{}{\mbox{#2}}% Always using \mbox for last overlay.
5138 }
5139 % \end{macrocode}
5140 %
5141 % \subsubsection{Implementation of \cs{stepwise}}
5142 %
5143 % Every variant of |\stepwise| takes an optional argument, like this
5144 %
5145 % |\stepwise[<settings>]{<contents>}|
5146 %
5147 % |<settings>| will be placed right before the internal loop which produces the sequence of pages. It can contain
5148 % settings of parameters which modify the behaviour of |\stepwise| or |\step|. |<settings>| is placed inside a group so all
5149 % changes are local to this call of |\stepwise|.
5150 %
5151 % Usually, the first page of a sequence produced contains only material which is not part of any |<stepcontents>|. The
5152 % first |<stepcontents>| are displayed on the second page of the sequence.
5153 %
5154 % For special effects, it might be desirable to have the first |<stepcontents>| active even on the first page of the
5155 % sequence.
5156 %
5157 % All variants of |\stepwise| have a starred version (e.\,g.\ |\stepwise*|) which does exactly that.
5158 %
5159 % When |\stepwise| is executed, for every page of the sequence generated, |<contents>| is wrapped in the environment
5160 % stepcapsule (but not grouped by default). This is empty by default for minimum intrusion. Redefine stepcapsule in the
5161 % optional argument of |\stepwise| to change this (as is done for instance by |\liststepwise|).
5162 % \begin{macrocode}
5163 \newenvironment{stepcapsule}{}{}
5164 % \end{macrocode}
5165 %
5166 % Because |\step| commands usually occur deep in some nested structure, it is difficult to set local parameters (like page
5167 % transitions) only for certain steps (local settings executed in |<stepcontents>| would be undone by closing groups).
5168 %
5169 % |\afterstep{<setting>}| has the effect that |<setting>| will be performed \textbf{after} the current execution of
5170 % |<contents>|, right before the page break for this page of the sequence generated.
5171 % \begin{macrocode}
5172 \newcommand{\afterstep}[1]
5173 {%
5174 \gdef\@afterstep@TP{#1}% The argument is simply stored in \@afterstep@TP, which is executed in \stepwise.
5175 }
5176 % \end{macrocode}
5177 %
5178 % One new counter for saving the value of firststep.
5179 % \begin{macrocode}
5180 \newcounter{o@fs@TP}
5181 % \end{macrocode}
5182 %
5183 % |\stepwise| user interface.
5184 % \begin{macrocode}
5185 \newcommand{\stepwise}
5186 {%
5187 \global\c@o@fs@TP=\c@firststep\relax% Save the default value of counter firststep.
5188 \@ifstar% Using the starred version?
5189 {% Yes.
5190 \c@firststep=1\relax% Start with counter step at number 1.
5191 \@stepwise@TP% Collect optional argument and proceed.
5192 }
5193 {% No.
5194 \@stepwise@TP% Use the default.
5195 }% End of \@ifstar.
5196 }%
5197 % \end{macrocode}
5198 %
5199 % Sometimes, it might happen that vertical spacing is different on every page of a sequence generated by |\stepwise|,
5200 % making lines `wobble'.
5201 % There are two custom versions |\liststepwise|, |\parstepwise| of |\stepwise| which produce better vertical spacing by
5202 % putting an invisible rule before |<contents>|. This will almost certainly lead to `consistent' spacing which might
5203 % nevertheless be different from the spacing if |\liststepwise| wasn't present.
5204 %
5205 % |\liststepwise{<contents>}| works exactly like |\stepwise|, but |<contents>| is delimited by a rule of height zero. Use for
5206 % list environments and aligned equations.
5207 %
5208 % |\parstepwise{<contents>}| works like |\liststepwise|, but |\boxedsteps| is turned on by default. Use for texts where
5209 % steps are to be filled into blank spaces.
5210 %
5211 % Command to activate special stepcapsule for |\liststepwise|.
5212 % \begin{macrocode}
5213 \newcommand{\list@stepcapsule}
5214 {%
5215 \renewenvironment{stepcapsule}% stepcapsule is to put an invisible rule on the vertical list.
5216 {\vspace*{\parskip}\hrule \@height\z@\relax}{}
5217 }%
5218
5219 \let\par@stepcapsule=\list@stepcapsule% Identical for \parstepwise.
5220 % \end{macrocode}
5221 % User interface for |\liststepwise|.
5222 % \begin{macrocode}
5223 \newcommand{\liststepwise}
5224 {%
5225 \@ifstar% Starred version?
5226 {\def\star@TP{*}\@liststepwise@TP}% Save star in \star@TP, collect optional argument and proceed.
5227 {\def\star@TP{}\@liststepwise@TP}% Collect optional argument and proceed (non-starred version).
5228 }
5229
5230 \newcommand{\@liststepwise@TP}[1][]% Collect optional argument.
5231 {%
5232 \expandafter\stepwise\star@TP% Re-insert the star (if given).
5233 [%
5234 \list@stepcapsule% Activate special stepcapsule.
5235 #1% Insert optional argument of \liststepwise.
5236 ]%
5237 }
5238 % \end{macrocode}
5239 % User interface for |\parstepwise|.
5240 % \begin{macrocode}
5241 \newcommand{\parstepwise}
5242 {%
5243 \@ifstar% Starred version?
5244 {\def\star@TP{*}\@parstepwise@TP}% Save star in \star@TP, collect optional argument and proceed.
5245 {\def\star@TP{}\@parstepwise@TP}% Collect optional argument and proceed (non-starred version).
5246 }
5247
5248 \newcommand{\@parstepwise@TP}[1][]% Collect optional argument.
5249 {%
5250 \expandafter\stepwise\star@TP% Re-insert the star (if given).
5251 [%
5252 \boxedsteps% Activate \boxedsteps.
5253 \par@stepcapsule% Activate special stepcapsule.
5254 #1% Insert optional argument of \parstepwise.
5255 ]%
5256 }
5257 % \end{macrocode}
5258 %
5259 % |\count@em@TP| is used by |\stepwise| as a redefinition of |\@@switch@TP| for counting |\step| commands.
5260 % \begin{macrocode}
5261 \newcommand{\count@em@TP}[2]
5262 {%
5263 \global\advance\c@stepcommand by 1\relax% We simply advance the number of \step commands...
5264 #2% ... and execute the second argument (to find nested uses of \step).
5265 }
5266 % \end{macrocode}
5267 %
5268 % |\savecounters@TP| saves the values of all counters that have ever been defined by |\newcounter| in the macro
5269 % |\restorecounters@TP|, which can be used later to restore the saved values. The code is snarfed from amsmath.sty.
5270 % During execution of |\stepwise|, this is used to restore the values of all counters between steps so that things counted
5271 % in the argument of |\stepwise| (like equation numbers) do not `run wild'.
5272 % \begin{macrocode}
5273 \def\@nb@TPfalse{\global\let\if@nb@TP\iffalse}
5274 \def\@nb@TPtrue{\global\let\if@nb@TP\iftrue}
5275 \newtoks\ep@TP
5276 \def\savecounters@TP{%
5277 \begingroup
5278 \def\@elt##1{\global\csname c@##1\endcsname\the\csname c@##1\endcsname}%
5279 \xdef\restorecounters@TP{\cl@@ckpt}%
5280 \endgroup
5281 \if@nobreak\@nb@TPtrue\else\@nb@TPfalse\fi
5282 \global\ep@TP\everypar
5283 }
5284 % \end{macrocode}
5285 %
5286 % |\saveTPcounters@TP| saves the values of all `stepwise-specific' counters in the macro |\restoreTPcounters@TP|.
5287 % This is used to `counteract' |\restorecounters@TP|, leaving the values of `stepwise-specific' counters intact.
5288 % \begin{macrocode}
5289 \def\saveTPcounters@TP{%
5290 \begingroup
5291 \def\@elt##1{\global\csname c@##1\endcsname\the\csname c@##1\endcsname}%
5292 \xdef\restoreTPcounters@TP{\cl@@ckpt@TP}%
5293 \endgroup
5294 }
5295 % \end{macrocode}
5296 %
5297 % This list gives the names of all `stepwise-specific' counters.
5298 % \begin{macrocode}
5299 \def\cl@@ckpt@TP{\@elt{totalsteps}\@elt{firststep}\@elt{step}\@elt{stepcommand}\@elt{stepsperformed}\@elt{o@fs@TP}}
5300 % \end{macrocode}
5301 %
5302 % |\releasecounter{<name>}| inserts |<name>| into the list |\cl@@ckpt@TP|. This way, the counter |<name>| is not restored
5303 % between steps.
5304 % \begin{macrocode}
5305 \newcommand{\releasecounter}[1]%
5306 {\expandafter\def\expandafter\cl@@ckpt@TP\expandafter{\cl@@ckpt@TP\@elt{#1}}}
5307 % \end{macrocode}
5308 %
5309 % |\disable@counting@TP| is executed when counting |\step| commands. Everything the execution of which would be harmful
5310 % during counting, or which needs much computing resources, can be disabled here.
5311 % \begin{macrocode}
5312 \newcommand{\disable@counting@TP}
5313 {%
5314 \let\afterstep=\@gobble
5315 \renewcommand{\backgroundstyle}[2][]{}%
5316 \renewcommand{\@@vgradrule@TP}[3][0pt]{}%
5317 \renewcommand{\@@@@dblvgradrule@TP}[3][0pt]{}%
5318 \renewcommand{\@@hgradrule@TP}[3][0pt]{}%
5319 \renewcommand{\@@@@dblhgradrule@TP}[3][0pt]{}%
5320 }
5321 % \end{macrocode}
5322 %
5323 % The boolean |instepwise@TP| indicates whether the execution of |\stepwise| is currently going on.
5324 % \begin{macrocode}
5325 \newboolean{instepwise@TP}
5326 % \end{macrocode}
5327 % The boolean |instep@TP| indicates whether we are inside a |\step| command.
5328 % \begin{macrocode}
5329 \newboolean{instep@TP}
5330 % \end{macrocode}
5331 % |\@stepwise@TP| implements the functionality of |\stepwise|. It is called by |\stepwise| after checking for the star.
5332 % \begin{macrocode}
5333 \newcommand{\@stepwise@TP}[2][]
5334 {%
5335 \save@TP% Save the current contents of the page.
5336 \savecounters@TP% Save the values of all counters.
5337 \dumpcolorset{stwcolors}% Make a copy of all color definitions.
5338 \begingroup% A group makes redefinitions local.
5339 \setboolean{instepwise@TP}{true}% Set indicatior.
5340 \let\step\proper@step@TP% By default, \step executes \proper@step@TP.
5341 \let\restep\proper@restep@TP%
5342 \let\bstep\proper@bstep@TP%
5343 \let\rebstep\proper@rebstep@TP%
5344 \let\dstep\proper@dstep@TP%
5345 \let\redstep\proper@redstep@TP%
5346 \let\vstep\proper@vstep@TP%
5347 \let\revstep\proper@revstep@TP%
5348 \let\steponce\proper@steponce@TP%
5349 \let\multistep\proper@multistep@TP%
5350 \let\movie\proper@movie@TP%
5351 \let\overlays\proper@overlays@TP%
5352 \let\switch\proper@switch@TP% By default, \switch executes \proper@switch@TP.
5353 \let\reswitch\proper@reswitch@TP%
5354 % \end{macrocode}
5355 % One big problem with math is that |\mathchoice| typesets its argument four times. If |\step| commands are inside the
5356 % argument of |\mathchoice|, counters (which are advanced globally by |\step|) go astray. So far, I don't know any
5357 % remedy for this apart from (locally) hacking |\mathchoice|. I know this is a very fragile and non-recommended
5358 % method, but it works for the examples and will hopefully do until someone helps me find a better solution.
5359 % \begin{macrocode}
5360 \let\orig@mathchoice@TP=\mathchoice% Save the current definition of \mathchoice...
5361 \def\mathchoice##1##2##3##4% ... and redefine.
5362 {%
5363 \orig@mathchoice@TP% The original definition of \mathchoice is called...
5364 {##1}% ... with the first argument untouched and in all other arguments, \step ...
5365 {\let\step\restep\let\bstep\rebstep\let\dstep\redstep\let\vstep\revstep\let\switch\reswitch##2}% ... redefined ...
5366 {\let\step\restep\let\bstep\rebstep\let\dstep\redstep\let\vstep\revstep\let\switch\reswitch##3}% ... to execute ...
5367 {\let\step\restep\let\bstep\rebstep\let\dstep\redstep\let\vstep\revstep\let\switch\reswitch##4}% ... \restep.
5368 }%
5369 %
5370 \c@stepcommand=0\relax% Initialize the counter for \step commands.
5371 \let\@@switch@TP=\count@em@TP% Next, we count the \step commands in <contents>...
5372 \setbox\tempbox@TP% ... by putting <contents> into a \vbox (which is then discarded).
5373 =\vbox
5374 {%
5375 \hfuzz\maxdimen\hbadness\@M\relax% No bogus `overfull \hbox' warnings.
5376 \disable@counting@TP#2% Inside the \vbox, some commands are redefined for safety and efficiency.
5377 }%
5378 \c@totalsteps=\c@stepcommand% Now, we know the total number of \step commands.
5379 %
5380 % Next, we have to reset \first@TP@<n> for <n>=0...\value{totalsteps}.
5381 \c@step=0\relax
5382 \loop
5383 \ifnum\c@step<\c@totalsteps
5384 \advance\c@step by 1\relax
5385 \expandafter\let\csname first@TP@\the\c@step\endcsname=\@undefined% \first@TP@<n>=\@undefined means step <n>
5386 % hasn't yet been activated.
5387 \repeat
5388 % \end{macrocode}
5389 % Next, the optional argument of |\stepwise| is executed. At this point, |\value{totalsteps}| already has its final
5390 % value and |\value{step}| has not yet been set to |\value{firststep}|, so both totalsteps and firststep can
5391 % meaningfully be modified in |<settings>|.
5392 % \begin{macrocode}
5393 #1%
5394 %
5395 \c@step=\c@firststep% Set the counter for the current step to its starting value...
5396 \c@stepsperformed=0\relax% ... and also the counter for the \step commands which are already activated.
5397 \let\@@switch@TP=\@switch@TP% \step will now act normally.
5398 \ifthenelse{\boolean{verbose@TP}}% Some accounting info (if verbose option is set).
5399 {\PackageInfo{texpower}{Total number of step commands: \the\c@totalsteps}}
5400 {}%
5401 %
5402 \ifthenelse{\boolean{display}}% Are dynamic features enabled?
5403 {}% Yes.
5404 {% No. Do only one loop.
5405 \c@stepsperformed=\c@totalsteps% Set everything up for the last loop.
5406 \c@step=0\relax% Set \first@TP@<n> for <n>=0...\value{totalsteps}.
5407 \loop
5408 \ifnum\c@step<\c@totalsteps
5409 \advance\c@step by 1\relax
5410 \expandafter\let\csname first@TP@\the\c@step\endcsname=\@empty% \first@TP@<n>=\@empty means step <n>
5411 % has already been activated.
5412 \repeat
5413 \advance\c@step by 1\relax% This way, the last step won't think it's `first activated'.
5414 }%
5415 \let\insertdup@TP=\insertfirstduplicate@TP% Setup command to restore page contents for the first time.
5416 \loop% This is the central loop.
5417 \c@stepcommand=0\relax% Initialize the counter for the current \step command.
5418 \saveTPcounters@TP% Save the `stepwise-specific' counters.
5419 \restorecounters@TP% Restore the `original' values of all counters...
5420 \restoreTPcounters@TP% ... and the current values of the `stepwise-specific' counters.
5421 \let\@afterstep@TP=\relax% Reset the container for \afterstep.
5422 %
5423 \insertdup@TP% Insert saved page contents.
5424 \begin{stepcapsule}% This is usually empty, but may start a minipage (or whatever).
5425 \usecolorset{stwcolors}% Restore colors to state at the beginning of \stepwise.
5426 \if@nb@TP\@nobreaktrue\else\@nobreakfalse\fi
5427 \global\everypar\ep@TP
5428 #2% Execute <contents>
5429 \end{stepcapsule}%
5430 %
5431 \@afterstep@TP% Whatever has been saved with \afterstep is now executed.
5432 \ifnum\c@stepsperformed<\c@totalsteps% Doing one more round?
5433 \outputduplicate@TP% Shipout this page and round we go again.
5434 \let\insertdup@TP=\insertsecondduplicate@TP% Setup command to restore page contents for subsequent times.
5435 \advance\c@step by 1\relax% Round we go again
5436 \repeat
5437 \endgroup
5438 \global\c@firststep=\c@o@fs@TP\relax% Restore default value of counter firststep.
5439 }
5440 % \end{macrocode}
5441 %
5442 % \subsubsection{Implementation of the fragilesteps environment}
5443 %
5444 % Defining fragilesteps - an environment for fragile/verbatim stuff.
5445 % The code is contributed by Till Tantau, the author of the excellent
5446 % presentation class beamer.
5447 %
5448 % \begin{macrocode}
5449 \newenvironment{fragilesteps}{%
5450 \def\texpower@verbatimfilename{\jobname-texpower.vrb}%
5451 \immediate\openout\texpower@verbatimfileout=\texpower@verbatimfilename%
5452 \texpower@verbatimreadframe%
5453 }
5454 {%
5455 \immediate\closeout\texpower@verbatimfileout%
5456 \stepwise{\input{\texpower@verbatimfilename}}%
5457 }
5458 % \end{macrocode}
5459 % Internals used in the fragilesteps environment.
5460 % \begin{macrocode}
5461 \newwrite\texpower@verbatimfileout
5462
5463 \def\texpower@verbatimreadframe{%
5464 \begingroup%
5465 \let\do\@makeother\dospecials%
5466 \count@=127%
5467 \@whilenum\count@<255 \do{%
5468 \advance\count@ by 1%
5469 \catcode\count@=11%
5470 }%
5471 \@makeother\^^L% and whatever other special cases
5472 \endlinechar`\^^M \catcode`\^^M=12 \texpower@processframefirstline}
5473
5474 {\catcode`\^^M=12\endlinechar=-1%
5475 \long\gdef\texpower@processframefirstline#1^^M{%
5476 \def\texpower@test{#1}%
5477 \ifx\texpower@test\texpower@stopframefirst%
5478 \let\next=\texpower@endfragilesteps%
5479 \else
5480 \ifx\texpower@test\@empty%
5481 \else%
5482 \@temptokena={#1}%
5483 \immediate\write\texpower@verbatimfileout{\the\@temptokena}%
5484 \fi%
5485 \let\next=\texpower@processframeline%
5486 \fi%
5487 \next%
5488 }
5489 \long\gdef\texpower@processframeline#1^^M{%
5490 \def\texpower@test{#1}%
5491 \ifx\texpower@test\texpower@stopframe%
5492 \let\next=\texpower@endfragilesteps%
5493 \else
5494 \immediate\write\texpower@verbatimfileout{#1}%
5495 \fi%
5496 \next%
5497 }
5498 }
5499
5500 {
5501 \escapechar=-1\relax%
5502 \xdef\texpower@stopframe{\string\\end\string\{fragilesteps\string\}}
5503 \xdef\texpower@stopframefirst{\noexpand\end\string\{fragilesteps\string\}}
5504 }
5505
5506 \def\texpower@endfragilesteps{\endgroup\end{fragilesteps}}
5507 % \end{macrocode}
5508 %
5509 % \subsubsection{Input system-specific settings}
5510 % If file exists.
5511 % \begin{macrocode}
5512 \InputIfFileExists{tpsettings.cfg}{}{}
5513 % \end{macrocode}
5514 % \Finale
5515 \endinput