%% %% 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-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 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 \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 \newcounter{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\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} \NewDocumentEnvironment{wraptable}{o m o G{0pt}}% {\wrapfloat{table}[#1]{#2}[#3]{#4}}% {\endwrapfloat} \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}% }% }{\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@}}% {\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 \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 \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 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 % 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 %% %% 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'.