%%
%% 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/02/01 v3.5 Patches for memoir class v1.61]

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Version 2.1 (2004/02/19), and 2.2 (2004/03/01) patches were folded
%% into version 1.61 of memoir.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Version 2.3 (2004/04/26 and later)

%%%% remove extraneous spaces from indexing code
\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{}{%
  \def\@@wrindexhyp#1||\\{%
    \ifshowindexmark\@showidx{#1}\fi
    \protected@write\@auxout{}%
      {\string\@@wrindexm@m{\@idxfile}{#1}{\thepage}}%
    \endgroup
    \@esphack}
  \def\@@wrspindexhyp#1||\\{%
    \ifshowindexmark\@showidx{#1}\fi
    \protected@write\@auxout{}%
      {\string\@@wrindexm@m{\@idxfile}{#1}{\@nameuse{the\@sptheidx}}}%
    \endgroup
    \@esphack}%
}}

%%%% fix misalignment of (sub)paragraph headings in the ToC
\cftsetindents{paragraph}{10.0em}{5.0em}
\cftsetindents{subparagraph}{12.0em}{6.0em}

%%%% fix color handling in \verbfootnote
\long\def\@verbfootnotetext{%
  \insert\footins\bgroup
    \footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
    \edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}%
%%%%    \color@begingroup
    \@makefntext{\rule{\z@}{\footnotesep}\ignorespaces}%
    \futurelet\next\fo@t}
\def\f@t#1{\color@begingroup
  #1\@foot
  \color@endgroup}
\def\@foot{\strut\egroup
%%%%           \color@endgroup
}

%%%% fix bookmark for \appendixpage
\renewcommand{\addappheadtotoc}{\phantomsection
  \addcontentsline{toc}{chapter}{\appendixtocname}}

%%%% fix memoir/listings spacing problem (from Cartsten Heinz)
\renewcommand*{\extrafeetins}{% <-- Missing %
   \setbox\@outputbox \vbox{%
     \unvbox\@outputbox
     \ifvoid\footinsv@r\else\@footstartv@r\@footgroupv@r\fi
     \extrafeetinshook}}

\newcommand{\bvendofpage}[1]{%
  \def\boxverb@botpage{#1}}
\bvendofpage{\hrule\kern-.4pt}
\def\boxverb@split{\ifnum\outputpenalty=\boxverbflag
  \ifdim\dp\@cclv=\z@
%%%%    \setbox\@cclv\vbox{\unvbox\@cclv\hrule\kern-.4pt}%
    \setbox\@cclv\vbox{\unvbox\@cclv\boxverb@botpage}%
    \null \kern-.7\topskip \b@vtop \boxverb@toprule
  \fi
\fi}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Version 3.0 (2004/11/23 and later)

%%% Dan Luecking noted that the second argument should be enclosed in
%%% braces so that ] can be used as part of the optional
\long\def\@caption#1[#2]#3{%
  \M@gettitle{#2}\@memold@caption{#1}[{#2}]{#3}}

%%% Lars Madsen indicated the following fix for \absleftindent not working as advertised
\newdimen\abs@leftindent
  \abs@leftindent=\leftmargin
\renewcommand*{\setup@bstract}{%
  \if@twocolumn
    \if@bsonecol
      \abs@leftindent=\absleftindent
    \else
      \abs@leftindent=\z@
      \renewcommand*{\abstractnamefont}{\normalfont\Large\bfseries}%
      \renewcommand*{\abstracttextfont}{\normalfont}%
      \renewcommand{\absnamepos}{flushleft}%
      \setlength{\abstitleskip}{-2ex}%
    \fi
  \else
    \abs@leftindent=\absleftindent
  \fi
  \setlength{\absrightindent}{\abs@leftindent}%
}
\renewenvironment{@bstr@ctlist}{%
  \list{}{%
    %%\topsep        \z@
    \partopsep     \z@
    \listparindent \absparindent
    \itemindent    \listparindent
    \leftmargin    \abs@leftindent
    \rightmargin   \absrightindent
    \parsep        \absparsep}%
  \item\relax}%
{\endlist}

%%% Don't deprecate \em
\DeclareRobustCommand{\em}{\@m@m@m}

%%% Adjust the braces for the second and third arguments (courtesy of Lars Madsen)
\renewcommand*{\@memoldfontwarn}[3]{%
  \@memwarn{The \protect#1\space font command is deprecated.
    \MessageBreak Use \protect#2{...} or {\protect#3... } instead}}

%%% \newleadpage[<page-style>]{<\command>}{<title>} creates new macros
%%% called <\command> and <\command*> that when called typesets a page
%%% like an Appendixpage, with a title <title> using page style <page-style>
%%% (default empty). The plain version adds an entry to the ToC but the
%%% starred <\command*> does not. \renewleadpage changes the definition.
%%% The ToC entry style is set by \leadpagetoclevel (default chapter). To
%%% have a part type entry: \renewcommand*{\leadpagetoclevel}{part}.
%%% (Suggested by Lars Madsen on 2004/11/28)
%%%
\newcommand*{\leadpagetoclevel}{chapter}
\newcommand*{\newleadpage}[3][empty]{%
  \newcommand*{#2}{\@ifstar{\dlfm@msapppage{#1}{#3}}%
                           {\dlfm@mapppage{#1}{#3}}}}
\newcommand*{\renewleadpage}[3][empty]{%
  \renewcommand*{#2}{\@ifstar{\dlfm@msapppage{#1}{#3}}%
                           {\dlfm@mapppage{#1}{#3}}}}

\newcommand*{\dlfm@msapppage}[2]{%
  \@setuppart
  \markboth{}{}%
  {\centering
   \interlinepenalty \@M
   \normalfont
   \printparttitle{#2}\par
   \thispagestyle{#1}}%
  \@endpart}
\newcommand*{\dlfm@mapppage}[2]{%
  \@setuppart
  \phantomsection
  \addcontentsline{toc}{\leadpagetoclevel}{#2}
  \markboth{}{}%
  {\centering
   \interlinepenalty \@M
   \normalfont
   \printparttitle{#2}\par
   \thispagestyle{#1}}%
  \@endpart}

%%%%%%%%%%%%%%%%%%%%%% Version 3.1 additions %%%%%%%%%%%%%%%%%%%%%%%%%

%%% Morten Hogholm (2004/12/17) found that \boxmaxdepth had to be set in \extrafeetins.
\renewcommand*{\extrafeetins}{%
  \setbox\@outputbox \vbox{%
    \boxmaxdepth \@maxdepth
    \unvbox\@outputbox
    \ifvoid\footinsv@r\else\@footstartv@r\@footgroupv@r\fi
    \extrafeetinshook}}

%%% Morten Hogholm (2004/12/17) noted a missing % in \@twocolfootnotetext
\renewcommand*{\@twocolfootnotetext}[1]{\insert\footinsv@r{%
  \foottextfont
  \@preamfntext
  \protected@edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}%
  \color@begingroup
    \@twocolfootfmt{#1}%
  \color@endgroup}%
  \m@mmf@prepare}

%%%%%%%%%%%%%%%%%%%%%% Version 3.2 additions %%%%%%%%%%%%%%%%%%%%%%%%%

%%% Fix these so that \maketitle does not throw an extra blank page when used
%%% within adjustwidth inside titlingpage environments.
\renewcommand{\maketitle}{\par
  \begingroup
    \@bsmarkseries
    \def\@makefnmark{\@textsuperscript{%
      \normalfont\@bsthanksheadpre \tamark \@bsthanksheadpost}}%
    \long\def\@makefntext##1{\makethanksmark ##1}%
    \if@twocolumn
      \ifnum\col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \ifdim\pagetotal>\z@
        \newpage
      \fi
      \global\@topnum\z@
      \@maketitle
    \fi
    \thispagestyle{title}\@thanks
  \endgroup
  \@bscontmark}
\renewcommand{\@maketitle}{%
  \let\footnote\m@m@titlefootkill
  \ifdim\pagetotal>\z@
    \newpage
  \fi
  \null
  \vskip 2em%
    \vspace*{\droptitle}
  \maketitlehooka
  {\@bspretitle \@title \@bsposttitle}
  \maketitlehookb
  {\@bspreauthor \@author \@bspostauthor}
  \maketitlehookc
  {\@bspredate \@date \@bspostdate}
  \maketitlehookd
  \par
  \vskip 1.5em}

%%% \sidebarmargin{<side>} sets the side where sidebars will be printed.
%%% Valid arguments are: left, right, outer, or inner
%%% Only effects onecolumn documents with \sidebaronesidefalse
%%% (\sidebarmargin{right} is equivalent to \sidebaronesidetrue)
\newcommand*{\sidebarmargin}[1]{%
  \def\@tempa{#1}\def\@tempb{left}%
  \ifx\@tempa\@tempb
    \gdef\m@msidebar@margin{0}%
  \else
    \def\@tempb{right}%
    \ifx\@tempa\@tempb
      \gdef\m@msidebar@margin{1}%
    \else
      \def\@tempb{outer}%
      \ifx\@tempa\@tempb
        \gdef\m@msidebar@margin{2}%
      \else
        \def\@tempb{inner}%
        \ifx\@tempa\@tempb
          \gdef\m@msidebar@margin{3}%
        \else
          \@memwarn{Bad \string\sidebarmargin\space argument}%
          \gdef\m@msidebar@margin{1}%
        \fi
      \fi
    \fi
  \fi}
%%% default outer
\gdef\m@msidebar@margin{2}

\renewcommand{\sidecontents}{{%
  \if@twocolumn%       put outside nearest column
    \if@firstcolumn%     move to left
      \setlength{\@tempdimc}{\sidebarwidth}%
      \advance\@tempdimc\sidebarhsep
      \moveleft\@tempdimc
    \else%               move to right
      \setlength{\@tempdimc}{\columnwidth}%
      \advance\@tempdimc\sidebarhsep
      \moveright\@tempdimc
    \fi
  \else%
    \ifsidebaroneside%   put in right margin
      \setlength{\@tempdimc}{\hsize}%
      \advance\@tempdimc\sidebarhsep
      \moveright\@tempdimc
    \else
      \ifcase\m@msidebar@margin%  0 to left
        \setlength{\@tempdimc}{\sidebarwidth}%
        \advance\@tempdimc\sidebarhsep
        \moveleft\@tempdimc
      \or%                      1 to right
        \setlength{\@tempdimc}{\hsize}%
        \advance\@tempdimc\sidebarhsep
        \moveright\@tempdimc
      \or%                      2 to outer
        \ifodd\c@page%            to right
          \setlength{\@tempdimc}{\hsize}%
          \advance\@tempdimc\sidebarhsep
          \moveright\@tempdimc
        \else%                    to left
          \setlength{\@tempdimc}{\sidebarwidth}%
          \advance\@tempdimc\sidebarhsep
          \moveleft\@tempdimc
        \fi
      \or%                      3 to inner
        \ifodd\c@page%            to left
          \setlength{\@tempdimc}{\sidebarwidth}%
          \advance\@tempdimc\sidebarhsep
          \moveleft\@tempdimc
        \else%                    to right
          \setlength{\@tempdimc}{\hsize}%
          \advance\@tempdimc\sidebarhsep
          \moveright\@tempdimc
        \fi
      \fi
    \fi
  \fi
  \vtop to0pt{%
    \vskip\onelineskip
    \unvbox\sideins \vss}%
}}

%%%%%%%%%%%%%%%%%%%%%% Version 3.3 additions %%%%%%%%%%%%%%%%%%%%%%%%%

%%%% fix vertical spacing in the verse environment
\renewenvironment{verse}[1][\linewidth]{%
  \refstepcounter{verse}%
  \setcounter{poemline}{0}\refstepcounter{poemline}%
  \setcounter{vslineno}{1}%
  \let\\=\@vscentercr
  \list{}{\itemsep      \z@
          \itemindent   -\vindent
          \listparindent\itemindent
          \parsep       \stanzaskip
          \ifdim #1<\linewidth %% short line
            \rightmargin        \z@
            \leftmargin         \linewidth
            \advance\leftmargin -#1\relax
            \advance\leftmargin -0.5\leftmargin
            \advance\leftmargin \vindent
          \else
            \ifdim #1>\linewidth %% long line
              \rightmargin \z@
              \leftmargin  \vindent
             \else               %% default
               \rightmargin        \leftmargin
               \advance\leftmargin \vindent
             \fi
          \fi}
  \item[]}{\endlist}

%%% David Carlisle noted on CTT (2005/01/17, Re: array-package and *)
%%% that this macro had a bug in the original array package.
\long\@namedef{NC@rewrite@*}#1#2{%
  \count@#1\relax
  \loop
  \ifnum\count@>\z@
    \advance\count@\m@ne
    \@temptokena\expandafter{\the\@temptokena#2}%
  \repeat
  \NC@find}

%%%%%%%%%%%%%%%%%%%%%% Version 3.4 additions %%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\@csoutstar}[2]{%
  \@ifbothcntrs{#1}{#2}{\@removefromreset{#1}{#2}}}

%%%%%%%%%%%%%%%%%%%%%% Version 3.5 additions %%%%%%%%%%%%%%%%%%%%%%%%%

%%% You can redefine \eminnershape to, say, \scshape, for a different
%%% emphasis font.
%%% (Suggested by Lars Madsen to match fixltx2e package)
\DeclareRobustCommand{\em}{%
  \@nomath\em
  \ifdim\fontdimen\@ne\font > \z@
    \eminnershape
  \else
    \itshape
  \fi}
\providecommand{\eminnershape}{\upshape}
\DeclareTextFontCommand{\emph}{\em}

%%% Fix by Lars Madsen to ensure article chapter title is on a newline
\renewcommand{\chapter}{%
  \ifartopt\par\else  %  <-- added \par
    \clearforchapter
    \thispagestyle{chapter}
    \global\@topnum\z@
  \fi
  \@afterindentfalse
  \@ifstar{\@m@mschapter}{\@m@mchapter}}

%%% Fix by Morten Hogholm to make \chapter's optional arguments work as described
\renewcommand{\@m@mchapter}[1][\@empty]{%
 \def\ch@pt@c{#1}% capture first optional arg
  \@ifnextchar[{\@chapter}{\@chapter[\@empty]}%
}
\def\@chapter[#1]#2{%
  \ifx\ch@pt@c\m@m@empty % no ToC entry, use same for ToC and head
    \def\f@rtoc{#2}%
    \def\f@rhdr{#2}%
  \else                  % ToC entry present
    \let\f@rtoc\ch@pt@c
    \ifx\m@m@empty#1\relax
      \let\f@rhdr\ch@pt@c
    \else
      \def\f@rhdr{#1}%
    \fi
  \fi
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \refstepcounter{chapter}%
    \fi
  \fi
  \chaptermark{\f@rhdr}%
  \ifartopt
    \@makechapterhead{#2}%
    \@afterheading
  \else
    \insertchapterspace
    \if@twocolumn
      \@topnewpage[\@makechapterhead{#2}]%
    \else
      \@makechapterhead{#2}%
    \fi
    \@afterheading
  \fi
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \addcontentsline{toc}{chapter}{%
        \protect\chapternumberline{\thechapter}\f@rtoc}%
    \else
      \addcontentsline{toc}{chapter}{\f@rtoc}%
    \fi
  \else
    \addcontentsline{toc}{chapter}{\f@rtoc}%
  \fi
  \ifheadnameref\M@gettitle{\f@rhdr}\else\M@gettitle{\f@rtoc}\fi
}

\renewcommand{\FrameRestore}{%
  \let\if@nobreak\iffalse
  \let\if@noskipsec\iffalse
  \let\-\@dischyph%  <-- missed the second `h' here
  \let\'\@acci\let\`\@accii\let\=\@acciii
  \linewidth\hsize
  \sloppy
\ifframeasnormal\else
  \let\par\@@par
  \parindent\z@ \parskip\z@skip
  \everypar{}%
  \@totalleftmargin\z@
  \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip
  \parfillskip\@flushglue \lineskip\normallineskip
  \baselineskip\normalbaselineskip
  \let\\\@normalcr
\fi}

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