From 9cdce20e7cb3a162be11edf1cb40ce012be4dd05 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Mon, 27 Dec 2021 21:15:01 +0000
Subject: wrapfig2 (27dec21)

git-svn-id: svn://tug.org/texlive/trunk@61423 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty | 480 ++++++++++++++++++++++
 1 file changed, 480 insertions(+)
 create mode 100644 Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty

(limited to 'Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty')

diff --git a/Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty b/Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty
new file mode 100644
index 00000000000..94ac12506de
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty
@@ -0,0 +1,480 @@
+%%
+%% 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 by Claudio Beccari (claudio.beccari@gmail.com)
+%% License information appended
+%% 
+\NeedsTeXFormat{LaTeX2e}[2019/01/01]
+\ProvidesPackage{wrapfig2}%
+        [2021-12-21 v.4.0 Wrapfig extended]
+
+\NeedsTeXFormat{LaTeX2e}[2020-01-01]
+\ProvidesPackage{wrapfig2}%
+ [2021-11-30 v.4.0 Wrap text around figures, tables, framed text blocks]
+\@ifpackageloaded{etoolbox}{}{\RequirePackage{etoolbox}}
+\ifcsdef{c@WF@wrappedlines}{\endinput}{}
+\ifcsdef{fpeval}{}{\RequirePackage{xfp}}
+\RequirePackage{xparse}
+
+\newdimen\wrapoverhang \wrapoverhang\z@
+\newdimen\WF@size
+\newcounter{WF@wrappedlines}
+\newbox\WF@box
+\newbox\NWF@box
+\newtoks\WF@everypar
+\newif\ifWF@float
+\newcount\WF@correctlines@switch
+\newdimen\insertwidth
+\let\@@parshape\parshape
+\let\WF@@everypar\everypar
+
+\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}
+
+\NewDocumentEnvironment{wraptext}%
+      {O{l}    D||{0.5\columnwidth} D<>{0}   D(){figure}}%
+{%                                                        Open environment
+  \insertwidth=#2\relax
+  \def\textplacement{#1}%
+  \def\textcorrection{#3}%
+  \def\WF@caption@label{#4}%
+  \begin{lrbox}\NWF@box%            This box is to contain the framed text
+    \minipage{\insertwidth}%
+   \tcolorbox
+}{%                                                      Close environment
+  \endtcolorbox\endminipage\end{lrbox}%
+  \edef\NWF@wli%                        \NWF@wli is a macro, not a counter
+    {%
+      \fpeval{%
+        round((\ht\NWF@box+\dp\NWF@box)/\baselineskip,0)+2+\textcorrection
+             }%
+    }%
+  \ifhmode\unskip\else\leavevmode\noindent\fi
+  \bgroup\edef\x{\egroup\noexpand\wrapfloat{\WF@caption@label}[\NWF@wli]%
+      {\textplacement}{\the\insertwidth}}\x
+    \box\NWF@box %                       Output framed box containing text
+  \endwrapfloat
+  \ignorespaces
+}
+
+
+\NewDocumentEnvironment{wrapfloat}{m o m o G{\z@}}%
+  {\def\@captype{#1}\WF@wr[#2]{#3}[#4]{#5}}%
+  {\ifdim\hsize>\z@
+    \par\hrule\@width\hsize\@height\z@ %   force width with invisible rule
+  \else
+    \unskip \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@}%
+  \global\@ignoretrue
+}
+
+\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
+  \@tempdima\pagedepth %                                   save page depth
+  {\advance\parskip\@tempdima\vskip-\parskip}%        back up to base line
+  \penalty\interlinepenalty %                       update page parameters
+  \@tempdimb\pagegoal \advance\@tempdimb-\pagetotal %    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@.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@.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\relax %                        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 lor r; calc 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 %                                                insert on light
+      \@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{\value{WF@wrappedlines}}%
+    \else
+      \setcounter{WF@wrappedlines}{\WF@wli}%      absolute number of lines
+      \global\advance\c@WF@wrappedlines\@ne
+    \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
+    \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
+  \@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
+  \@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
+
+\@ifundefined{DeclareOption}{\endinput}{%
+\def\WF@warning{\PackageWarning{wrapfig2}}%
+\DeclareOption{verbose}{\def\WF@info{\PackageInfo{wrapfig2}}}%
+\ProcessOptions
+\AtEndDocument{\WFclear}}%
+
+%% 
+%% 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 the auxiliary file README.txt.
+%% 
+%%
+%% End of file `wrapfig2.sty'.
-- 
cgit v1.2.3

