summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty
blob: 508e88fc576cd5cefe8c363b540f1ecccef26417 (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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
%%
%% This is file `wrapfig2.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% wrapfig2.dtx  (with options: `package')
%% 
%% Copyright (C) 1991-2003 by Donald Arseneau  (asnd@triumf.ca)
%% Copyright (C) 2021-2022 by Claudio Beccari (claudio.beccari@gmail.com)
%% License information appended
%% 
\NeedsTeXFormat{LaTeX2e}[2019/01/01]
\ProvidesPackage{wrapfig2}%
 [2022-02-16 v.6.0.0 Wrap text around figures, tables, framed text blocks]
\ifcsname c@WF@wrappedlines\endcsname
\PackageError{wrapfig2}{                              \MessageBreak
  ****************************************************\MessageBreak
  Package `wrapfig' has already been loaded perhaps   \MessageBreak
  by other packages, for example caption or subcaption.\MessageBreak
  Such packages are incompatible with wrapfig2        \MessageBreak
  Loading of`wrapfig2' is aborted                     \MessageBreak
  ****************************************************\MessageBreak
}{You might type X <return> and might get along without\MessageBreak
  this package if you don't use the new environment   \MessageBreak
 `wraptext' and the new commands; otherwise you get   \MessageBreak
  errors about such environment not being defined;    \MessageBreak
  you must kill your job!}
\expandafter\endinput\fi

\def\WF@warning{\PackageWarning{wrapfig2}}
\DeclareOption{verbose}{\def\WF@info{\PackageInfo{wrapfig2}}}
\newif\ifWFnew \let\ifWFnew\iftrue
\newif\ifWFfive \let\ifWFfive\iffalse
\DeclareOption{WFold}{\let\ifWFnew\iffalse}
\DeclareOption{WFfive}{\let\ifWFnew\iffalse \let\ifWFfive\iftrue}
\ProcessOptions

\RequirePackage{xparse}
\@ifpackageloaded{xfp}{}{\RequirePackage{xfp}}
\@ifpackageloaded{etoolbox}{}{\RequirePackage{etoolbox}}
\@ifpackageloaded{float}{}{\RequirePackage{float}}
\@ifpackageloaded{color}{}{%
   \@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}%
 }
\@ifpackageloaded{curve2e}{}{\RequirePackage{curve2e}}
\@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}}

\ifboolexpr{ bool{WFfive} or bool{WFnew} }%
   {\floatstyle{plain}%
  \ifcsname chapter\endcsname
    \newfloat{text}{tbp}{lotx}[chapter]%
  \else
    \newfloat{text}{tbp}{lotx}%
  \fi
  \floatname{text}{Text}% come personalizzare con le diverse lingue?
  \let\WF@text@caption\float@caption
  }{}

\newdimen\wrapoverhang \wrapoverhang\z@
\newdimen\WF@size
\newcount\c@WF@wrappedlines
\newbox\WF@box
\newbox\NWF@box
\newtoks\WF@everypar
\newif\ifWF@float
\newcount\WF@correctlines@switch
\let\@@parshape\parshape
\let\WF@@everypar\everypar

\newdimen\insertwidth
\newdimen\radius
\newdimen\WFinsertwidthL
\newdimen\WFinsertwidthH

\definecolor{WFbackground}{rgb}{0.95,0.95,0.95}
\definecolor{WFframe}{rgb}{0.1,0.1,0.1}
\colorlet{WFtext}{black}
\def\SetWFbgd#1{\colorlet{WFbackground}{#1}}
\def\SetWFfrm#1{\colorlet{WFframe}{#1}}
\def\SetWFtxt#1{\colorlet{WFtext}{#1}}

\def\WFsplitdimens#1,#2!{\fboxrule=#1\relax\fboxsep=#2\relax}

\providecommand\setfontsize{}
\RenewDocumentCommand\setfontsize{O{1.2} m}{%
  \fontsize{#2}{\fpeval{#1*#2}}\selectfont}

\def\WFscalefactor{0.8}%
\newcommand*\WFscalewidth{%
  \WFinsertwidthL=\fpeval{\WFscalefactor*0.5\columnwidth}\p@
  \WFinsertwidthH=\fpeval{0.5\columnwidth/\WFscalefactor}\p@
  \ifdim\insertwidth<\WFinsertwidthL
    \insertwidth=\WFinsertwidthL
  \else
    \ifdim\insertwidth>\WFinsertwidthH
      \insertwidth=\WFinsertwidthH
    \fi
  \fi
}%

\DeclareOptionX<wraptext>{scalefactor}[0.8]{\def\WFscalefactor{#1}}
\DeclareOptionX<wraptext>{fboxrule}[1pt]{\fboxrule=#1}
\DeclareOptionX<wraptext>{fboxsep}[1ex]{\fboxsep=#1}
\DeclareOptionX<wraptext>{framecolor}[WFframe]{\SetWFfrm{#1}}
\DeclareOptionX<wraptext>{backgroundcolor}[WFbackground]{\SetWFbgd{#1}}
\DeclareOptionX<wraptext>{textcolor}[WFtext]{\SetWFtxt{#1}}
\DeclareOptionX<wraptext>{fontstyle}[\normalfont]{#1}
\DeclareOptionX<wraptext>{radius}[\fboxsep]{\radius=#1}
\DeclareOptionX<wraptext>{insertionwidth}[0.5\columnwidth]{\insertwidth=#1}

\DeclareOptionX*{\PackageWarning{wrapfig2}{`\CurrentOption' ignored}}

\ExecuteOptionsX<wraptext>{scalefactor, fboxrule, fboxsep, framecolor,
backgroundcolor, textcolor, fontstyle, radius, insertionwidth}

\ProcessOptionsX*

\NewDocumentEnvironment{wrapfigure}{o m o G{0pt}}%
  {\wrapfloat{figure}[#1]{#2}[#3]{#4}}%
  {\endwrapfloat}

\NewDocumentEnvironment{wraptable}{o m o G{0pt}}%
  {\wrapfloat{table}[#1]{#2}[#3]{#4}}%
  {\endwrapfloat}

\ifbool{WFnew}{%
\NewDocumentCommand\includeframedtext{O{\insertwidth} m O{} o}{\bgroup%
  \ExecuteOptionsX<wraptext>{#3}%     executes possible key=value options
  \insertwidth=#1\WFscalewidth
  \framedbox{#2}{\fboxrule}{\fboxsep}[\radius]\egroup}
}{}

\ifbool{WFfive}{%
\NewDocumentCommand\includeframedtext{O{\insertwidth} m O{1pt,1ex} o}%
{\bgroup
  \WFsplitdimens #3!\relax
  \IfNoValueTF{#4}%
    {\framedbox{#2}{\fboxrule}{\fboxsep}}%
    {\framedbox{#2}{\fboxrule}{\fboxsep}[#4]}
\egroup}%
}{}

\NewDocumentCommand\framedbox{ m m m O{#3}}{\bgroup
\fboxrule=#2\fboxsep=#3\relax
\setbox0\hbox{\fboxrule=\z@\fboxsep=#3\relax
\framebox{\parbox{%                    draw a framed box without the frame
  \fpeval{\insertwidth-2\fboxrule-2\fboxsep}\p@}{\textcolor{WFtext}{#1}}}}

\unitlength=\fpeval{\wd0/100}\p@ %             set the picture \unitlength
 %   determine the picture coordinates and displacement of the axes origin
\edef\x{100}%
\edef\y{\fpeval{(\ht0 +\dp0)/\unitlength}}%
\edef\xc{50}%
\edef\yc{\fpeval{\y/2}}\edef\R{\fpeval{#4/\unitlength}}%
\edef\R{\fpeval{#4/\unitlength}}%                   radius in unit lengths
 %        compute the horizontal and vertical shifts of the corner extrema
\edef\WFXds{\fpeval{-\xc+\R}}\edef\WFXsd{-\WFXds}%
\edef\WFYuo{\fpeval{\yc-\R}}\edef\WFYou{-\WFYuo}%
 %             compute the coordinates of the curved corners frame contour
\edef\PSEl{\WFXsd,-\yc}\edef\PSEu{\xc,\WFYou}\edef\PNEd{\xc,\WFYuo}%
\edef\PNEl{\WFXsd,\yc}\edef\PNWr{\WFXds,\yc}\edef\PNWd{-\xc,\WFYuo}%
\edef\PSWu{-\xc,\WFYou}\edef\PSWr{\WFXds,-\yc}%

\def\WFrectangle{%            define the contour as the argument of \Curve
  (\WFXsd,-\yc)<1,0>(\xc,\WFYou)<0,1>(\xc,\WFYuo)<0,1>%
  (\WFXsd,\yc)<-1,0>(\WFXds,\yc)<-1,0>(-\xc,\WFYuo)<0,-1>%
  (-\xc,\WFYou)<0,-1>(\WFXds,-\yc)<1,0>(\WFXsd,-\yc)<1,0>}%
\def\CurveStar{\Curve*}%            define a macro for adding the asterisk

\begin{picture}(\x,\y)(-\xc,-\yc)
{\color{WFbackground}\expandafter\CurveStar\WFrectangle}%  draw background
\ifdim\fboxrule>\z@%           draw the frame if its thickness is not zero
  {\color{WFframe}\linethickness{#2}\expandafter\Curve\WFrectangle}%
\fi
 %              put the text block in a null box at the coordinates origin
\put(0,0){\makebox(0,0)[cc]{\box0}}%
\end{picture}
\egroup}

\ifboolexpr{bool{WFnew} or bool{WFfive}}{% definition for versions 5 and 6
\NewDocumentEnvironment{wraptext}{O{0} m O{0pt} G{0.5\columnwidth}}{%
  \insertwidth=#4\WFscalewidth
  \def\textplacement{#2}%
  \def\textcorrection{#1}%
  \def\textoverhang{#3}%
  \bgroup\edef\x{\egroup\noexpand\wrapfloat{text}%
    [\textcorrection]{\textplacement}[\textoverhang]{\insertwidth}*}\x%
  \def\caption{\unskip
    \refstepcounter\@captype
    \let\@tempf\@caption
    \unless\ifcsname @float@c@\@captype\endcsname
      \expandafter\expandafter\let
        \expandafter\@tempf\csname @float@c@\@captype\endcsname
    \fi
    \@dblarg{\@caption\@captype}%
    }%
}{\endwrapfloat\ignorespaces}%
}{%                                     definition for version 4 fall back
  \NewDocumentEnvironment{wraptext}%
        {O{l}    D||{0.5\columnwidth} D<>{0}   D(){text}    }%
  {%                                                      Open environment
    \insertwidth=#2
    \def\textplacement{#1}%
    \def\textcorrection{#3}%
    \def\WF@caption@label{#4}%
    \setbox0\hbox\bgroup
      \minipage{\dimexpr\insertwidth-2pt-6ex}%
}{%                                                      Close environment
  \endminipage\egroup
    \begin{lrbox}{\NWF@box}%
      \framedbox{\box0}{1pt}{1ex}%
    \end{lrbox}
    \edef\NWF@wli]{\fpeval{%
      round((\ht\NWF@box+\dp\NWF@box)/\baselineskip,0)+2+\textcorrection}%
                          }%
    \unles\ifhmode
      \leavevmode\noindent
    \fi
    \bgroup\edef\x{\egroup\noexpand\wrapfloat{\WF@caption@label}[\NWF@wli]%
        {\textplacement}{\the\insertwidth}}\x
      \box\NWF@box
    \endwrapfloat
    \ignorespaces
  }
}

\NewDocumentEnvironment{wrapfloat}{m o m o G{\z@}}%
{%                                                   open environment code
    \def\@captype{#1}\WF@wr[#2]{#3}[#4]{#5}%
}{%                                                 close environment code
  \ifdim\hsize>\z@
    \par\hrule\@width\hsize\@height\z@ %   force width with invisible rule
  \else
    \egroup \box\z@  %                                       or close hbox
  \fi
 \egroup %                      close the vtop box; its width now is known
  \WF@floatstyhook %                                 support for float.sty
  \def\width{\wd\WF@box}%
  \setlength\wrapoverhang{\WF@ovh}%
  \xdef\WF@ovh{\the\wrapoverhang}%                     save until wrapping
  \ifdim\ht\WF@box>\topskip \ht\WF@box\z@ \fi%          too high, set flag
  \ifdim\ht\WF@box<.5\p@ %                              too short, move up
    \global\setbox\WF@box\vtop{\vskip-1.4ex\unvbox\WF@box}%
  \fi
   \global\WF@size=%                  compute total box hight with \fpeval
     \fpeval{\ht\WF@box+\dp\WF@box+1.5\baselineskip+\tw@\intextsep}\p@
   \aftergroup\WF@startfloating %        use even when not really floating
  \unless\ifWF@float
    \ifhmode
      {\unskip \parfillskip\z@skip \par \vskip-\parskip}%
      \aftergroup\noindent
    \fi
  \fi
  \global\@ignoretrue
}

\NewDocumentCommand\WF@wr{o m o m s}{%
  \xdef\WF@wfname{wrap\@captype\space}%
  \unless\ifvoid\WF@box
    \WFclear \WF@collision
  \fi
  \xdef\WF@place{\string`\@car#2r\@nil}%
  \ifnum\lccode\WF@place=\WF@place
      \global\WF@floatfalse
  \else
      \global\WF@floattrue
  \fi
  \ifx\parshape\WF@fudgeparshape
    \unless\ifWF@float\\WF@collision\fi
  \else
    \ifx\par\@@par
      \ifnum\@@parshape>\z@\WF@conflict\fi
    \else
      \WF@conflict
    \fi
   \fi
   \IfValueTF{#1}%                 save optional line number or correction
     {\gdef\WF@wli{#1}}%
     {\gdef\WF@wli{0}}%
  \IfValueTF{#3}%                                   save optional overhang
      {\gdef\WF@ovh{#3}}%
      {\gdef\WF@ovh{\z@}}%
   \global\setbox\WF@box\vtop\bgroup \setlength\hsize{#4}%       set width
   \ifdim\hsize>\z@
     \@parboxrestore
   \else
     \setbox\z@\hbox\bgroup
     \let\wf@@caption\caption
     \let\caption\wf@caption
     \ignorespaces
   \fi
  \IfBooleanTF{#5}%    if the asterisk is present set the numerical switch
              {\global\WF@correctlines@switch=\@ne}%
              {\global\WF@correctlines@switch=\z@}%

}
\def\wf@caption{\relax%        redefine \wf@caption in case \hsize is zero
  \ifdim\hsize>\z@
    \let\caption\wf@@caption
  \else
    \unskip \egroup \hsize\wd\z@ \@parboxrestore \box\z@%      empty \box0
  \fi
  \caption
}

\def\WF@startfloating{%
 \WF@everypar\expandafter{\the\everypar}\let\everypar\WF@everypar
 \WF@@everypar{\ifvoid\WF@box\else\WF@floathand\fi \the\everypar
 \WF@wraphand
}}

\def\WF@floathand{%
  \ifx\parshape\WF@fudgeparshape
    \WF@fltmes
  \else
    \ifx\par\@@par
      \ifnum\@@parshape=\z@
        \ifdim\hangindent=\z@
          \setbox\z@\lastbox \begingroup
          \@@par \WF@@everypar{}\WF@putfigmaybe
          \endgroup %                      after this group start wrapping
          \unless\ifvoid\z@ %                          replace indentation
              \box\z@
          \fi
        \else
          \WF@fltmes
        \fi
      \else
        \WF@fltmes
      \fi
    \else
      \WF@fltmes
    \fi
  \fi}

\def\WF@putfigmaybe{%
\ifinner
  \vskip-\parskip \global\WF@floatfalse
  \let\pagetotal\maxdimen %              kludge flag for "not top of page"
\else %                                                         outer page
  {\advance\parskip\@tempdima\vskip-\parskip}%        back up to base line
  \penalty\interlinepenalty %                       update page parameters
  \@tempdimb\dimexpr\pagegoal - \pagetotal \relax%       room left on page
  \ifdim \@tempdimb<\z@ %                                page already full
    \global\WF@floatfalse
    \unless\ifdim-\@tempdimb>\pageshrink \pagebreak \fi
  \else
    \ifdim\WF@size>\@tempdimb%     box too high does not fit in \@tempdimb
      \ifWF@float
        \dimen@ 0.5\baselineskip
      \else
        \dimen@ 2\baselineskip
      \fi
      \ifdim\pagestretch>\dimen@ \dimen@\pagestretch \fi
      \ifdim\pagefilstretch>\z@ \dimen@\@tempdimb \fi
      \ifdim\pagefillstretch>\z@ \dimen@\@tempdimb \fi
      \advance\dimen@ 0.5\baselineskip
      \ifdim\dimen@>\@tempdimb %                     stretch page contents
        \global\WF@floatfalse \pagebreak
      \fi
    \else %                                         box fits in \@tempdimb
      \global\WF@floatfalse
    \fi
  \fi
  \vskip\@tempdima%                               return erased page depth
\fi
\noindent
\ifWF@float
  \WF@fltmes
\else %                                               place insertion here
  \WF@info{Put \WF@wfname here:}%
  {\ifodd
     \if@twoside\c@page\else\@ne\fi %          assign l/r to i/o placement
     \lccode`i`l\lccode`o`r\else \lccode`i`r\lccode`o`l%
   \fi
   \xdef\WF@place{\the\lccode\lccode\WF@place}%
                 }%                               twice to get only l or r
  \hbox to\z@{% llap o rlap depending on l or r; determine effective width
    \@tempdima\wd\WF@box \@tempdimb\WF@ovh
    \advance\@tempdima-\@tempdimb \advance\@tempdima\columnsep
    \@tempdimb\hsize \advance\@tempdimb-\@tempdima
    \xdef\WF@adjlw{\the\@tempdima}%
    \ifnum `l=\WF@place %                                   object on left
      \hss
      \def\@tempa{\kern\columnsep}%             take right gap into action
    \else %                                                object on right
      \@tempdima\z@ %                                  no left indentation
      \kern\@tempdimb \kern\columnsep
      \def\@tempa{\hss}%                object overlaps space to the right
    \fi
    \ifdim\@tempdimb<\hsize
      \xdef\WF@wrapil{\the\@tempdima \the\@tempdimb}%  indent.n and length
      \xdef\WF@adjtlm{\the\@tempdima}%
    \else
      \xdef\WF@wrapil{\z@ \the\hsize}%
      \xdef\WF@adjlw{\z@}\xdef\WF@adjtlm{\z@}%
    \fi
    \ifdim\pagetotal=\z@ %              put object at top of page \thepage
      \global\advance\WF@size-\intextsep
    \else %                               put object in middle of the page
      \setbox\WF@box\hbox{\lower\intextsep\box\WF@box}%
    \fi
    \dp\WF@box\z@
    \box\WF@box
    \@tempa
  }%                                                      end \hbox to 0pt
  \aftergroup\WF@startwrapping
\fi
}

\def\WF@startwrapping{%
  \ifnum\WF@wli=\z@ %                              no number was specified
    \setcounter{WF@wrappedlines}%
      {\fpeval{round(\WF@size/\baselineskip,0)}}%
    \xdef\WF@wli{\value{WF@wrappedlines}}%
  \else
    \ifnum\WF@correctlines@switch>\z@ %             line number correction
      \setcounter{WF@wrappedlines}
        {\fpeval{round((\WF@size)/\baselineskip,0)+\WF@wli}}%
      \xdef\WF@wli{\the\c@WF@wrappedlines}%
    \else
      \setcounter{WF@wrappedlines}{\WF@wli}%      absolute number of lines
      \stepcounter{WF@wrappedlines}%
    \fi
  \fi
  \ifnum\c@WF@wrappedlines>\@ne %                              fine tuning
    \let\parshape\WF@fudgeparshape \let\WF@pspars\@empty \let\WF@@par\par
    \def\@setpar##1{\def\WF@@par{##1}}\def\par{\@par}\let\@par\WF@mypar
    \xdef\WF@restoretol{\tolerance\the\tolerance}\tolerance9999\relax
    \advance\linewidth-\WF@adjlw \advance\@totalleftmargin\WF@adjtlm
  \fi
}

\def\WF@wraphand{%                    for indenting one or more paragraphs
  \ifnum\c@WF@wrappedlines<\tw@
    \WF@finale
  \else \begingroup %                            create a parshape command
    \@tempcnta\@ne \let\WF@wrapil\relax \gdef\WF@ps{}%
    \@whilenum
      \@tempcnta<\c@WF@wrappedlines\do{%              repeated indentation
      \xdef\WF@ps{\WF@ps\WF@wrapil}\advance\@tempcnta\@ne
      }%
    \endgroup
    \ifx\WF@pspars\@empty
      \@@parshape\c@WF@wrappedlines \WF@ps \WF@noil
    \else %           use external `parshape' values to modify my parshape
      \WF@modps
    \fi
  \fi
}

\def\WF@mypar{\relax
  \WF@@par
  \ifnum\@@parshape=\z@
    \let\WF@pspars\@empty %                                 reset parshape
  \fi
  \global\advance\c@WF@wrappedlines-\prevgraf \prevgraf\z@
  \ifnum\c@WF@wrappedlines<\tw@
    \WF@finale
  \fi
}

\def\WF@modps{\begingroup
  \afterassignment\@tempdimb \@tempdima\WF@pspars %  a=indent.num, b=width
  \advance\@tempdima-\WF@adjtlm \advance\@tempdimb\WF@adjlw
  \let\WF@wrapil\WF@pspars
  \edef\@tempb{\@@parshape\c@WF@wrappedlines
                \WF@ps \the\@tempdima \the\@tempdimb}%
  \expandafter\endgroup\@tempb
}

\let\@@setpar\@setpar
\def\WF@noil{\z@ \hsize}
\let\WF@pspars\@empty

\def\WF@fudgeparshape{\relax
  \ifnum\c@WF@wrappedlines<\tw@
    \WF@finale
  \else
    \afterassignment\WF@fudgeparshapee \fam
  \fi
}

\def\WF@fudgeparshapee{%
  \ifnum\fam=\@ne \expandafter
    \WF@parshapeee
  \else
    \WF@conflict \@@parshape\fam
  \fi
}

\def\WF@parshapeee#1#2{%
  \begingroup\delimitershortfall#1%
  \nulldelimiterspace#2%         \advance \nulldelimiterspace by \WF@adjlw
  \edef\@tempa{\def\noexpand\WF@pspars{%
      \the\delimitershortfall \the\nulldelimiterspace}}%
  \expandafter\endgroup\@tempa \WF@wraphand
}

\def\WF@finale{%
  \ifx\parshape\WF@fudgeparshape
    \WF@restoretol \let\@setpar\@@setpar \let\par\WF@@par
    \advance\linewidth\WF@adjlw \advance\@totalleftmargin-\WF@adjtlm
    \WF@info{Finish wrapping text}%
    \ifx\par\@@par
      \def\@par{\let\par\@@par\par}%
    \else
      \let\@par\WF@@par
    \fi
    \let\parshape\@@parshape
    \parshape=\ifx\WF@pspars\@empty
                \z@
              \else
                \@ne \WF@pspars
              \fi
  \fi
  \ifvoid\WF@box
    \ifx\everypar\WF@everypar
      \let\everypar\WF@@everypar \everypar\expandafter{\the\WF@everypar}%
    \fi
  \fi
}

\newcommand{\WFclear}{\par
  \unless\ifvoid\WF@box
    \vskip\bigskipamount \box\WF@box
    \let\everypar\WF@@everypar \everypar\expandafter{\the\WF@everypar}%
  \fi
  \global\c@WF@wrappedlines\z@ \WF@finale
  \global\WF@correctlines@switch\z@
}

\begingroup
 \toks0={\let\everypar\WF@@everypar
         \everypar\expandafter{\the\WF@everypar}%
         \let\parshape\@@parshape
         \let\@setpar\@@setpar
        }
 \toks1=\expandafter{\@arrayparboxrestore}%
 \toks2=\expandafter{\clearpage}%
 \edef\@tempa{%
      \def\noexpand\@arrayparboxrestore{\the\toks0 \the\toks1}%
      \def\noexpand\clearpage
      {\noexpand\protect\noexpand\WFclear \the\toks2}}%
 \expandafter
 \endgroup\@tempa

\@ifundefined{@capwidth}{\let\@capwidth\hsize}{}%

\def\WF@conflict{\WF@warning
  {\WF@wfname used inside a conflicting environment}}%

\def\WF@collision{\WF@warning{Collision between wrapping environments}}%

\def\WF@fltmes{%                                        message for floats
  \ifWF@float
    \WF@info{\WF@wfname floats}%
 \else
   \WF@warning{Stationary \WF@wfname forced to float}%
 \fi
}

\let\WF@warning\@warning
\let\WF@info\@gobble

\let\WF@floatstyhook\relax

\@ifundefined{newfloat}{}{%         \newfloat comes from somewhere besides
 %                                                               float.sty
  \@ifundefined{restylefloat}{%
    \@ifclassloaded{memoir}{%
      \toks@=\expandafter\expandafter\expandafter
       {\csname\string\newfloat\endcsname [{#1}]{#2}{#3}{#4}%
       \newenvironment{wrap#2}{\wrapfloat{#2}}{\endwrapfloat}%
      }%                             Mmmm; this might be wrong. Not tested
   \edef\@tempa{\def\expandafter\noexpand\csname\string\newfloat\endcsname
        [##1]##2##3##4{\the\toks@}}%
      \@tempa
     }%                                                 end memoir support
     {}%                                  other origins of \newfloat here?
  }{%          float.sty handler. Ops: Two versions for different versions
 %           Changing \floatstyle or \restylefloat changes also \newfloat.
  \@ifundefined{float@restyle}%
    {%                                                     older float.sty

      \toks@=\expandafter{\restylefloat{##1}%       env. might be undefined
      \@namedef{wrap#1}{%
        \def\@captype{#1}\@nameuse{fst@#1}%
        \def\WF@floatstyhook{\let\@currbox\WF@box \columnwidth\wd\WF@box
          \global\setbox\WF@box\float@makebox}%
      \@ifnextchar[\WF@wr{\WF@wr[]}}%
      \expandafter\let\csname endwrap#1\endcsname \endwrapfigure
      }%
    \edef\@tempa{\def\noexpand\restylefloat##1{\the\toks@}}%
  }{%             newer float.sty: uses \float@restyle, and \float@makebox
      \toks@=\expandafter{\float@restyle{#1}%      env. might be undefined
        \@namedef{wrap#1}{\def\@captype{#1}\@nameuse{fst@#1}%
          \def\WF@floatstyhook{\let\@currbox\WF@box
            \global\setbox\WF@box\float@makebox{\wd\WF@box}}%
        \@ifnextchar[\WF@wr{\WF@wr[]}}%
        \expandafter\let\csname endwrap#1\endcsname \endwrapfigure
      }%
      \edef\@tempa{\def\noexpand\float@restyle##1{\the\toks@}}%
    }%
    \@tempa %                                        perform redefinitions
    }%                                               end float.sty handler
}%                                          end redefinitions of \newfloat

\ifcsname newfloatlist\endcsname%                     support ccaption.sty
  \toks@=\expandafter\expandafter\expandafter
    {\csname\string\newfloatlist\endcsname [{#1}]{#2}{#3}{#4}{#5}%
  \@namedef{wrap#2}{\wrapfloat{#2}}%
  \expandafter\let\csname endwrap#2\endcsname \endwrapfloat
  }%
  \edef\@tempa{%
  \def\expandafter\noexpand\csname\string\newfloatlist\endcsname
   [##1]##2##3##4##5{\the\toks@}}%
  \@tempa
\fi

%% 
%% Distributable under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained"
%% 
%% This work  consists of file  wrapfig2.dtx, and the derived  files
%% wrapfig2.sty and wrapfig2.pdf, plus this file README.txt.
%% 
%%
%% End of file `wrapfig2.sty'.