summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/cutwin/cutwin.sty
blob: cdf1b47bc0855260f6776c3eecd18734bf72a45b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
%%
%% This is file `cutwin.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% cutwin.dtx  (with options: `pkg')
%% 
%% -----------------------------------------------------------------
%%   Author: Peter Wilson, Herries Press (herries dot press at earthlink dot net)
%%           and Alan Hoenig
%%   Copyright 2010 Peter R. Wilson
%% 
%%   Current Maintainer David Carlisle
%%   Copyright 2021 Peter R. Wilson, David Carlisle
%% 
%%   This work may be distributed and/or modified under the
%%   conditions of the LaTeX Project Public License, either
%%   version 1.3 of this license or (at your option) any
%%   later version.
%%   The latest version of the license is in
%%      http://www.latex-project.org/lppl.txt
%%   and version 1.3 or later is part of all distributions of
%%   LaTeX version 2003/06/01 or later.
%% 
%%   This work has the LPPL maintenance status "maintained".
%% 
%%   This work consists of the files listed in the README file.
%% -----------------------------------------------------------------
%% 
%% \iffalse meta-comment
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cutwin}[2021/10/13 v0.2 cutout windows]
\newcount\c@twwinlines % window lines
\newcount\c@twtoplines % top lines
\newcount\c@twcnt      % a count
\newdimen\c@twlftside  % left width
\newdimen\c@twrtside   % right width
\newdimen\c@twtopht    % height of top text
\newdimen\c@twvsilg    % Vertical Shift or InterLine Glue
\newtoks\c@twtoka      % build of parshape spec
\newtoks\c@twtokb      % build of parshape spec
\newbox\c@twrawtext    % text as input
\newbox\c@twholdwin    % text for window sides
\newbox\c@twwindow     % composed window
\newbox\c@twfinaltext  % final assembled cutout paragraph
\newbox\c@twslicea     % slice A of window text
\newbox\c@twsliceb     % slice B of window text
\newdimen\c@twdima    % formally \@tempdimb
\newdimen\c@twdimb    % formally \@tempdimc
\newcommand*{\opencutleft}{\def\c@twl@c{-1}}
\newcommand*{\opencutright}{\def\c@twl@c{1}}
\newcommand*{\opencutcenter}{\def\c@twl@c{0}}
\opencutcenter
\newcommand{\cutfuzz}{\vbadness=50000
   \hbadness=50000
  \sloppy}
\newcommand*{\c@twcalcilg}{%
  \c@twvsilg=\baselineskip
  \setbox0=\hbox{(}%
  \advance\c@twvsilg-\ht0 \advance\c@twvsilg-\dp0}
\newcommand*{\pageinwindow}{%
  \c@twdimb=\c@twwinlines\baselineskip % cutout height
  \c@twdima=\hsize
  \ifnum\c@twl@c=\m@ne % openleft
    \advance\c@twdima -\c@twrtside
  \else
    \ifnum\c@twl@c=\@ne % openright
      \advance\c@twdima -\c@twlftside
    \else% center
      \advance\c@twdima - \c@twlftside
      \advance\c@twdima - \c@twrtside
    \fi
  \fi
  \begin{picture}(0,0)%
    \put(0,0){%
      \raisebox{4pt}{%
        \begin{minipage}[t][\c@twdimb][c]{\c@twdima}%
          \windowpagestuff
        \end{minipage}%
      }% end raisebox
    }% end put
  \end{picture}}
\newcommand*{\windowpagestuff}{}
\newenvironment{cutout}[4]{%
  \cutfuzz
  \c@twtoplines=#1\relax
  \c@twwinlines=#4\relax
  \c@twlftside=#2\relax
  \c@twrtside=#3\relax
  \c@twtoka={}%
  \c@twmakeparspec
  \c@twtoplines=#1\relax
  \c@twwinlines=#4\relax
  \c@twcalcshift \vskip-\c@twvsilg
  \setbox\c@twrawtext=\vbox\bgroup
  \parshape=\c@twcnt \the\c@twtoka}%
  {\egroup% end \box\c@twrawtext
  \parshape=0 % reset parshape;
  \c@twcalcilg % find ILG using current font
  \ifnum\c@twtoplines>\z@
    \setbox\c@twfinaltext=\vsplit\c@twrawtext to\c@twtoplines\baselineskip
  \fi
  \c@twtopht=\c@twwinlines\baselineskip
  \ifnum\c@twl@c=\z@ % center
    \c@twtopht=2\c@twtopht
  \fi
  \setbox\c@twholdwin=\vsplit\c@twrawtext to\c@twtopht
  \ifnum\c@twl@c=\z@% center
    \c@twcompctr{\c@twholdwin}{\c@twwindow}%
  \else% left or right
    \c@twcomplftrt{\c@twholdwin}{\c@twwindow}%
  \fi
  \setbox\c@twfinaltext=
    \vbox{\ifnum\c@twtoplines>\z@\unvbox\c@twfinaltext\vskip\c@twvsilg\fi
    \unvbox\c@twwindow%
    \vskip-\c@twvsilg\unvbox\c@twrawtext}%
  \box\c@twfinaltext}
\newcommand*{\c@twcompctr}[2]{%
  \def\c@twfirst{1}%
  \loop\advance\c@twwinlines\m@ne
  \setbox\c@twslicea=\vsplit#1 to\baselineskip
  \setbox\c@twsliceb=\vsplit#1 to\baselineskip
  \c@twprune{\c@twslicea}{\c@twlftside}%
  \c@twprune{\c@twsliceb}{\c@twrtside}%
  \ifnum\c@twfirst=\@ne
    \setbox#2=\vbox{\unvbox#2\hbox
    to\hsize{\box\c@twslicea\pageinwindow\hfil\box\c@twsliceb}}%
  \else
    \setbox#2=\vbox{\unvbox#2\hbox
    to\hsize{\box\c@twslicea\hfil\box\c@twsliceb}}%
  \fi
  \def\c@twfirst{2}%
  \ifnum\c@twwinlines>\z@\repeat}
