%% marginal.sty
%% Copyright 1997 Sigitas Tolu\v sis
%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
%% e-mail sigitas@vtex.lt
%% http://www.vtex.lt/tex/download/macros/
%%
% This program can redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or (at your option) any later version.
%
% PURPOSE:   Enlarge free and show lost marginal inserts
%
% SHORT DESCRIPTION:
%
% \showlostmarginals
% ------------------
%   Outputs lost marginal notes at the left of page
%
% \enlargefreelist 
% ----------------
%   Adds more(34) free inserts to freelist
%
% \onesidemarginals 
% -----------------
%   Outputs marginal notes only on one side. It saves one half 
%   of the available free inserts.
%
\def\get@CVSdate#1Id: #2,v #3 #4 #5 #6 #7${#4}%$
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{marginal}[\get@CVSdate$Id: marginal.sty,v 1.1 2002/06/11 15:09:37 sigitas Exp $]
%
\newif\if@mparlost      \@mparlostfalse
%
\newbox\@mparlostbox
\setbox\@mparlostbox\vbox{}
%
\gdef\@fltovfpar{\global\@mparlosttrue%
  \@latex@warning{Too many unprocessed (marginal)floats}\relax}
\gdef\@fltovfmess{%
  \@latex@error{Too many unprocessed floats}\@ehb}
%
\def\marginpar{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{}{}\@next\@marbox\@freelist{\global
      \count\@marbox\m@ne}{\@floatpenalty\z@ \@fltovfmess
         \def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}\fi
     \@ifnextchar [\@xmpar\@ympar}
%
\long\def \@savemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@marginparreset
        #2%
        \global\@minipagefalse
        \outer@nobreak
        }%
    \color@endbox%
    \if@mparlost\global\setbox\@mparlostbox\vbox{\unvbox\@mparlostbox\copy#1}%
    \global\@mparlostfalse\fi
}
%
%   \showlostmarginals - outputs lost marginal notes at the left of the page
%
\def\showlostmarginals{%
  \global\let\old@textbottom\@textbottom
  \gdef\@textbottom{\vtop to\z@{\hbox to\z@{\kern-\wd\@mparlostbox\vbox 
  to\z@{\kern-\ht\@mparlostbox\box\@mparlostbox\vfill}}}\old@textbottom}%
  \global\let\@fltovfmess\@fltovfpar}
%
%   \enlargefreelist - Adds more(34) free inserts to freelist
%
\def\enlargefreelist{%
\newinsert\bx@S
\newinsert\bx@T
\newinsert\bx@U
\newinsert\bx@V
\newinsert\bx@W
\newinsert\bx@X
\newinsert\bx@Y
\newinsert\bx@Z
\newinsert\bx@a
\newinsert\bx@b
\newinsert\bx@c
\newinsert\bx@d
\newinsert\bx@e
\newinsert\bx@f
\newinsert\bx@g
\newinsert\bx@h
\newinsert\bx@i
\newinsert\bx@j
\newinsert\bx@k
\newinsert\bx@l
\newinsert\bx@m
\newinsert\bx@n
\newinsert\bx@o
\newinsert\bx@p
\newinsert\bx@q
\newinsert\bx@r
\newinsert\bx@s
\newinsert\bx@t
\newinsert\bx@u
\newinsert\bx@v
\newinsert\bx@w
\newinsert\bx@x
\newinsert\bx@y
\newinsert\bx@z
\gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E
                \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J
                \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N
                \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R
                \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V
                \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z
                \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e
                \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j
                \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n
                \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r
                \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v
                \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z}%
}
%
%   \onesidemarginals - outputs marginals only on one side
%
\def\onesidemarginals{%
\newbox\@marbox
\gdef\@addmarginpar{\@cons\@freelist\@currbox
    \@tempdima\@mparbottom
    \advance\@tempdima -\@pageht
    \advance\@tempdima\ht\@currbox
    \ifdim\@tempdima >\z@
      \@latex@warning@no@line {Marginpar on page \thepage\space moved}%
    \else
      \@tempdima\z@
    \fi
    \global\@mparbottom\@pageht
    \global\advance\@mparbottom\@tempdima
    \global\advance\@mparbottom\dp\@currbox
    \global\advance\@mparbottom\marginparpush
    \advance\@tempdima -\ht\@currbox
    \global\setbox \@currbox
                   \vbox {\vskip \@tempdima
                          \box \@currbox}%
    \global \ht\@currbox \z@
    \global \dp\@currbox \z@
    \kern -\@pagedp
    \nointerlineskip
    \hb@xt@\columnwidth
      {\hskip\columnwidth \hskip\marginparsep \box\@currbox \hss}%
    \nointerlineskip
    \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}}%
%
\gdef\marginpar{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\ifinner\@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{\global
      \count\@currbox\m@ne}{\@floatpenalty\z@ \@fltovfmess
         \def\@currbox{\@tempboxa}}\fi
     \@ifnextchar [\@xmpar\@ympar}%
%
\long\gdef\@xmpar[##1]##2{\@savemarbox\@currbox{##2}\@xympar}%
\long\gdef\@ympar##1{\@savemarbox\@currbox{##1}\@xympar}%
\def \@xympar{%
%  \ifnum\@floatpenalty <\z@\@cons\@currlist\@marbox\fi
  \setbox\@tempboxa
    \color@vbox
      \vbox \bgroup
  \end@float
  \global \@ignorefalse \@esphack}%
}
\endinput
