% BACKGRound around block of text (e.g. several paragraphs), LaTeX style
% Vit Zyka, 1999, v1.0
\def\topins{252}
\input{backgr.tex}
{\advance\textwidth by0pt\xdef\bgwd{\the\textwidth}}
%\def\bght{\the\textheight}
\makeatletter
\def\@texttop{\backgroutput}
%\removeprevins{253}
\def\countprevinsertcorr#1{{%
  \dimen0=0pt                                           % vsize of prev inserts
  \pgstretchins=0pt \pgfilstretchins=0pt                % glue in prev inserts
  \pgfillstretchins=0pt \pgfilllstretchins=0pt \pgshrinkins=0pt
  \loop\ifnum\insc@unt<255
    \dimen2=\pgshrink \dimen3=\pgstretch \dimen4=\pgfilstretch
    \dimen5=\pgfillstretch \dimen6=\pgfilllstretch
    \countglue{\insc@unt}{\tmps}
    \ifx\@toplist\empty\else\advance\tmps by\floatsep\fi%
    \getpgregisters{\tmps}%
    \@testfalse \@tempcnta=2 \@xbitor\insc@unt
    \if@test
      \advance\dimen0 by\ht\insc@unt
      \advance\dimen0 by\dp\insc@unt
      \ifx\@toplist\empty\else\advance\dimen0 by\floatsep\fi%
      \setpgprevins
    \fi%
    \advance\insc@unt by 1
  \repeat%
  \ifx\@toplist\empty\else%
    \advance\dimen0 by-\floatsep \advance\dimen0 by\textfloatsep\fi%
%  \bgmessage{PrevIns:\the\dimen0}%
  \global#1=\dimen0 }}

% Marks with optional parameter for simpler correction specification:
%   \backgr[dimen] \endBackgr[dimen]
\def\Backgr{\@ifnextchar [{\backgrB}{\backgr}}
\def\endBackgr{\@ifnextchar [{\backgrE}{\endbackgr}}
\def\backgrB[#1]{\backgrcorrection=#1\backgr}
\def\backgrE[#1]{\backgrcorrection=#1\endbackgr}
\makeatother