\newcommand*{\c@twcomplftrt}[2]{%
  \def\c@twfirst{1}%
  \loop\advance\c@twwinlines\m@ne
  \setbox\c@twslicea=\vsplit#1 to\baselineskip
  \ifnum\c@twl@c=\m@ne%    open left, text at right
    \c@twprune{\c@twslicea}{\c@twrtside}%
    \ifnum\c@twfirst=\@ne
      \setbox#2=\vbox{\unvbox#2\hbox
      to\hsize{\pageinwindow\hfil\box\c@twslicea}}%
    \else
      \setbox#2=\vbox{\unvbox#2\hbox
      to\hsize{\mbox{}\hfil\box\c@twslicea}}%
    \fi
    \def\c@twfirst{2}%
  \else
    \ifnum\c@twl@c=\@ne% open right, text at left
      \c@twprune{\c@twslicea}{\c@twlftside}%
      \ifnum\c@twfirst=\@ne\relax
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\box\c@twslicea\pageinwindow}}%
      \else
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\box\c@twslicea}}%
      \fi
      \def\c@twfirst{2}%
    \fi
  \fi
  \ifnum\c@twwinlines>\z@\repeat}
\newcommand*{\c@twprune}[2]{%
  \unvbox#1 \setbox#1=\lastbox % \box#1 is now an \hbox
  \setbox#1=\hbox to#2{\strut\unhbox#1\unskip}}
\newcommand*{\c@twmakeparspec}{%
  \c@twcnt=\c@twwinlines
  \ifnum\c@twl@c=\z@
    \multiply \c@twcnt by \tw@
  \fi
  \advance\c@twcnt by \c@twtoplines \advance\c@twcnt by \@ne
  \ifnum\c@twtoplines>\z@
    \loop\c@twtoka=\expandafter{\the\c@twtoka 0pt \hsize}%
      \advance\c@twtoplines -1\relax
    \ifnum\c@twtoplines>\z@\repeat
  \fi
  \ifnum\c@twl@c=\m@ne % openleft
    \c@twlftside=\hsize
    \advance\c@twlftside -\c@twrtside
  \fi
  \loop\c@twtoka=%
    \ifnum\c@twl@c=\m@ne % openleft
      \expandafter{\the\c@twtoka \c@twlftside \c@twrtside}%
    \else
      \ifnum\c@twl@c=\@ne % openright
        \expandafter{\the\c@twtoka 0pt \c@twlftside}%
      \else %center
        \expandafter{\the\c@twtoka 0pt \c@twlftside 0pt \c@twrtside}%
      \fi
    \fi
    \advance\c@twwinlines \m@ne
  \ifnum\c@twwinlines>\z@\repeat
  \c@twtoka=\expandafter{\the\c@twtoka 0pt \hsize}}
\newcommand*{\c@twcalcshift}{% vertical shift
  \c@twvsilg=\c@twwinlines\baselineskip
  \ifnum\c@twtoplines<\@ne
    \advance\c@twvsilg -0.25\baselineskip
  \fi
  \c@twvsilg=0.5\c@twvsilg
  \ifnum\c@twl@c=\z@\else
    \c@twvsilg=0.5\c@twvsilg
  \fi}
\newcommand*{\picinwindow}{%
  \begin{picture}(0,0)
  \putstuffinpic
  \end{picture}}
\newcommand*{\putstuffinpic}{}
\newenvironment{shapedcutout}[3]{%
  \cutfuzz
  \c@twtoplines=#1\relax
  \c@twwinlines=#2\relax
  \edef\c@twb{#3}%       user's parspec
  \c@twmaketopoddspec
  \c@twbuildoddspec{#3}
  \c@twtoplines=#1\relax
  \c@twwinlines=#2\relax
  \c@twcalcshift \vskip-\c@twvsilg
  \setbox\c@twrawtext=\vbox\bgroup
  \parshape=\c@twcnt \the\c@twtoka \the\c@twtokb 0pt \hsize}%
 {\egroup
  \parshape=0
  \c@twcalcilg
  \ifnum\c@twtoplines>\z@
    \setbox\c@twfinaltext=\vsplit\c@twrawtext to\c@twtoplines\baselineskip
  \fi
  \c@twtopht=\c@twwinlines\baselineskip
  \ifnum\c@twl@c=\z@ % center
    \c@twtopht=2\c@twtopht
  \fi
  \setbox\c@twholdwin=\vsplit\c@twrawtext to\c@twtopht
  \ifnum\c@twl@c=\z@%    center
    \c@twcompoddctr{\c@twholdwin}{\c@twwindow}%
  \else% open left or right
    \c@twcompoddlftrt{\c@twholdwin}{\c@twwindow}%
  \fi
  \setbox\c@twfinaltext=
    \vbox{\ifnum\c@twtoplines>\z@\unvbox\c@twfinaltext\vskip\c@twvsilg\fi
    \unvbox\c@twwindow%
    \vskip-\c@twvsilg\unvbox\c@twrawtext}%
  \box\c@twfinaltext}
\newcommand*{\c@twmaketopoddspec}{%
  \c@twcnt=\c@twwinlines
  \ifnum\c@twl@c=\z@
    \multiply \c@twcnt by \tw@
  \fi
  \advance\c@twcnt by \c@twtoplines \advance\c@twcnt by \@ne
%% \c@twcnt is total of toplines + 2(window lines) + 1
  \c@twtoka={}%
  \ifnum\c@twtoplines>\z@
    \loop\c@twtoka=\expandafter{\the\c@twtoka 0pt \hsize}%
      \advance\c@twtoplines -1\relax
      \ifnum\c@twtoplines>\z@\repeat
  \fi}
\newcommand*{\c@twaddtospec}[1]{%
  \c@twtokb=\c@twxpf{\the\c@twtokb 0pt #1 }}
\let\c@twxpf\expandafter
\newcommand*{\c@twbuildoddspec}[1]{%
  \c@twtokb={}%
  \@for\c@twlspec:=#1\do{%
    \c@twxpf\c@twxpf\c@twxpf\c@twaddtospec\c@twxpf{\c@twlspec}}}
\newcommand*{\c@twcompoddctr}[2]{%
  \def\c@twrounds{1}%
  \def\c@twfirst{1}%
  \@for\c@twlspec:=\c@twb\do{%
    \ifnum\c@twrounds=1
      \setbox\c@twslicea=\vsplit#1 to\baselineskip % first of pair
      \c@twprune{\c@twslicea}{\c@twlspec}%
      \def\c@twrounds{2}%
    \else
      \setbox\c@twsliceb=\vsplit#1 to\baselineskip % second of pair
      \c@twprune{\c@twsliceb}{\c@twlspec}%
      \ifnum\c@twfirst=1
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\box\c@twslicea\hfil\picinwindow\hfil\box\c@twsliceb}}%
        \def\c@twfirst{2}%
      \else
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\box\c@twslicea\hfil\box\c@twsliceb}}%
      \fi
      \def\c@twrounds{1}%
    \fi}}
\newcommand*{\c@twcompoddlftrt}[2]{%
  \def\c@twfirst{1}%
  \@for\c@twlspec:=\c@twb\do{%
    \setbox\c@twslicea=\vsplit#1 to\baselineskip % get a line
    \c@twprune{\c@twslicea}{\c@twlspec}%
    \ifnum\c@twl@c=\m@ne%   open left, text at right
      \ifnum\c@twfirst=1
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\mbox{}\hfil\picinwindow\hfil\box\c@twslicea}}%
        \def\c@twfirst{2}%
      \else
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\mbox{}\hfil\box\c@twslicea}}%
      \fi
    \else
      \ifnum\c@twl@c=\@ne%  open right, text at left
        \ifnum\c@twfirst=1
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\box\c@twslicea\hfil\picinwindow\hfil}}%
        \def\c@twfirst{2}%
      \else
        \setbox#2=\vbox{\unvbox#2\hbox
        to\hsize{\box\c@twslicea\hfil}}%
      \fi
    \fi
  \fi}}
\endinput
%%
%% End of file `cutwin.sty'.