% mparhackleft-209.sty
% forces all marginpars onto the right column.
%
% see also marginHELP
%
% Stefan Ulrich <ulrich@cis.uni-muenchen.de> with
% Tom Sgouros <tomfool@top.gso.uri.edu> and Hilmar Schlegel
% <hshlgaii@mailszrz.zrz.tu-berlin.de> (for the 209 version).
%
% Eventually there will be a unified version compatible with
% both 209 and 2e (as soon as I get to it ;-)
%
%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
%% as published by the Free Software Foundation; either version 2
%% of the License, or (at your option) any later version.
%% 
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
%%

% Just in case I'm using AmS-LaTeX.
\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11

\def\@secondoftwo#1#2{#2}

\newcounter{mp@cnt}

\newcommand\mp@setref[3]{%
  \ifx#1\relax
    0 % just a dummy
  \else
   \expandafter#2#1%
  \fi
}
\newcommand\mp@pageref[1]{%
    \expandafter\mp@setref\csname r@#1\endcsname
    \@secondoftwo{#1}%
}

%%% from the 209 definition of \@addmarginpar

\def\@addmarginpar{%
%%%    \stepcounter{mp@cnt}%
%%%    \label{@mp@lab:\themp@cnt}%
    \@next\@marbox\@currlist{\@cons\@freelist\@marbox
    \@cons\@freelist\@currbox}\@latexbug\@tempcnta\@ne
%%%%%%%%%%%%%%%%%%    \@tempcnta\m@ne %%%%%%%%%%%%% removed this to make it right instead of left
%%%    \if@twocolumn
%%%        \if@firstcolumn \@tempcnta\m@ne \fi
%%%    \else
%%%      \if@mparswitch
%%%        \@ifundefined{r@@mp@lab:\themp@cnt}%
%%%          {\ifodd\c@page \else\@tempcnta\m@ne \fi}%
%%%          {\ifodd\mp@pageref{@mp@lab:\themp@cnt}%
%%%            \else\@tempcnta\m@ne \fi}%
%%%      \fi
    \if@reversemargin \@tempcnta -\@tempcnta \fi
%%%    \fi
    \ifnum\@tempcnta <\z@  \global\setbox\@marbox\box\@currbox \fi
    \@tempdima\@mparbottom
    \advance\@tempdima -\@pageht
    \advance\@tempdima\ht\@marbox
    \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\@marbox
    \global\advance\@mparbottom\marginparpush
    \advance\@tempdima -\ht\@marbox
    \global\setbox \@marbox
                   \vbox {\vskip \@tempdima
                          \box \@marbox}%
    \global \ht\@marbox \z@
    \global \dp\@marbox \z@
    \kern -\@pagedp
    \nointerlineskip
    \hb@xt@\columnwidth
      {\ifnum \@tempcnta >\z@
          \hskip\columnwidth \hskip\marginparsep
       \else
          \hskip -\marginparsep \hskip -\marginparwidth
       \fi
       \box\@marbox \hss}%
    \nointerlineskip
    \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}%
}


\catcode`\@=\TheAtCode\relax

