%\filename{insertmacros.tex}
%\edited{last by stolfi on Thu Dec 15 00:28:28 1988}

% Macros for top/bottom/mid/floating insertions (figures, footnotes, etc.)

\catcode`@=11 \endlinechar=-1

  \message{insertions ...}
  
  % Non-floating bottom insertions

    \newglue\botinsertsep % extra glue between footnotes

    \long\def\botinsert#1{\insert\botins
      {\floatingpenalty=\@MM\vbreak\forbidden
         \vbox{#1}\vbreak\forbidden\vskip\botinsertsep}}

    \newinsert\botins

    \count\botins=1000 % footnote magnification factor (1 to 1)
    \dimen\botins=\maxdimen % no limits for now

  %  Insertions at top/mid/full page (floating)

    \newdimen\topinsertsep % extra glue between topinserts

    \long\def\topinsert#1{
      {\insert\topins{\floatingpenalty=\@MM\vbreak\forbidden\vbox{#1}
         \vbreak\forbidden\vskip\topinsertsep}}
    }

    \long\def\pageinsert#1{
      {\insert\topins{\flo@tit
          \vbox to\textheight{#1\kern-\prevdepth}}}
    }

    \long\def\midinsert#1{\par{\setbox0\vbox{#1}
      \dimen@=\ht0 \advance\dimen@\dp0
      \advance\dimen@\abovedisplaysep \advance\dimen@\belowdisplaysep
      \advance\dimen@\pagetotal\advance\dimen@-\pageshrink
        \ifdim\dimen@>\pagegoal
           \insert\topins{\flo@tit\box\z@\vbreak\forbidden
             \vskip\belowdisplaysep}
         \else
           \unvskip
           \penalty\predisplaypenalty
           \vskip\abovedisplaysep
           \box\z@
           \penalty\postdisplaypenalty
           \vskip\belowdisplaysep \fi}}

    \newinsert\topins

    \count\topins=1000 % magnification factor (1 to 1)
    \dimen\topins=\maxdimen % no limit per page

    \def\flo@tit{\penalty100\splittopsep=\z@glue
      \splitmaxdepth=\maxdimen\floatingpenalty=\z@}

  %  Side insertions

    \newdimen\sideinsertsep
    
    \long\def\sideinsert#1{
      { \insert\sideins{
          \floatingpenalty=1000
          \vbreak\forbidden
          \vskip 0pt plus 500pt
          \vbox{#1}
          \vbreak\forbidden
          \vskip 0pt plus 500pt
          \vbreak\forbidden
          \vskip\sideinsertsep
        }
      }
    }

    \newinsert\sideins

    \count\sideins=0 % magnification factor (0 to 1)
    \dimen\sideins=\maxdimen % no limit per page

\catcode`@=12 \endlinechar=`\^^M

% END


