From 0b19d44096eb613853c6b04e08fbe716091c8798 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Wed, 26 Jan 2022 21:09:26 +0000
Subject: wrapfig2 (26jan22)

git-svn-id: svn://tug.org/texlive/trunk@61749 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty | 192 +++++++++++++++++-----
 1 file changed, 149 insertions(+), 43 deletions(-)

(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
index f805080f5af..0fe642f2490 100644
--- a/Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty
+++ b/Master/texmf-dist/tex/latex/wrapfig2/wrapfig2.sty
@@ -7,20 +7,51 @@
 %% 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)
+%% Copyright (C) 2021-2022 by Claudio Beccari (claudio.beccari@gmail.com)
 %% License information appended
 %% 
 \NeedsTeXFormat{LaTeX2e}[2019/01/01]
 \ProvidesPackage{wrapfig2}%
-        [2022-01-03 v.4.0.1 Wrapfig extended]
+ [2022-01-26 v.5.0.7 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 `wrapfig2' 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'; otherwise you get errors about such      \MessageBreak
+  environment not being defined; 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
+\DeclareOption{WFold}{\let\ifWFnew\iffalse}
+\ProcessOptions
 
-\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}
+\@ifpackageloaded{xfp}{}{\RequirePackage{xfp}}
+\@ifpackageloaded{etoolbox}{}{\RequirePackage{etoolbox}}
+\@ifpackageloaded{float}{}{\RequirePackage{float}}
+\@ifpackageloaded{color}{}{%
+   \@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}%
+ }
+\@ifpackageloaded{curve2e}{}{\RequirePackage{curve2e}}
+
+\ifWFnew
+  \floatstyle{plain}
+  \ifcsname chapter\endcsname
+    \newfloat{text}{tbp}{lotx}[chapter]
+  \else
+    \newfloat{text}{tbp}{lotx}
+  \fi
+  \floatname{text}{Text}
+  \let\WF@text@caption\float@caption
+\fi
 
 \newdimen\wrapoverhang \wrapoverhang\z@
 \newdimen\WF@size
@@ -30,10 +61,34 @@
 \newtoks\WF@everypar
 \newif\ifWF@float
 \newcount\WF@correctlines@switch
-\newdimen\insertwidth
 \let\@@parshape\parshape
 \let\WF@@everypar\everypar
 
+\newdimen\insertwidth
+\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}
+
+\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
+}%
+
 \NewDocumentEnvironment{wrapfigure}{o m o G{0pt}}%
   {\wrapfloat{figure}[#1]{#2}[#3]{#4}}%
   {\endwrapfloat}
@@ -42,31 +97,88 @@
   {\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
-             }%
+\NewDocumentCommand\includeframedtext{O{\insertwidth} m O{1pt,1ex} o}%
+{\bgroup \WFsplitdimens #3!%
+\insertwidth=#1\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=0pt\fboxsep=#3\relax
+\framebox{\parbox{%
+  \fpeval{\insertwidth-2\fboxrule-2\fboxsep}pt}{\textcolor{WFtext}{#1}}}}%
+\unitlength=\fpeval{\wd0/100}pt
+\edef\x{100}\edef\y{\fpeval{(\ht0 +\dp0)/\unitlength}}%
+\edef\xc{50}\edef\yc{\fpeval{\y/2}}\edef\R{\fpeval{#4/\unitlength}}%
+\edef\WFXds{\fpeval{-\xc+\R}}\edef\WFXsd{-\WFXds}%
+\edef\WFYuo{\fpeval{\yc-\R}}\edef\WFYou{-\WFYuo}%
+\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{%
+  (\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*}%
+\begin{picture}(\x,\y)(-\xc,-\yc)
+{\color{WFbackground}\expandafter\CurveStar\WFrectangle}%
+{\color{WFframe}\linethickness{#2}\expandafter\Curve\WFrectangle}%
+\put(0,0){\makebox(0,0)[cc]{\box0}}%
+\end{picture}
+\egroup}
+
+\ifWFnew
+\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}%
     }%
-  \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
-}
+}{\endwrapfloat\ignorespaces}%
+\else %
+  \NewDocumentEnvironment{wraptext}%
+        {O{l}    D||{0.5\columnwidth} D<>{0}   D(){text}    }%
+  {%
+    \insertwidth=#2
+    \def\textplacement{#1}%
+    \def\textcorrection{#3}%
+    \def\WF@caption@label{#4}%
+    \setbox0\hbox\bgroup
+      \minipage{\dimexpr\insertwidth-2pt-6ex}%
+}{\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
+  }
+\fi
 
 
 \NewDocumentEnvironment{wrapfloat}{m o m o G{\z@}}%
@@ -182,7 +294,7 @@
   \vskip-\parskip \global\WF@floatfalse
   \let\pagetotal\maxdimen %              kludge flag for "not top of page"
 \else %                                                         outer page
-  \@tempdima\pagedepth %                                   save page depth
+  \unless\ifWFnew \@tempdima\pagedepth \fi%                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
@@ -222,7 +334,7 @@
    \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; calc effective width
+  \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
@@ -306,7 +418,7 @@
 }
 
 \def\WF@modps{\begingroup
-  \afterassignment\@tempdimb \@tempdima\WF@pspars % a=indent.num, b= width
+  \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
@@ -459,12 +571,6 @@
   \@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
@@ -473,7 +579,7 @@
 %% 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.
+%% wrapfig2.sty and wrapfig2.pdf, plus this file README.txt.
 %% 
 %%
 %% End of file `wrapfig2.sty'.
-- 
cgit v1.2.3

