%
% pxstfloats.sty
% written by Hironobu Yamashita (@aminophen)
%
% This package is actually part of the pxsttools bundle, but
% for now distributed as part of the plautopatch bundle.
% https://github.com/aminophen/plautopatch
%
% This package is expected to be compatible with
%   * stfloats.sty in sttools
%     (2012/05/29 v1.1 -- 2017/03/27 v3.3)
%   * plcore.ltx in platex
%     (2001/09/26 v1.2a -- 2021/06/03 v1.3j)
% Many thanks to lltjp-stfloats.sty in LuaTeX-ja project.
%

\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{pxstfloats}
  [2021/05/24 v0.2a stfloats package for pLaTeX]
\RequirePackage{stfloats}

\ifx\pltx@adjust@wd@outputbox\@undefined
  % pLaTeX2e <2020-10-01>+2 or older
  \ifx\pdfprimitive\@undefined % just in case ...
    \def\pltx@adjust@wd@outputbox{%
      \ifydir\else\vbox{\hskip\z@}\fi}
  \else                        % same as plcore.dtx 2021/03/25 v1.3i
    \def\pltx@adjust@wd@outputbox{%
      \ifydir\else\vbox{\pdfprimitive\everypar{}\hskip\z@}\fi}
  \fi
\fi

%% mostly based on \fn@makecol in stfloats.sty, and
%% the additions for supporting pLaTeX are based on
%% pLaTeX2e 2021-06-01 community ed.
%% the code is essentially compatible with
%%   fnpos.sty (yafoot) 1999/07/14 v1.0
%%   |\makeFNmid| + |\makeFNbelow| status.
\gdef\pxstfl@fnbelowfl@makecol{%
    \setbox\@outputbox \box\@cclv
    \let\@elt\relax
    \xdef\@freelist{\@freelist\@midlist}%
    \global \let \@midlist \@empty
    \@combinefloats
    \ifvoid\footins
    \else
        \setbox\@outputbox \vbox {%
            \boxmaxdepth \@maxdepth
            \unvbox \@outputbox
            \vskip \skip\footins
            \color@begingroup
                \normalcolor
                \footnoterule
                \unvbox \footins
            \color@endgroup
            }%
    \fi
    \ifvbox\@kludgeins
        \@makespecialcolbox
    \else
        \setbox\@outputbox \vbox to\@colht {%
            \@texttop
            \dimen@ \dp\@outputbox
            \unvbox \@outputbox
            \pltx@adjust@wd@outputbox %% for pLaTeX
            \vskip -\dimen@
            \@textbottom
            }%
    \fi
    \global \maxdepth \@maxdepth
}

%% mostly based on \@makecol in latex.ltx, and
%% the additions for supporting pLaTeX are based on
%% pLaTeX2e 2021-06-01 community ed.
%% the code is essentially compatible with
%%   fnpos.sty (yafoot) 1999/07/14 v1.0
%%   |\makeFNmid| + |\makeFNabove| status.
\gdef\pxstfl@fnabovefl@makecol {%
   \ifvoid\footins
     \setbox\@outputbox \box\@cclv
   \else
     \setbox\@outputbox \vbox {%
       \boxmaxdepth \@maxdepth
       \unvbox \@cclv
       \vskip \skip\footins
       \color@begingroup
         \normalcolor
         \footnoterule
         \unvbox \footins
       \color@endgroup
       }%
   \fi
   \let\@elt\relax
   \xdef\@freelist{\@freelist\@midlist}%
   \global \let \@midlist \@empty
   \@combinefloats
   \ifvbox\@kludgeins
     \@makespecialcolbox
   \else
     \setbox\@outputbox \vbox to\@colht {%
       \@texttop
       \dimen@ \dp\@outputbox
       \unvbox \@outputbox
       \pltx@adjust@wd@outputbox %% for pLaTeX
       \vskip -\dimen@
       \@textbottom
       }%
   \fi
   \global \maxdepth \@maxdepth
}

%% the definition \fnunderfloat is unnecessary, as stfloats.sty
%% has already defined it. others should be re-declared here
\def\fnbelowfloat{\global\let\@makecol\pxstfl@fnbelowfl@makecol}
\def\fnabovefloat{\global\let\@makecol\pxstfl@fnabovefl@makecol}

%% all done

\endinput
