%%
%% This is file `mempatch.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% mempatch.dtx  (with options: `patch')
%% 
%%   Author: Peter Wilson (Herries Press) herries dot press at earthlink dot net
%%   Copyright 2001 --- 2005 Peter R. Wilson
%% 
%%   This work may be distributed and/or modified under the
%%   conditions of the LaTeX Project Public License, either
%%   version 1.3 of this license or (at your option) any
%%   later version.
%%   The latest version of the license is in
%%      http://www.latex-project.org/lppl.txt
%%   and version 1.3 or later is part of all distributions of
%%   LaTeX version 2003/06/01 or later.
%% 
%%   This work has the LPPL maintenance status "author-maintained".
%% 
%%   This work consists of the files listed in the README file.
%% 
\ProvidesFile{mempatch.sty}[2005/10/06 v4.1 Patches for memoir class v1.618]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Version 4.0 was released simultaneously with version 1.618 of memoir.
%%% By definition there were no patches.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Version 4.1 (2005/10/03 and later)

%%%% Use correct number of arguments for \memsecstarinfo (2 not 3).
\def\@ssect#1#2#3#4#5{%
  \M@gettitle{#5}%
  \memsecstarinfo{\m@msecn@mame}{#5}%
  \@mem@old@ssect{#1}{#2}{#3}{#4}{#5}}

\newsavebox{\m@mscap@capbox}
\newsavebox{\m@mscap@fbox}

\newdimen\sidecapsep
  \sidecapsep=\marginparsep
\newdimen\sidecapwidth
  \sidecapwidth=\marginparwidth

\newdimen\m@m@tempdima
\newdimen\m@mscapraise

\newdimen\sidecapraise
  \sidecapraise \z@

\newcommand*{\setsidecappos}[1]{%
  \def\m@mscappos{#1}\def\@tempb{t}%
  \ifx\@tempb\m@mscappos
  \else
    \def\@tempb{b}%
    \ifx\@tempb\m@mscappos
    \else
      \def\@tempb{c}%
      \ifx\@tempb\m@mscappos
      \else
        \@memerror{Argument to \string\setsidecappos\space not t, c, or b.
                   \MessageBreak Set to c}{\@ehc}%
        \def\m@mscappos{c}%
      \fi
    \fi
  \fi}
\setsidecappos{c}

\newcommand{\sidecapmargin}[1]{%
  \def\@tempa{#1}\def\@tempb{left}%
    \ifx\@tempb\@tempa
      \def\m@mscapmarg{0}%   left
    \else
      \def\@tempb{right}%
      \ifx\@tempb\@tempa
        \def\m@mscapmarg{1}%  right
      \else
        \def\@tempb{outer}%
        \ifx\@tempb\@tempa
          \def\m@mscapmarg{2}%  outer
        \else
          \def\@tempb{inner}%
          \ifx\@tempb\@tempa
            \def\m@mscapmarg{3}%  inner
          \else
            \@memerror{Unrecognized argument for \string\sidecapmargin}%
                      {\@ehc}%
            \def\m@mscapmarg{-1}% error
          \fi
        \fi
      \fi
    \fi}
\sidecapmargin{left}

\newif\ifscapmargleft

\def\sidecapfloatwidth{\linewidth}
\newdimen\m@mscapmainwidth

\newdimen\m@mscaplkern
\newcommand*{\setm@mscaplkern}{%
  \m@mscaplkern=\sidecapwidth
  \advance\m@mscaplkern \sidecapsep
  \advance\m@mscaplkern \m@mscapmainwidth}

\newcommand*{\sidecapstyle}{%
%%%  \captionnamefont{\bfseries}%
  \ifscapmargleft
    \captionstyle{\raggedleft}%
  \else
    \captionstyle{\raggedright}%
  \fi}

\newcommand*{\sidecaption}{%
  \@ifnextchar [{\@sidecaption}{\@sidecaption[]}}
\def\@sidecaption[#1]#2{%
  \@ifnextchar [{\@@sidecaption{#1}{#2}}{\@@sidecaption{#1}{#2}[]}}
\def\@@sidecaption#1#2[#3]{%
  \ifx\@empty#1\@empty
    \def\m@mscap@fortoc{#2}%
  \else
    \def\m@mscap@fortoc{#1}%
  \fi
  \def\m@mscap@forcap{#2}%
  \ifx\@empty#3\@empty
    \def\m@mscaplabel{}%
  \else
    \def\m@mscaplabel{\@bsphack\label{#3}\@esphack}%
  \fi
  \m@mscapstart@fbox}

\newcommand*{\m@mscapstart@fbox}{%
  \setlength{\m@mscapmainwidth}{\sidecapfloatwidth}%
  \setm@mscaplkern
  \begin{lrbox}{\m@mscap@fbox}%
    \begin{minipage}[c]{\m@mscapmainwidth}}
\newcommand*{\m@mscapend@fbox}{%
    \end{minipage}%
  \end{lrbox}}

\def\endsidecaption{%
  \m@mscapend@fbox
  \refstepcounter\@captype
  \m@mscaplabel
  \begin{lrbox}{\m@mscap@capbox}%
    \begin{minipage}[c]{\sidecapwidth}%
      \sidecapstyle
      \@caption\@captype[\m@mscap@fortoc]{\m@mscap@forcap}
    \end{minipage}%
  \end{lrbox}%
  \m@mscapopboxes}
\newcommand*{\m@mscapopboxes}{%
  \m@mcalcscapraise
  \usebox{\m@mscap@fbox}\m@mscapcheckside
  \ifscapmargleft%
    \rlap{\kern-\m@mscaplkern
          \raisebox{\m@mscapraise}{\usebox{\m@mscap@capbox}}}%
  \else%
    \rlap{\kern\sidecapsep
          \raisebox{\m@mscapraise}{\usebox{\m@mscap@capbox}}}%
  \fi
  \gdef\m@mscapthisside{}}

\newcommand*{\m@mcalcscapraise}{%
  \def\@tempb{t}%
  \ifx\m@mscappos\@tempb
    \settoheight{\m@m@tempdima}{\strut\usebox{\m@mscap@capbox}}%
    \settoheight{\m@mscapraise}{\usebox{\m@mscap@fbox}}%
    \advance\m@mscapraise -\m@m@tempdima
    \advance\m@mscapraise  0.5ex
  \else
    \def\@tempb{b}%
    \ifx\m@mscappos\@tempb
      \settodepth{\m@m@tempdima}{\usebox{\m@mscap@fbox}}%
      \settodepth{\m@mscapraise}{\strut\usebox{\m@mscap@capbox}}%
      \advance\m@mscapraise -\m@m@tempdima
    \else
      \m@mscapraise=\z@
      \advance\m@mscapraise 0.25ex
    \fi
  \fi
  \advance\m@mscapraise  \sidecapraise}

\newcommand*{\m@mscapcheckside}{%
  \if@twocolumn
    \ifdim\hsize=\textwidth%  float*
      \m@mscapcheckregside
    \else
      \if@firstcolumn
        \scapmarglefttrue
      \else
        \scapmargleftfalse
      \fi
    \fi
  \else
    \m@mscapcheckregside
  \fi
  \m@mscapthisside}
\newcommand*{\m@mscapcheckregside}{%
    \if@twoside
      \checkoddpage
      \ifnum\m@mscapmarg<\@ne%      % left
        \scapmarglefttrue
      \else
        \ifnum\m@mscapmarg=\@ne%    % right
          \scapmargleftfalse
        \else
          \ifnum\m@mscapmarg=\tw@%  % outer
            \scapmargleftrue
            \ifoddpage
              \scapmargleftfalse
            \fi
          \else%                  % inner
            \scapmargleftfalse
            \ifoddpage
              \scapmarglefttrue
            \fi
          \fi
        \fi
      \fi
    \else%     oneside
      \scapmarglefttrue
      \ifnum\m@mscapmarg>\@ne
        \ifnum\m@mscapmarg<\thr@@
          \scapmargleftfalse
        \fi
      \fi
    \fi}

\newcommand*{\overridescapmargin}[1]{%
  \def\@tempb{#1}\def\@tempa{left}%
  \ifx\@tempa\@tempb
    \def\m@mscapthisside{\scapmarglefttrue}%
  \else
    \def\@tempa{right}%
    \ifx\@tempa\@tempb
      \def\m@mscapthisside{\scapmargleftfalse}%
    \else
      \@memerror{Argument to \string\overridescapmargin\space neither
                 left nor right}{\@ehc}%
      \def\m@mscapthisside{}%
    \fi
  \fi}
\newcommand*{\m@mscapthisside}{}

\newcommand*{\sidecontcaption}{%
  \@sidecontcaption}
\def\@sidecontcaption#1{%
  \@ifnextchar [{\@@sidecontcaption{#1}}{\@@sidecontcaption{#1}[]}}
\def\@@sidecontcaption#1[#2]{%
  \def\m@mscap@forcap{#1}%
  \ifx\@empty#2\@empty
    \def\m@mscaplabel{}%
  \else
    \def\m@mscaplabel{\@bsphack\label{#2}\@esphack}%
  \fi
  \m@mscapstart@fbox}

\def\endsidecontcaption{%
  \m@mscapend@fbox
  \addtocounter{\@captype}{\m@ne}\refstepcounter\@captype
  \m@mscaplabel
  \begin{lrbox}{\m@mscap@capbox}%
    \begin{minipage}[c]{\sidecapwidth}%
      \sidecapstyle
      \@contcaption\@captype{\m@mscap@forcap}
    \end{minipage}%
  \end{lrbox}%
  \m@mscapopboxes}

\newcommand*{\sidenamedlegend}{%
  \@ifnextchar [{\@sidenamedlegend}{\@sidenamedlegend[]}}
\def\@sidenamedlegend[#1]#2{%
  \@@sidenamedlegend{#1}{#2}}
\def\@@sidenamedlegend#1#2{%
  \ifx\@empty#1\@empty
    \def\m@mscap@fortoc{#2}%
  \else
    \def\m@mscap@fortoc{#1}%
  \fi
  \def\m@mscap@forcap{#2}%
  \def\m@mscaplabel{}%
  \m@mscapstart@fbox}

\def\endsidenamedlegend{%
  \m@mscapend@fbox
  \begin{lrbox}{\m@mscap@capbox}%
    \begin{minipage}[c]{\sidecapwidth}%
      \sidecapstyle
      \@legend\@captype[\m@mscap@fortoc]{\m@mscap@forcap}
    \end{minipage}%
  \end{lrbox}%
  \m@mscapopboxes}

\newcommand*{\sidelegend}{%
  \@@sidelegend}
\def\@@sidelegend#1{%
  \def\m@mscap@forcap{#1}%
  \m@mscapstart@fbox}

\def\endsidelegend{%
  \m@mscapend@fbox
  \begin{lrbox}{\m@mscap@capbox}%
    \begin{minipage}[c]{\sidecapwidth}%
      \sidecapstyle
      \legend{\m@mscap@forcap}
    \end{minipage}%
  \end{lrbox}%
  \m@mscapopboxes}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
%%
%% End of file `mempatch.sty'.
