Debian Codegraph @

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

raw
1 %% \iffalse meta-comment
2 %
3 % cutwin.dtx
4 % Author: Peter Wilson, Herries Press
5 % and Alan Hoenig
6 % Copyright 2010 Peter R. Wilson
7 %
8 % Current Maintainer David Carlisle
9 % Copyright 2021 Peter R. Wilson, David Carlisle
10 %
11 % This work may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either
13 % version 1.3 of this license or (at your option) any
14 % later version.
15 % The latest version of the license is in
16 % http://www.latex-project.org/lppl.txt
17 % and version 1.3 or later is part of all distributions of
18 % LaTeX version 2003/06/01 or later.
19 %
20 % This work has the LPPL maintenance status "maintained".
21 %
22 % This work consists of the files listed in the README file.
23 %
24 %<*driver>
25 \documentclass[twoside]{ltxdoc}
26 \usepackage{alltt}
27 \usepackage{cutwin}
28 %\usepackage[draft=false,
29 % plainpages=false,
30 % pdfpagelabels,
31 % bookmarksnumbered,
32 % hyperindex=false
33 % ]{hyperref}
34 \providecommand{\phantomsection}
35 \show\makeatletter
36 \makeatletter
37 \@mparswitchfalse
38 \makeatother
39 \renewcommand{\MakeUppercase}[1]{#1}
40 \pagestyle{headings}
41 \EnableCrossrefs
42 \CodelineIndex
43 %%\OnlyDescription
44 \setcounter{StandardModuleDepth}{1}
45 \begin{document}
46 \raggedbottom
47 \DocInput{cutwin.dtx}
48 \end{document}
49 %</driver>
50 %
51 % \fi
52 %
53 %
54 % \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
55 % \DoNotIndex{\@centercr,\@cite}
56 % \DoNotIndex{\@dotsep,\@empty,\@float,\@gobble,\@gobbletwo,\@ignoretrue}
57 % \DoNotIndex{\@input,\@ixpt,\@m}
58 % \DoNotIndex{\@minus,\@mkboth,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
59 % \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\c@twdima}
60 % \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
61 % \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
62 % \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
63 % \DoNotIndex{\advance,\Alph,\alph}
64 % \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
65 % \DoNotIndex{\bullet}
66 % \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
67 % \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
68 % \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
69 % \DoNotIndex{\EnableCrossrefs,\end,\end@dblfloat,\end@float,\endgroup}
70 % \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
71 % \DoNotIndex{\fbox}
72 % \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
73 % \DoNotIndex{\global,\halign,\hangindent,\hbox,\hfil,\hfill,\hrule}
74 % \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
75 % \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
76 % \DoNotIndex{\input}
77 % \DoNotIndex{\jobname,\kern,\leavevmode,\let,\leftmark}
78 % \DoNotIndex{\list,\llap,\long,\m@ne,\m@th,\mark,\markboth,\markright}
79 % \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
80 % \DoNotIndex{\NeedsTeXFormat,\newdimen}
81 % \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
82 % \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
83 % \DoNotIndex{\pagestyle,\par,\paragraph,\paragraphmark,\parfillskip}
84 % \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
85 % \DoNotIndex{\protect,\ProvidesClass,\raggedbottom,\raggedright}
86 % \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
87 % \DoNotIndex{\rightmarnnnnnnngin,\rightmark,\rightskip,\rlap,\rmfamily,\roman}
88 % \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
89 % \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
90 % \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
91 % \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
92 % \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
93 % \DoNotIndex{\wd,\xiipt,\year,\z@}
94 %
95 % \changes{v0.1}{2010/09/29}{First public release}
96 % \changes{v0.2}{2021/10/13}{Declare registers}
97 %
98 % \def\dtxfile{cutwin.dtx}
99 % \def\fileversion{v0.2} \def\filedate{2021/10/13}
100 % \newcommand*{\Lpack}[1]{\textsf {#1}} ^^A typeset a package
101 % \newcommand*{\Lopt}[1]{\textsf {#1}} ^^A typeset an option
102 % \newcommand*{\file}[1]{\texttt {#1}} ^^A typeset a file
103 % \newcommand*{\Lcount}[1]{\textsl {\small#1}} ^^A typeset a counter
104 % \newcommand*{\pstyle}[1]{\textsl {#1}} ^^A typeset a pagestyle
105 % \newcommand*{\Lenv}[1]{\texttt {#1}} ^^A typeset an environment
106 % \newcommand*{\ablankline}{\vspace{\baselineskip}}
107 %
108 % \title{Making cutouts in paragraphs\thanks{This
109 % file (\texttt{\dtxfile}) has version number \fileversion, last revised
110 % \filedate.}}
111 %
112 % \author{%
113 % Peter Wilson\thanks{Herries Press} and Alan Hoenig\and
114 % Maintained by David Carlisle\thanks{https://github.com/latex-package-repositories/cutwin/issues}%
115 % }
116 % \date{\filedate}
117 % \maketitle
118 % \begin{abstract}
119 % The \Lpack{cutwin} package helps in making a cutout window in the middle
120 % of a paragraph.
121 %
122 % \end{abstract}
123 % \tableofcontents
124 %
125 %
126 %
127 % \section{Introduction}
128 %
129 % ^^A Based on Alan Hoenig, `TeX Does Windows --- The Conclusion',
130 % ^^A TUGboat, 8, 2 pp211-215, 1987
131 %
132 %
133 % This manual is typeset according to the conventions of the
134 % \LaTeX{} \textsc{docstrip} utility which enables the automatic
135 % extraction of the \LaTeX{} macro source files~\cite{COMPANION}.
136 %
137 % Section~\ref{sec:usc} describes the usage of the \Lpack{cutwin}
138 % package and
139 % commented source code is in Section~\ref{sec:code}.
140 %
141 % \section{The \Lpack{cutwin} package} \label{sec:usc}
142 %
143 % The code provided by the \Lpack{cutwin} package is meant to help
144 % in creating windows, or cutouts, in a text-only paragraph. It is
145 % based on code originally published by Alan Hoenig~\cite{HOENIG87}.
146 %
147 % \subsection{General}
148 %
149 % \DescribeMacro{\opencutleft}
150 % \DescribeMacro{\opencutright}
151 % \DescribeMacro{\opencutcenter}
152 % Declarations specifying where a window is to be placed. The choices
153 % are: \cs{opencutleft} open into the left margin, \cs{opencutright}
154 % open into the right margin, and \cs{opencutcenter}, which is the default,
155 % open in the `center' of the text, i.e, have text on both sides of the
156 % window.
157 %
158 % \DescribeMacro{\cutfuzz}
159 % This is provided as a convenience to reduce the number of overfull
160 % and underfull warnings. Its default definition is:
161 % \begin{verbatim}
162 % \newcommand{\cutfuzz}{%
163 % \vbadness=50000
164 % \hbadness=50000
165 % \sloppy}
166 % \end{verbatim}
167 % and it is only applied to the paragraph being windowed.
168 %
169 % \subsection{Rectangular cutouts}
170 %
171 % \newcommand*{\tinwin}{%
172 % \centering\bfseries
173 % Text \\ in \\Window \par}
174 % \newcommand*{\qinwin}{%
175 % \centering\bfseries\Huge ?\,
176 % \par}
177 % \let\windowpagestuff\tinwin
178 % \begin{cutout}{2}{0.2\textwidth}{0.4\textwidth}{3}
179 % A rectangular space can be placed in a paragraph with the text flowing
180 % across the gap. The space may break open into the top or side of the
181 % paragraph or, with some care, into the bottom (the number of lines
182 % specified for the cutout should not exceed the amount of text
183 % available for those lines). Some text or a logo or
184 % graphic may be placed within the window, or it may be left empty.
185 % In this instance I have put three short bold text lines in the window
186 % opening. The window should not be too wide as it can be difficult
187 % to track the exterior text lines across the gap.
188 % \end{cutout}
189 %
190 % \DescribeEnv{cutout}
191 % The |cutout| environment, the body of which must be a single paragraph,
192 % enables a rectangular window to be cut out of the paragraph with the
193 % text flowing across the cutout. Use as:\\
194 % \verb?\begin{cutout}?\marg{numtop}\marg{leftwidth}\marg{rightwidth}\marg{numcut} \\
195 % where \meta{numtop} is the number of full lines above the window
196 % and \meta{numcut} is the number of lines to be cut (giving the height
197 % of the window).
198 % The meaning of the lengths \meta{leftwidth} and \meta{rightwidth} depend
199 % on the location of the cutout:
200 % \begin{itemize}
201 % \item for a centered cutout \meta{leftwidth} and \meta{rightwidth} are the
202 % lengths of the text lines at the left and right sides of the window;
203 % \item for an open left cutout \meta{leftwidth} is ignored and
204 % \meta{rightwidth} is the length of the lines to the right of the cutout; and
205 % \item for an open right cutout \meta{rightwidth} is ignored and
206 % \meta{leftwidth} is the length of the lines at the left of the cutout.
207 % \end{itemize}
208 %
209 %
210 % \DescribeMacro{\pageinwindow}
211 % \DescribeMacro{\windowpagestuff}
212 % The macro \cs{pageinwindow} puts a zero-sized |picture| positioned
213 % at the left of the window aligned with the first line of the window (i.e,
214 % at the top left of the cutout).
215 % The |picture| consists of a |minipage| sized to fit the window.
216 % The contents of the minipage is \cs{windowpagestuff}. These two
217 % macros may be used to put a graphic or text into the windowed area.
218 %
219 % The default definition of \cs{windowpagestuff} is: \\
220 % \verb?\newcommand*{\windowpagestuff}{}? \\
221 % and you can change it as you wish. For instance, I used the following
222 % to put some text centrally within the above cutout.
223 % \begin{verbatim}
224 % \renewcommand*{\windowpagestuff}{%
225 % \centering\bfseries
226 % Text \\ in \\ Window \par}
227 % \end{verbatim}
228 % You may well need to experiment to get everything adjusted to your
229 % satisfaction.
230 %
231 % \subsection{Shaped cutouts}
232 %
233 % \newcommand*{\mycut}{%
234 % 0.1\textwidth, 0.3\textwidth,
235 % 0.2\textwidth, 0.4\textwidth,
236 % 0.3\textwidth, 0.5\textwidth}
237 % \renewcommand*{\putstuffinpic}{%
238 % \put(0,-8){\makebox(0,0){\Huge\bfseries \$}}}
239 %
240 % \begin{shapedcutout}{2}{3}{\mycut}
241 % A \emph{shaped cutout} is one where the shape of the window is
242 % specified by the user who has to supply the length of the text lines
243 % bordering the cutout. Normally there is text on either side of the
244 % window but it could be open at either the left or right side of
245 % the paragraph. It is possible to put a logo or some text in the
246 % window. In this paragraph with a shaped cutout I have used a large
247 % \$ sign as a simple logo.
248 % \end{shapedcutout}
249 %
250 %
251 % \DescribeEnv{shapedcutout}
252 % The |shapedcutout| environment, the body of which must be a single paragraph,
253 % enables an arbitrary shaped window to be cut out of the paragraph with the
254 % text flowing across the cutout. Use as:\\
255 % \verb?\begin{shapedcutout}?\marg{numtop}\marg{numcut}\marg{shapespec}
256 % where \meta{numtop} is the number of full lines above the window,
257 % \meta{numcut} is the number of lines to be cut (giving the height of
258 % the window) and
259 % \meta{shapespec} is the specification of the length of the lines
260 % bordering the cutout.
261 %
262 % More precisely \meta{shapespec} is a comma-separated list of the
263 % lengths of the
264 % text lines bordering the window.
265 % \begin{itemize}
266 % \item For a centered cutout one pair of entries are required for each cut
267 % line denoting the length of the left and right part of the cut line.
268 % There must be exactly \meta{numcut} pairs.
269 % \item
270 % For example you might do something along the lines of:
271 % \begin{verbatim}
272 % \newcommand*{\mycut}{%
273 % 0.1\textwidth, 0.3\textwidth,
274 % 0.2\textwidth, 0.4\textwidth,
275 % 0.3\textwidth, 0.5\textwidth}
276 % \begin{shapedcutout}{2}{3}{\mycut}
277 % ...
278 % \end{verbatim}
279 % which is what I used to create the shaped cutout above.
280 % \item For an open cutout each entry is the text length of a line. There must
281 % be exactly \meta{numcut} entries. For instance, given the above definition
282 % of \cs{mycut} then a call out for an open window would be like: \\
283 % \verb?\begin{shapedcutout}{2}{6}{\mycut}?
284 % \end{itemize}
285 %
286 % \DescribeMacro{\picinwindow}
287 % In a shaped cutout the macro \cs{picinwindow} is placed at the center
288 % of the gap in the first line of the
289 % cutout. The default \cs{picinwindow} is a zero-sized picture whose contents
290 % is \cs{putstuffinpic}.
291 %
292 % \cs{picinwindow} and \cs{putstuffinpic} are initially defined as
293 % \begin{verbatim}
294 % \newcommand*{\picinwindow}{%
295 % \begin{picture}(0,0)
296 % \putstuffinpic
297 % \end{picture}}
298 % \newcommand*{\putstuffinpic}{}
299 % \end{verbatim}
300 %
301 % You can change \cs{putstuffinpic} to place what you want in the picture.
302 % For example, to put the large \$ symbol in the shaped cutout paragraph above
303 % I used:
304 % \begin{verbatim}
305 % \renewcommand*{\putstuffinpic}{%
306 % \put(0,-8){\makebox(0,0){\Huge\bfseries \$}}}
307 % \end{verbatim}
308 % You have to adjust the placement to suit your purposes and the shape of
309 % the cutout.
310 %
311 % \StopEventually{
312 % \bibliographystyle{alpha}
313 % \begin{thebibliography}{GMS04}
314 % \bibitem[GM04]{COMPANION}
315 % Frank Mittelbach and Michel Goossens.
316 % \newblock \emph{The LaTeX Companion}. Second edition.
317 % \newblock Addison-Wesley Publishing Company, 2004.
318 % \bibitem[Hoe87]{HOENIG87}
319 % Alan Hoenig.
320 % \newblock TeX does windows --- The conclusion,
321 % \newblock \emph{TUGboat}, vol 8, no 2, pp 211--215, 1987.
322 % \end{thebibliography}
323 % }
324 %
325 %
326 % \clearpage
327 % \section{The package code} \label{sec:code}
328 %
329 % To try and avoid name clashes, all the internal commands include
330 % the string |c@tw|.
331 %
332 % \subsection{Preliminaries}
333 %
334 % Announce the name and version of the package, which requires
335 % \LaTeXe.
336 % \begin{macrocode}
337 %<*pkg>
338 \NeedsTeXFormat{LaTeX2e}
339 \ProvidesPackage{cutwin}[2021/10/13 v0.2 cutout windows]
340 % \end{macrocode}
341 %
342 %
343 % \subsection{General}
344 %
345 % \begin{macro}{\c@twwinlines}
346 % \begin{macro}{\c@twtoplines}
347 % \begin{macro}{\c@twcnt}
348 % We need lots of variables. First some counts.
349 % \begin{macrocode}
350 \newcount\c@twwinlines % window lines
351 \newcount\c@twtoplines % top lines
352 \newcount\c@twcnt % a count
353 % \end{macrocode}
354 % \end{macro}
355 % \end{macro}
356 % \end{macro}
357 %
358 % \begin{macro}{\c@twlftside}
359 % \begin{macro}{\c@twrtside}
360 % \begin{macro}{\c@twtopht}
361 % \begin{macro}{\c@twvsilg}
362 % And some lengths.
363 % \begin{macrocode}
364 \newdimen\c@twlftside % left width
365 \newdimen\c@twrtside % right width
366 \newdimen\c@twtopht % height of top text
367 \newdimen\c@twvsilg % Vertical Shift or InterLine Glue
368 % \end{macrocode}
369 % \end{macro}
370 % \end{macro}
371 % \end{macro}
372 % \end{macro}
373 %
374 % \begin{macro}{\c@twtoka}
375 % \begin{macro}{\c@twtokb}
376 % And some tokens.
377 % \begin{macrocode}
378 \newtoks\c@twtoka % build of parshape spec
379 \newtoks\c@twtokb % build of parshape spec
380 % \end{macrocode}
381 % \end{macro}
382 % \end{macro}
383 %
384 % \begin{macro}{\c@twrawtext}
385 % \begin{macro}{\c@twholdwin}
386 % \begin{macro}{\c@twwindow}
387 % \begin{macro}{\c@twfinaltext}
388 % \begin{macro}{\c@twslicea}
389 % \begin{macro}{\c@twsliceb}
390 % And some boxes.
391 % \begin{macrocode}
392 \newbox\c@twrawtext % text as input
393 \newbox\c@twholdwin % text for window sides
394 \newbox\c@twwindow % composed window
395 \newbox\c@twfinaltext % final assembled cutout paragraph
396 \newbox\c@twslicea % slice A of window text
397 \newbox\c@twsliceb % slice B of window text
398 % \end{macrocode}
399 % \end{macro}
400 % \end{macro}
401 % \end{macro}
402 % \end{macro}
403 % \end{macro}
404 % \end{macro}
405 %
406 % \begin{macro}{\c@twdima}
407 % \begin{macro}{\c@twdimb}
408 % And some lengths.
409 % \begin{macrocode}
410 \newdimen\c@twdima % formally \@tempdimb
411 \newdimen\c@twdimb % formally \@tempdimc
412 % \end{macrocode}
413 % \end{macro}
414 % \end{macro}
415 %
416 % \begin{macro}{\opencutleft}
417 % \begin{macro}{\opencutright}
418 % \begin{macro}{\opencutcenter}
419 % \begin{macro}{\c@twl@c}
420 % User commands for positioning a cutout; left, right, or center.
421 % The default is \cs{opencutcenter}.
422 % \cs{c@twl@c} is the internal representation.
423 % \begin{macrocode}
424 \newcommand*{\opencutleft}{\def\c@twl@c{-1}}
425 \newcommand*{\opencutright}{\def\c@twl@c{1}}
426 \newcommand*{\opencutcenter}{\def\c@twl@c{0}}
427 % \end{macrocode}
428 % \end{macro}
429 % \end{macro}
430 % \end{macro}
431 % \end{macro}
432 % \begin{macrocode}
433 \opencutcenter
434 % \end{macrocode}
435 %
436 % \begin{macro}{\cutfuzz}
437 % An attempt to stop TeX moaning about over/under full h/v boxes.
438 % \begin{macrocode}
439 \newcommand{\cutfuzz}{\vbadness=50000
440 \hbadness=50000
441 % \hfuzz=1pt
442 \sloppy}
443 % \end{macrocode}
444 % \end{macro}
445 %
446 % \begin{macro}{\c@twcalcilg}
447 % Calculate the interline glue.
448 % \begin{macrocode}
449 \newcommand*{\c@twcalcilg}{%
450 \c@twvsilg=\baselineskip
451 \setbox0=\hbox{(}%
452 \advance\c@twvsilg-\ht0 \advance\c@twvsilg-\dp0}
453 % \end{macrocode}
454 % \end{macro}
455 %
456 %
457 % \subsection{Rectangular cutouts}
458 %
459 % \begin{macro}{\pageinwindow}
460 % \begin{macro}{\windowpagestuff}
461 % User modifiable macros for putting (\cs{pageinwindow}), via a
462 % zero-sized picture,
463 % stuff (\cs{windowpagestuff}) in a cutout window.
464 % \begin{macrocode}
465 \newcommand*{\pageinwindow}{%
466 \c@twdimb=\c@twwinlines\baselineskip % cutout height
467 \c@twdima=\hsize
468 \ifnum\c@twl@c=\m@ne % openleft
469 \advance\c@twdima -\c@twrtside
470 \else
471 \ifnum\c@twl@c=\@ne % openright
472 \advance\c@twdima -\c@twlftside
473 \else% center
474 \advance\c@twdima - \c@twlftside
475 \advance\c@twdima - \c@twrtside
476 \fi
477 \fi
478 \begin{picture}(0,0)%
479 \put(0,0){%
480 \raisebox{4pt}{%
481 %\fbox{%
482 \begin{minipage}[t][\c@twdimb][c]{\c@twdima}%
483 \windowpagestuff
484 \end{minipage}%
485 %}% end fbox
486 }% end raisebox
487 }% end put
488 \end{picture}}
489 \newcommand*{\windowpagestuff}{}
490 % \end{macrocode}
491 % \end{macro}
492 % \end{macro}
493 %
494 % \begin{environment}{cutout}
495 % The environment for cutting a rectangular window from a paragraph.
496 %
497 % \verb?\begin{cutout}?\marg{numtop}\marg{leftwidth}\marg{rightwidth}\marg{numcut} \\
498 % where \meta{numtop} is the number of full lines above the window,
499 % \meta{leftwidth} and \meta{rightwidth} are the widths of the text
500 % at the sides of the window,
501 % and \meta{numcut} is the number of lines to be cut (giving the height
502 % of the window).
503 %
504 % The basic method is to split the paragraph into three parts (a)
505 % the top lines above the window, (b) the window lines and (c) the rest
506 % (which will be below the window). \cs{parshape} is used to do the
507 % splitting. The top lines are left at their natural length, each line
508 % crossing the window is treated as a pair of short lines, and the rest
509 % are left at their natural length.
510 %
511 % The top lines are put into one box, the windowed ones into another
512 % and then there are the remainder. When being boxed, the window lines
513 % are combined pairwise to make single lines with space in the middle.
514 % Finally, the boxes are output.
515 % \begin{macrocode}
516 \newenvironment{cutout}[4]{%
517 \cutfuzz
518 \c@twtoplines=#1\relax
519 \c@twwinlines=#4\relax
520 \c@twlftside=#2\relax
521 \c@twrtside=#3\relax
522 \c@twtoka={}%
523 % \end{macrocode}
524 % Generate the \cs{parshape} specification.
525 % \begin{macrocode}
526 \c@twmakeparspec
527 % \end{macrocode}
528 % Reset the arguments and calculate a vertical shift.
529 % \begin{macrocode}
530 \c@twtoplines=#1\relax
531 \c@twwinlines=#4\relax
532 \c@twcalcshift \vskip-\c@twvsilg
533 % \end{macrocode}
534 % Open the \cs{c@twrawtext} box, call the \cs{parshape} and start
535 % collecting the text to be windowed.
536 % \begin{macrocode}
537 \setbox\c@twrawtext=\vbox\bgroup
538 \parshape=\c@twcnt \the\c@twtoka}%
539 % \end{macrocode}
540 % Now the code for the actions at \verb?\end{cutout}?, which starts by ending
541 % the \cs{c@rawtext} box, resetting \cs{parshape} and calculating
542 % the interline glue.
543 % \begin{macrocode}
544 {\egroup% end \box\c@twrawtext
545 \parshape=0 % reset parshape;
546 \c@twcalcilg % find ILG using current font
547 % \end{macrocode}
548 % If there are lines above the window, split them off from \cs{c@twrawtext}
549 % into \cs{c@twfinaltext}.
550 % \begin{macrocode}
551 \ifnum\c@twtoplines>\z@
552 \setbox\c@twfinaltext=\vsplit\c@twrawtext to\c@twtoplines\baselineskip
553 \fi
554 % \end{macrocode}
555 % Calculate the `height' of the lines that make up the window. If
556 % the window is in the center then this is twice the expected height
557 % (at this point each final window line is stored as a pair of lines),
558 % otherwise it is the expected height based on \meta{numcut}.
559 % \begin{macrocode}
560 \c@twtopht=\c@twwinlines\baselineskip
561 \ifnum\c@twl@c=\z@ % center
562 \c@twtopht=2\c@twtopht
563 \fi
564 % \end{macrocode}
565 % Split the window lines from what is left in the \cs{c@twrawtext} box
566 % into box \cs{c@twholdwin} which will then contain the narrowed text for the
567 % window side(s).
568 % \begin{macrocode}
569 \setbox\c@twholdwin=\vsplit\c@twrawtext to\c@twtopht
570 % \end{macrocode}
571 % Now `compose' the window side(s) text (\cs{c@twholdwin})
572 % into the final set of windowed lines (\cs{c@twwindow}).
573 % The process depends on whether the cutout is at the left, right, or center.
574 % \begin{macrocode}
575 \ifnum\c@twl@c=\z@% center
576 \c@twcompctr{\c@twholdwin}{\c@twwindow}%
577 \else% left or right
578 \c@twcomplftrt{\c@twholdwin}{\c@twwindow}%
579 \fi
580 % \end{macrocode}
581 % Assemble the various boxes into the final box (\cs{c@twfinaltext})
582 % to be output.
583 % \begin{macrocode}
584 \setbox\c@twfinaltext=
585 \vbox{\ifnum\c@twtoplines>\z@\unvbox\c@twfinaltext\vskip\c@twvsilg\fi
586 \unvbox\c@twwindow%
587 \vskip-\c@twvsilg\unvbox\c@twrawtext}%
588 % \end{macrocode}
589 % We're done, hand off the paragraph.
590 % \begin{macrocode}
591 \box\c@twfinaltext}
592 % \end{macrocode}
593 % \end{environment}
594 %
595 % \begin{macro}{\c@twcompctr}
596 % \begin{macro}{\c@twfirst}
597 % \cs{c@twcompctr}\marg{linepairbox}\marg{composedbox} composes a
598 % center window box \meta{linepairbox} consisting of pairs of short
599 % lines into a box \meta{composedbox} where the pairs have been assembled
600 % into single lines.
601 %
602 % \cs{c@twfirst} is used as a flag for indicating the first line of a cutout.
603 % \begin{macrocode}
604 \newcommand*{\c@twcompctr}[2]{%
605 \def\c@twfirst{1}%
606 \loop\advance\c@twwinlines\m@ne
607 % \end{macrocode}
608 % Get a pair of lines and remove skips.
609 % \begin{macrocode}
610 \setbox\c@twslicea=\vsplit#1 to\baselineskip
611 \setbox\c@twsliceb=\vsplit#1 to\baselineskip
612 \c@twprune{\c@twslicea}{\c@twlftside}%
613 \c@twprune{\c@twsliceb}{\c@twrtside}%
614 % \end{macrocode}
615 % \begin{macrocode}
616 \ifnum\c@twfirst=\@ne
617 % \end{macrocode}
618 % The first time put the texts into a box at the left and right with
619 % \cs{pageinwindow} at the end of the left text.
620 % \begin{macrocode}
621 \setbox#2=\vbox{\unvbox#2\hbox
622 to\hsize{\box\c@twslicea\pageinwindow\hfil\box\c@twsliceb}}%
623 \else
624 % \end{macrocode}
625 % For further lines just put the texts at the left and right.
626 % \begin{macrocode}
627 \setbox#2=\vbox{\unvbox#2\hbox
628 to\hsize{\box\c@twslicea\hfil\box\c@twsliceb}}%
629 \fi
630 % \end{macrocode}
631 % \begin{macrocode}
632 \def\c@twfirst{2}%
633 \ifnum\c@twwinlines>\z@\repeat}
634 % \end{macrocode}
635 % \end{macro}
636 % \end{macro}
637 %
638 % \begin{macro}{\c@twcomplftrt}
639 % Compose an open (left or right) sided rectangular window.
640 % \begin{macrocode}
641 \newcommand*{\c@twcomplftrt}[2]{%
642 \def\c@twfirst{1}%
643 \loop\advance\c@twwinlines\m@ne
644 % \end{macrocode}
645 % For an open window we simply deal with one line at a time, not
646 % pairs. In other respects the code is generally similar to that for
647 % \cs{c@twcompctr}.
648 % \begin{macrocode}
649 \setbox\c@twslicea=\vsplit#1 to\baselineskip
650 \ifnum\c@twl@c=\m@ne% open left, text at right
651 \c@twprune{\c@twslicea}{\c@twrtside}%
652 \ifnum\c@twfirst=\@ne
653 \setbox#2=\vbox{\unvbox#2\hbox
654 to\hsize{\pageinwindow\hfil\box\c@twslicea}}%
655 \else
656 \setbox#2=\vbox{\unvbox#2\hbox
657 to\hsize{\mbox{}\hfil\box\c@twslicea}}%
658 \fi
659 \def\c@twfirst{2}%
660 \else
661 \ifnum\c@twl@c=\@ne% open right, text at left
662 \c@twprune{\c@twslicea}{\c@twlftside}%
663 \ifnum\c@twfirst=\@ne\relax
664 \setbox#2=\vbox{\unvbox#2\hbox
665 to\hsize{\box\c@twslicea\pageinwindow}}%
666 \else
667 \setbox#2=\vbox{\unvbox#2\hbox
668 to\hsize{\box\c@twslicea}}%
669 \fi
670 \def\c@twfirst{2}%
671 \fi
672 \fi
673 \ifnum\c@twwinlines>\z@\repeat}
674 % \end{macrocode}
675 % \end{macro}
676 %
677 %
678 % \begin{macro}{\c@twprune}
679 % \cs{c@twprune}\marg{vbox}\marg{width} chops off the \cs{lastskip}.
680 % It takes a \meta{vbox} containing a single \cs{hbox}, \cs{unvbox}es
681 % it,cancels the \cs{lastskip} which can be put at the right of
682 % a short \cs{parshape} line, then puts it in a box width \meta{width}.
683 % \begin{macrocode}
684 \newcommand*{\c@twprune}[2]{%
685 \unvbox#1 \setbox#1=\lastbox % \box#1 is now an \hbox
686 \setbox#1=\hbox to#2{\strut\unhbox#1\unskip}}
687 % \end{macrocode}
688 % \end{macro}
689 %
690 % \begin{macro}{\c@twmakeparspec}
691 % Calculate the required \cs{parshape} spec for a paragraph with a rectangular
692 % cutout window.
693 % \begin{macrocode}
694 \newcommand*{\c@twmakeparspec}{%
695 % \end{macrocode}
696 % \cs{c@twcnt} is the total number of lines for the \cs{parshape}, i.e.,
697 % the number of the top lines plus (twice) the number of window line
698 % plus one for the remaining lines.
699 % \begin{macrocode}
700 \c@twcnt=\c@twwinlines
701 \ifnum\c@twl@c=\z@
702 \multiply \c@twcnt by \tw@
703 \fi
704 \advance\c@twcnt by \c@twtoplines \advance\c@twcnt by \@ne
705 % \end{macrocode}
706 % If there are top lines generate a \verb?0pt \hsize? for each
707 % \begin{macrocode}
708 \ifnum\c@twtoplines>\z@
709 \loop\c@twtoka=\expandafter{\the\c@twtoka 0pt \hsize}%
710 \advance\c@twtoplines -1\relax
711 \ifnum\c@twtoplines>\z@\repeat
712 \fi
713 % \end{macrocode}
714 % Now do the cutout portion of the spec.
715 % \begin{macrocode}
716 \ifnum\c@twl@c=\m@ne % openleft
717 % \end{macrocode}
718 % For open left calculate the width of the open cutout as \cs{c@twlftside}.
719 % \begin{macrocode}
720 \c@twlftside=\hsize
721 \advance\c@twlftside -\c@twrtside
722 \fi
723 % \end{macrocode}
724 % Loop over the windowed lines.
725 % \begin{macrocode}
726 \loop\c@twtoka=%
727 \ifnum\c@twl@c=\m@ne % openleft
728 % \end{macrocode}
729 % For open left generate a \verb?\c@twlftside \c@twrtside? for each.
730 % \begin{macrocode}
731 \expandafter{\the\c@twtoka \c@twlftside \c@twrtside}%
732 \else
733 \ifnum\c@twl@c=\@ne % openright
734 % \end{macrocode}
735 % For open right generate a \verb?\0pt c@twlftside? for each
736 % \begin{macrocode}
737 \expandafter{\the\c@twtoka 0pt \c@twlftside}%
738 \else %center
739 % \end{macrocode}
740 % For centered generate \verb?0pt \c@twlftside 0pt \c@twrtside? for each pair.
741 % \begin{macrocode}
742 \expandafter{\the\c@twtoka 0pt \c@twlftside 0pt \c@twrtside}%
743 \fi
744 \fi
745 \advance\c@twwinlines \m@ne
746 \ifnum\c@twwinlines>\z@\repeat
747 % \end{macrocode}
748 % That finishes the cutout portion. For the remaining lines in the
749 % paragraph just generate a single \verb?0pt \hsize?.
750 % \begin{macrocode}
751 \c@twtoka=\expandafter{\the\c@twtoka 0pt \hsize}}
752 % \end{macrocode}
753 % \end{macro}
754 %
755 % \begin{macro}{\c@twcalcshift}
756 % Calculate the estimated vertical shift needed for the window.
757 % I determined the values experimentally based on a 10pt font.
758 % In may be different for different fonts, but I hope not.
759 % \begin{macrocode}
760 \newcommand*{\c@twcalcshift}{% vertical shift
761 \c@twvsilg=\c@twwinlines\baselineskip
762 \ifnum\c@twtoplines<\@ne
763 \advance\c@twvsilg -0.25\baselineskip
764 \fi
765 \c@twvsilg=0.5\c@twvsilg
766 \ifnum\c@twl@c=\z@\else
767 \c@twvsilg=0.5\c@twvsilg
768 \fi}
769 % \end{macrocode}
770 % \end{macro}
771 %
772 %
773 % \subsection{Shaped cutouts}
774 %
775 % \begin{macro}{\picinwindow}
776 % A zero-sized picture, with contents \cs{putstuffinpic}, which is placed in
777 % the center of the first gap in a shaped cutout.
778 % \begin{macrocode}
779 \newcommand*{\picinwindow}{%
780 \begin{picture}(0,0)
781 \putstuffinpic
782 \end{picture}}
783 % \end{macrocode}
784 % \end{macro}
785 %
786 % \begin{macro}{\putstuffinpic}
787 % Default \cs{putstuffinpic} is empty.
788 % \begin{macrocode}
789 \newcommand*{\putstuffinpic}{}
790 % \end{macrocode}
791 % \end{macro}
792 %
793 % \begin{environment}{shapedcutout}
794 % \begin{macro}{\c@twb}
795 % A shaped cutout where the user defines the shape. \\
796 % \verb?\begin{shapedcutout}?\marg{numtop}\marg{numcut}\marg{shapespec} \\
797 % where \meta{numtop} is the number of full lines above the window,
798 % \meta{numcut} is the number of lines to be cut (giving the height
799 % of the window) and
800 % \meta{shapespec} is the user's specification of the shape of the
801 % surroundings of the cutout. This is in the form of a comma-separated
802 % list of either the pairs of widths of the left and right texts of a centered
803 % cutout or the widths of the left or right texts of an open cutout.
804 %
805 % \cs{c@twb} holds arg 3 (\meta{shapespec}), the user's parspec.
806 %
807 % The code is very similar to that for the |cutout| environment.
808 % \begin{macrocode}
809 \newenvironment{shapedcutout}[3]{%
810 \cutfuzz
811 \c@twtoplines=#1\relax
812 \c@twwinlines=#2\relax
813 \edef\c@twb{#3}% user's parspec
814 % \end{macrocode}
815 % Generate the top lines portion of the parspec followed by the cutout
816 % portion.
817 % \begin{macrocode}
818 \c@twmaketopoddspec
819 \c@twbuildoddspec{#3}
820 % \end{macrocode}
821 % Continue like the |cutout| code.
822 % \begin{macrocode}
823 \c@twtoplines=#1\relax
824 \c@twwinlines=#2\relax
825 \c@twcalcshift \vskip-\c@twvsilg
826 \setbox\c@twrawtext=\vbox\bgroup
827 % \end{macrocode}
828 % \cs{c@twcnt} is the total number of parshape lines; \cs{c@twtoka} is the
829 % spec for the top lines; \cs{c@twtokb} is the spec for the cutout lines;
830 % and \verb?0pt \hsize? is the spec for the remainder of the paragraph.
831 % \begin{macrocode}
832 \parshape=\c@twcnt \the\c@twtoka \the\c@twtokb 0pt \hsize}%
833 % \end{macrocode}
834 % \end{macro}
835 % The code for the end of the environment, where most of the work is done.
836 % It is similar to the code for the end of the |cutout| environment.
837 % \begin{macrocode}
838 {\egroup
839 \parshape=0
840 \c@twcalcilg
841 \ifnum\c@twtoplines>\z@
842 \setbox\c@twfinaltext=\vsplit\c@twrawtext to\c@twtoplines\baselineskip
843 \fi
844 \c@twtopht=\c@twwinlines\baselineskip
845 \ifnum\c@twl@c=\z@ % center
846 \c@twtopht=2\c@twtopht
847 \fi
848 \setbox\c@twholdwin=\vsplit\c@twrawtext to\c@twtopht
849 \ifnum\c@twl@c=\z@% center
850 \c@twcompoddctr{\c@twholdwin}{\c@twwindow}%
851 \else% open left or right
852 \c@twcompoddlftrt{\c@twholdwin}{\c@twwindow}%
853 \fi
854 \setbox\c@twfinaltext=
855 \vbox{\ifnum\c@twtoplines>\z@\unvbox\c@twfinaltext\vskip\c@twvsilg\fi
856 \unvbox\c@twwindow%
857 \vskip-\c@twvsilg\unvbox\c@twrawtext}%
858 \box\c@twfinaltext}
859 % \end{macrocode}
860 % \end{environment}
861 %
862 % \begin{macro}{\c@twmaketopoddspec}
863 % Make up the easy part of the odd \cs{parshape} specification;
864 % total number \cs{c@twcnt} and the toplines spec (\cs{c@twtoka}).
865 % \begin{macrocode}
866 \newcommand*{\c@twmaketopoddspec}{%
867 \c@twcnt=\c@twwinlines
868 \ifnum\c@twl@c=\z@
869 \multiply \c@twcnt by \tw@
870 \fi
871 \advance\c@twcnt by \c@twtoplines \advance\c@twcnt by \@ne
872 %% \c@twcnt is total of toplines + 2(window lines) + 1
873 \c@twtoka={}%
874 \ifnum\c@twtoplines>\z@
875 \loop\c@twtoka=\expandafter{\the\c@twtoka 0pt \hsize}%
876 \advance\c@twtoplines -1\relax
877 \ifnum\c@twtoplines>\z@\repeat
878 \fi}
879 % \end{macrocode}
880 % \end{macro}
881 %
882 % \begin{macro}{\c@twaddtospec}
883 % Adds a `zero-indented line' to a parshape spec being assembled in
884 % \cs{c@twtokb}.
885 % \begin{macrocode}
886 \newcommand*{\c@twaddtospec}[1]{%
887 \c@twtokb=\c@twxpf{\the\c@twtokb 0pt #1 }}
888 % \end{macrocode}
889 % \end{macro}
890 % \begin{macro}{\c@twbuildoddspec}
891 % \begin{macro}{\c@twxpf}
892 % \cs{c@twbuildoddspec}\marg{commalist} builds up the parshape spec for
893 % the odd cutout lines from the comma-separated list of lengths
894 % in \meta{commalist}.
895 %
896 % \cs{c@twxpf} is a shorthand for \cs{expandafter}
897 % to try and make the code shorter to read.
898 % \begin{macro}{\c@twlspec}
899 % \cs{c@twlspec} is used as a temporary variable when iterating over
900 % a comma-separated list.
901 % \end{macro}
902 %
903 % \begin{macrocode}
904 \let\c@twxpf\expandafter
905 \newcommand*{\c@twbuildoddspec}[1]{%
906 \c@twtokb={}%
907 \@for\c@twlspec:=#1\do{%
908 \c@twxpf\c@twxpf\c@twxpf\c@twaddtospec\c@twxpf{\c@twlspec}}}
909 % \end{macrocode}
910 % \end{macro}
911 % \end{macro}
912 %
913 % \begin{macro}{\c@twcompoddctr}
914 % \begin{macro}{\c@twrounds}
915 % Compose the lines of an odd shaped center cutout.
916 %
917 % We go through the user's shape list an item at a time but we need to
918 % collect pairs of items. The \cs{c@twrounds} variable is for managing the
919 % pairing. \cs{c@twfirst} is a flag for positioning the \cs{picinwindow} in
920 % the first line of the cutout.
921 % \begin{macrocode}
922 \newcommand*{\c@twcompoddctr}[2]{%
923 \def\c@twrounds{1}%
924 \def\c@twfirst{1}%
925 \@for\c@twlspec:=\c@twb\do{%
926 \ifnum\c@twrounds=1
927 \setbox\c@twslicea=\vsplit#1 to\baselineskip % first of pair
928 \c@twprune{\c@twslicea}{\c@twlspec}%
929 \def\c@twrounds{2}%
930 \else
931 \setbox\c@twsliceb=\vsplit#1 to\baselineskip % second of pair
932 \c@twprune{\c@twsliceb}{\c@twlspec}%
933 \ifnum\c@twfirst=1
934 \setbox#2=\vbox{\unvbox#2\hbox
935 to\hsize{\box\c@twslicea\hfil\picinwindow\hfil\box\c@twsliceb}}%
936 \def\c@twfirst{2}%
937 \else
938 \setbox#2=\vbox{\unvbox#2\hbox
939 to\hsize{\box\c@twslicea\hfil\box\c@twsliceb}}%
940 \fi
941 \def\c@twrounds{1}%
942 \fi}}
943 % \end{macrocode}
944 % \end{macro}
945 % \end{macro}
946 %
947 % \begin{macro}{\c@twcompoddlftrt}
948 % Compose the open (left or right) lines of an odd shaped cutout.
949 % \begin{macrocode}
950 \newcommand*{\c@twcompoddlftrt}[2]{%
951 \def\c@twfirst{1}%
952 \@for\c@twlspec:=\c@twb\do{%
953 \setbox\c@twslicea=\vsplit#1 to\baselineskip % get a line
954 \c@twprune{\c@twslicea}{\c@twlspec}%
955 \ifnum\c@twl@c=\m@ne% open left, text at right
956 \ifnum\c@twfirst=1
957 \setbox#2=\vbox{\unvbox#2\hbox
958 to\hsize{\mbox{}\hfil\picinwindow\hfil\box\c@twslicea}}%
959 \def\c@twfirst{2}%
960 \else
961 \setbox#2=\vbox{\unvbox#2\hbox
962 to\hsize{\mbox{}\hfil\box\c@twslicea}}%
963 \fi
964 \else
965 \ifnum\c@twl@c=\@ne% open right, text at left
966 \ifnum\c@twfirst=1
967 \setbox#2=\vbox{\unvbox#2\hbox
968 to\hsize{\box\c@twslicea\hfil\picinwindow\hfil}}%
969 \def\c@twfirst{2}%
970 \else
971 \setbox#2=\vbox{\unvbox#2\hbox
972 to\hsize{\box\c@twslicea\hfil}}%
973 \fi
974 \fi
975 \fi}}
976 % \end{macrocode}
977 % \end{macro}
978 %
979 %
980 %
981 %
982 % The end of this package.
983 % \begin{macrocode}
984 %</pkg>
985 % \end{macrocode}
986 %
987 %
988 %
989 %
990 % \Finale
991 % \PrintIndex
992 %
993 \endinput
994