%\usepackage[fleqn]{amsmath}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{eufrak}   % included in amsfonts ???
\usepackage{ntheorem}
\usepackage{graphicx}
%\usepackage{times}
%\usepackage{chicago}
\usepackage{fancyhdr}
\usepackage{array}

\usepackage{boxedminipage}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% miscellaneous macros
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\version{\relax}
\def\bookNAME{\relax}

% for pagestyles
\newif\ifnormal
\normaltrue

\def\sc#1{{\scshape#1}}
\renewcommand{\theenumi}{(\roman{enumi})}
\renewcommand{\labelenumi}{(\roman{enumi})}

\def\LIST{\showboxdepth=40\showboxbreadth=45\showlists}

\def\today{\number\day \space \ifcase\month\or
January\or February\or March\or April\or May\or
June\or July\or August\or September\or October\or
November\or December\fi  \space \number\year}

\def\norm#1{\left\Vert#1\right\Vert}
\def\newdef#1{{\itshape\bfseries #1}}

\def\cases@#1{\left\{\,\vcenter{\normalbaselines\m@th
    \ialign{$##$\hfil&\quad##\hfil\crcr#1\crcr}}\right.}

\def\Cases#1\endCases{\let\\=\cr\cases@{#1}}

\def\Matrix{\begin{matrix}}
\def\endMatrix{\end{matrix}}

\def\bullitem{\item[$\bullet$]}

%\def\framemath#1{\fboxsep=0pt\fbox{\vbox{#1}}}
%\def\framemath#1{\vskip2pt\fboxsep=0pt\fbox{\vbox{#1}}}
\def\framemath#1{\setbox0=\hbox{$\displaystyle#1$}\fbox{\box0}}

\let\frameword=\fbox

% Need to write Python script to collect first and last pages

\newlinechar=`\^^J
\def\first@page#1#2{\relax}  %written to .aux file by \@Chapter
\def\last@page#1#2{\relax} 
\def\endChapter{%
	\protected@write \@auxout {}{\string \last@page{\thisChap}{\thepage}}%
%	\protected@write \@auxout {}{^^J}%
}
\let\endAppendix=\endChapter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% General page dimensions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newdimen\marginindent
\newdimen\marginpoke
\marginindent=3pc
\marginpoke=\marginindent

%\newdimen\widehsize
%\newdimen\headwidth  % clashes with fancyhdr
%\newdimen\headframewidth


\abovedisplayskip=5pt plus1pt minus1pt
\belowdisplayskip=5pt plus1pt minus1pt

\newskip\proclaimskipamount
\newskip\ritemskipamount

\proclaimskipamount=6pt  plus1pt minus1pt %12pt  plus1pt minus1pt
\ritemskipamount=2pt %plus1pt minus1pt

\def\proclaimbreak{\par \ifdim\lastskip<\proclaimskipamount
		   \removelastskip \penalty-200\vskip\proclaimskipamount\fi}

\def\marginflush#1{\vbox{\moveleft\marginindent\hbox{#1}}}

%\rightskip=0ptplus1em minus1pt
\newskip\AboveChapterHead
\AboveChapterHead=1in

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Page styles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\fancyhf{}
%\usepackage{fancyhdr}
\def\sectionmark#1{%
  \markboth {{%
	\ifnum \c@secnumdepth >\z@
	  \thesection\quad
	\fi
	#1}}{}}%
	
\fancyhead{}
%\fancyhead[LO]{\S\ChapterNumber.\normalsize\scshape\leftmark}
%\fancyhead[LO]{\S\ChapterNumber.\normalsize\scshape\botmark}
\fancyhead[LO]{\ifnormal\S\ChapterNumber.\thesection\fi\normalsize\scshape\SectionName}
%\fancyhead[LO]{\llap{\S\ChapterNumber\qquad}.\leftmark}
\fancyhead[RO]{\thepage}
%\fancyhead[RE]{\small Chapter \ChapterNumber: \ChapterName}
\fancyhead[RE]{\normalsize\scshape \ChapterName}
\fancyhead[LE]{\thepage}
\fancyfoot{}
\addtolength{\headheight}{\baselineskip}


\fancypagestyle{normal}{%
	\normaltrue
	\fancyhf{} % clear all header and footer fields
	\fancyhead[LO]{%
		\ifnormal\S\ChapterNumber.\thesection\quad\fi
		\normalsize\scshape\SectionName
	}%
	\fancyhead[RO]{\thepage}
	\fancyhead[LE]{\thepage}
	\fancyhead[RE]{\scshape \normalsize\ChapterName}
	\fancyfoot{}
	\renewcommand{\headrulewidth}{0.5pt}
	\renewcommand{\footrulewidth}{0pt}%
}

\pagestyle{normal}

%\newcommand{\ps@startchap}{%
%\renewcommand{\@oddhead}{%
%	\hfil\thepage
%	}%
%\renewcommand{\@evenhead}{%
%	\thepage\hfil
%	}%
%\renewcommand{\@oddfoot}{
%	\hfil
%	\hbox{%
%		\vbox to0pt{\vss%
%			\small\itshape 
%			version: \version\\
%			printed: \today%
%	}\hfil
%		\vbox to0pt{\vss 
%			\small\itshape 
%			\llap{\bookNAME}\\%
%			\llap{\copyright David Pollard}}%
%		}%
%	}%
%}

\fancypagestyle{startchap}{%
	\fancyhf{} % clear all header and footer fields
	\fancyfoot[L]{%
		\vtop to0pt{%
			\small\itshape 
			version: \version\\
			printed: \today%
			\vss
		}}
	%\fancyfoot[C]{\thepage}
	\fancyfoot[R]{%
		\vtop to0pt{%
			\small\itshape 
			\bookNAME\\%
			\copyright David Pollard%
			\vss 
		}}%
	\renewcommand{\headrulewidth}{0pt}
	\renewcommand{\footrulewidth}{0.5pt}%
}

%\newcommand{\ps@references}{}
\fancypagestyle{references}{%
	\fancyhf{}
	\fancyhead[LO]{\scshape
	\ChapTitle/ \ChapterNumber\ references}
	%\fancyhead[LO]{\llap{\S\ChapterNumber\qquad}.\leftmark}
	\fancyhead[RO]{\thepage}%
	\fancyhead[RE]{\scshape \ChapterName}%
	\fancyhead[LE]{\thepage}%
}

\fancypagestyle{problems}{%
	\fancyhf{}
	\fancyhead[LO]{\scshape
	\ChapTitle/ \ChapterNumber\ problems}
	%\fancyhead[LO]{\llap{\S\ChapterNumber\qquad}.\leftmark}
	\fancyhead[RO]{\thepage}%
	\fancyhead[RE]{\scshape \ChapterName}%
	\fancyhead[LE]{\thepage}%
}

\fancypagestyle{notes}{%
	\fancyhf{}
	\fancyhead[LO]{\scshape\normalsize Chapter \ChapterNumber\ notes}
	%\fancyhead[LO]{\llap{\S\ChapterNumber\qquad}.\leftmark}
	\fancyhead[RO]{\thepage}%
	\fancyhead[RE]{\scshape \ChapterName}%
	\fancyhead[LE]{\thepage}%
}

\fancypagestyle{roman}{%
	\fancyhf{}
	\fancyhead[RO]{\roman{page}}
	\fancyhead[LE]{\roman{page}}
	\renewcommand{\headrulewidth}{0pt}
}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Table of Contents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\renewcommand\tableofcontents{%
	\gdef\ChapterName{\relax}%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
%    \pagestyle{roman}
    \thispagestyle{startchap}%
    %\pagestyle{plain}
    \noindent{\Large \textbf{Contents}}%\break

    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }

\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \Large  #1\hfil \hb@xt@\@pnumwidth{\hss\mdseries\normalsize #2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}


\newcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
%      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss\mdseries #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
  
  
\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand*\l@starsection{\@dottedtocline{1}{1.5em}{2.3em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\scshape\llap{Part }\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {%\centering
    \thispagestyle{empty}%
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname~\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
%     \vfil\newpage %  used to be:  \@endpart}
}

%\def\@endpart{\vfil\newpage
%              \if@twoside
%                \null
%                \thispagestyle{empty}%
%                \newpage
%              \fi
%              \if@tempswa
%                \twocolumn
%              \fi
%              }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Chapter and Appendix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\newcount\count@Chapter
%\newcount\count@Appendix
\newcounter{Chapter}
\newcounter{Appendix}
\newtoks\tok@Chap
%\count@Chapter= 0  
%\count@Appendix=`\A   %   Capital A
%\count@Appendix= 0   %   Capital A

\def\GiveChapNumber#1{%
\stepcounter{Chapter}%
%\expandafter\xdef\csname Chap#1\endcsname{\the\count@Chapter}%
\expandafter\xdef\csname Chap#1\endcsname{\arabic{Chapter}}%
%\advance\count@Chapter by1}
}

\gdef\GiveAppLetter#1{%
\stepcounter{Appendix}%
%\expandafter\xdef\csname App#1\endcsname{\char\the\count@Appendix}%
\expandafter\xdef\csname App#1\endcsname{\Alph{Appendix}}%
%\advance\count@Appendix by1}
}

\def\Chapter#1#2{%
	\global\pagestyle{normal}%
	\gdef\ChapTitle/{Chapter}%
	\gdef\ChapAbbrev/{Chap}%
	\@Chapter{#1}{#2}%
}

\def\Appendix#1#2{
	\pagestyle{normal}%
	\gdef\ChapTitle/{Appendix}%
	\gdef\ChapAbbrev/{App}%
	\@Chapter{#1}{#2}%
}

\def\@Chapter#1#2{
 %\protected@write \@auxout {}{\string \first@page{#1}{\thepage}}%
 %	\protected@write \@auxout {}{^^J}%
%%	\ifodd\thepage\relax\else\thispagestyle{plain}\newpage\fi
	\write \@auxout {\string \first@page{#1}{\thepage}}%
	\global\tok@Chap={#1}%
	\gdef\thisChap{#1}%
%  \global\FirstPagetrue
	\gdef\SectionNumber{\relax}%
	\gdef\ChapterNumber{\csname \ChapAbbrev/#1\endcsname}%
	\gdef\ChapterName{#2}%
	\addcontentsline{toc}{chapter}%
       {\protect\numberline{\ChapterNumber}#2}%
     \setcounter{section}{0}%
     \setcounter{equation}{0}%
	
	\thispagestyle{startchap}%
%  \setcounter{chapter}{\ChapterNumber}   % for Latex numbering of sections
%	\noindent{\Large \textbf{\ChapTitle/~\ChapterNumber}}\hfil\break
%	\noindent{\Large \textbf{\ChapTitle/~\ChapterNumber}\hfil}\break
	\noindent{\Large \textbf{\ChapTitle/~\ChapterNumber}\hfil}\par
  \smallskip
%\nointerlineskip
	\hrule 
	\medskip
	\noindent{\huge #2}%
	\bigskip
}




%\input dpHeading.sty


%\def\section[#1]#2{Section[#1]#2}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sections 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\SectionName{\relax}
%\def\Notes{\pagestyle{notes}\section*{Notes}}
\def\Notes{%
	\section*{Notes}%
%	\mark{{Notes for Chapter \ChapterNumber}}%
	\gdef\SectionName{Notes for \ChapTitle/ \ChapterNumber}
	\normalfalse
}

\@addtoreset{section}{Chapter}
%\def\Sref#1{\ref{Sect.#1}}
%\let\sref=\Sref

\def\sect@star{\relax}

\renewcommand{\@seccntformat}[1]{\llap{\sect@star\ChapterNumber.\csname the#1\endcsname\qquad}}

\newcommand\starsection{\@startsection {starsection}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

\let\c@starsection = \c@section
\let\p@starsection= \p@section
\let\thestarsection = \thesection
%\def\Section[#1]#2{\section{#2}\label{Sect.#1}}

%\def\SectionName{\relax}

%\def\Section[#1]#2{%
%	\gdef\SectionName{#2}%
%	\def\sect@star{\relax}%
%	\section{#2}%
%	\label{\the\tok@Chap::#1}%
%}
\def\Section[#1]#2{%
	\gdef\SectionName{#2}%
	\def\sect@star{\relax}%
	\section{#2}%
	\label{\the\tok@Chap::#1}%
	\check@for@SN@abbrev
}

\def\check@for@SN@abbrev{\@ifnextchar[{\resetSN}{\relax}}

\def\resetSN[#1]{\def\SectionName{#1}}


%\let\starSection=\Section
\def\starSection[#1]#2{%
	\gdef\SectionName{#2}%
	\def\sect@star{*}%
	\starsection{#2}%
	\label{\the\tok@Chap::#1}%
	\check@for@SN@abbrev
}


%\def\@seccntformat#1{\csname the#1\endcsname\quad}
\def\Sref{%
	\@ifnextchar[{\@Sref}%	
	{\@Sref[\the\tok@Chap]}%
}
\def\@Sref[#1]#2{\ref{#1::#2}}
\let\sref=\Sref

%\def\starSection[#1]#2{\section*{#2}\label{Sect.#1}}

\def\beginPreamble{\bgroup\itshape}
\def\endPreamble{\bigskip\egroup}

%\def\SectionDescribe#1{\par\hangindent\parindent\hangafter1\noindent
%\expandafter SECTION~{\ref{Sect.#1}}
\def\SectionDescribe#1{\par
\hangindent\parindent\hangafter1\noindent
{\scshape Section}~{\ref{\the\tok@Chap::#1}}}

\def\starSectionDescribe#1{\par
\hangindent\parindent\hangafter1\noindent
\expandafter {\scshape \llap{*}Section}{\ref{\the\tok@Chap::#1}}}

%\def\PreambleSref#1{\getcref{Sect.#1}\crefsection}
%
%\def\beginPreamble{%
%\bgroup\SDfont\baselineskip=11.5pt\let\sref=\PreambleSref}
%\def\endPreamble{\bigskip\egroup}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Theorems, Examples, ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\newtheoremstyle{DBP}%
%  {\item[\rlap{\vbox{\hbox{\hskip\labelsep 
%          \llap{$<$##2$>$\qquad}\theorem@headerfont##1\theorem@separator}\hbox{\strut}}}]}%
%  {\item[\rlap{\vbox{\hbox{\hskip\labelsep \theorem@headerfont
%          ##2\ ##1\ (##3)\theorem@separator}\hbox{\strut}}}]}
%
%\newtheoremstyle{DBP2}%
%  {\item[\llap{$<$##2$>$\qquad}\theorem@headerfont  ##1\theorem@separator]}%
%  {\item[\llap{$<$##2$>$\qquad}\theorem@headerfont  ##1\ (##3)\theorem@separator]}
%{\item[\llap{$<$##2$>$\qquad}\hskip\labelsep\theorem@headerfont  ##1\theorem@separator]}%
%{\item[\llap{$<$##2$>$\qquad}\hskip\labelsep\theorem@headerfont  ##1\ (##3)\theorem@separator]}

%\def\theorem@headerfont{\normalfont\bfseries}
\newtheoremstyle{DBPrem}%
  {\item[\theorem@headerfont  ##1\theorem@separator]}%
  {\item[\theorem@headerfont  ##1\ (##3)\theorem@separator]}

\def\shim#1{\hskip#1pt\relax}

%\newtheoremstyle{DBP4}%
%  {\item[\hbox to5.5pt{\hss$<$##2$>$\shim{20}}\theorem@headerfont  ##1\theorem@separator]}%
%  {\item[\hbox to6pt{\hss$<$##2$>$\shim{21}}\theorem@headerfont  ##1\ (##3)\theorem@separator]}

\newtheoremstyle{DBP4}%
  {\item[\hbox to5.5pt{\hss$<$##2$>$\shim{20}}\theorem@headerfont  ##1\theorem@separator]}%
  {\item[\hbox to6pt{\hss$<$##2$>$\shim{21}}\theorem@headerfont  ##1\ [##3]\theorem@separator]}




\theoremstyle{DBP4}
\theoremseparator{.}
\theoremheaderfont{\normalfont\bfseries}
%\theoremheaderfont{\sc} commented out 9 nov09
\theorembodyfont{\itshape}
\newtheorem{theorem}[equation]{Theorem}
%\newtheorem{theorem}[equation]{$|$Theorem}  % for testing

\newtheorem{definition}[equation]{Definition}
\newtheorem{lemma}[equation]{Lemma}
\newtheorem{corollary}[equation]{Corollary}
\newtheorem{assumption}[equation]{Assumption}

\theorembodyfont{\normalfont}

\newtheorem{example}[equation]{Example}

\theoremstyle{DBPrem}
\theoremindent2em
\theorembodyfont{\small}
\newtheorem{remark}{Remark}
\newtheorem{remarks}{Remarks}


\theoremindent0pt

%\theoremheaderfont{\sc}
\theoremheaderfont{\scshape}
\theorembodyfont{\upshape}
\theoremstyle{nonumberplain}
\theoremseparator{}
\theoremsymbol{\rule{1ex}{1ex}}
\newtheorem{proof}{Proof}


\def\Remark{\begin{remark}\rightskip=3em plus2em minus2pt}
\def\endRemark{\end{remark}}

\def\Remarks{\begin{remarks}\rightskip=3em plus2em minus2pt}
\def\endRemarks{\end{remarks}}

\def\Corollary{\begin{corollary}}
\def\endCorollary{\end{corollary}}

\def\Definition{\begin{definition}}
\def\endDefinition{\end{definition}}

\def\Theorem{\begin{theorem}}
\def\endTheorem{\end{theorem}}

\def\NamedTheorem{\begin{theorem}}
\def\endNamedTheorem{\end{theorem}}

\def\Lemma{\begin{lemma}}
\def\endLemma{\end{lemma}}

\def\Assumption{\begin{assumption}}
\def\endAssumption{\end{assumption}}

\def\Example{\begin{example}}
%\def\endExample{\end{example}}
\def\endExample{\noindent\vadjust{\llap{\qedsymbol\qquad}}\end{example}}



\def\Proof{\begin{proof}}
\def\endProof{\end{proof}}

\def\mnote#1{\marginpar{\par\tiny#1}}
\def\msymbol#1{\marginpar{\par\tiny#1}}


\def\qed@{\ifmmode{\square}\else{$\square$}\fi}
\let\qedsymbol=\qed@
\def\endProof{\noindent\vadjust{\llap{\qedsymbol\qquad}}\end{proof}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Equation (and theorem ... ) labels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\beq}{\begin{equation}}  % expects a label
\newcommand{\eeq}{\end{equation}}

\newcommand{\beqN}{\begin{equation*}}  %no label, same as $$ .... $$ except for alignment
\newcommand{\eeqN}{\end{equation*}}

%\newcommand{\bAlign}{\begin{align*}}
%\newcommand{\eAlign}{\end{align*}}


\newcommand{\bea}{\begin{eqnarray*}}
\newcommand{\eea}{\end{eqnarray*}}
\newcommand{\bean}{\begin{eqnarray}}
\newcommand{\eean}{\end{eqnarray}}
\newcommand{\bear}{\begin{array}}
\newcommand{\eear}{\end{array}}

%Note:  With \Showlabels the labels must be \Labels
%\def\bAlignL#1\eAlignL{\begin{align}#1\end{align}}  % Labels
\def\bAlign#1\eAlign{\begin{align*}#1\end{align*}}	% no labels

%\def\bxAlignat#1#2\exAlignat{%
%	\begin{xalignat}{#1}#2\end{xalignat}%
%}
\def\bAlignL#1\eAlignL{%
	\let\tagform@=\old@tagform@
	\begin{align}#1\end{align}%
	\let\tagform@=\new@tagform@
	\showmarginlabels    %does nothing if no Showlabels	
}% end bAlignL

\def\bxAlignat#1#2\exAlignat{%
	\let\tagform@=\old@tagform@
	\begin{xalignat}{#1}#2\end{xalignat}%
	\let\tagform@=\new@tagform@
	\showmarginlabels   %does nothing if no Showlabels		
}%

\def\NT{\notag\\}  

\def\leqn{\hbox{$<$}}
\def\reqn{\hbox{$>$}}
\def\cref#1{\normalsize%
	$<$\hbox{\normalfont\small\ref{#1}}\normalsize$>$}

\newdimen\label@push
\def\eqn@label{\relax}
\def\makeeqnlabel#1{\llap{%
	\normalfont\normalcolor\small\eqn@label
	\leqn\ignorespaces#1\unskip\@@italiccorr\reqn}}
  
\def\@eqnnum{\hbox to1sp{}\llap{\normalfont\normalcolor
    \hskip -\displaywidth\tagform@\theequation}}
\def\tagform@#1{\maketag@@@{\small\leqn\ignorespaces#1\unskip\@@italiccorr\reqn}}

\renewenvironment{equation}%
    {\@beginparpenalty\predisplaypenalty
     \@endparpenalty\postdisplaypenalty
     \refstepcounter{equation}%
     \trivlist \item[]\leavevmode
       \hb@xt@\linewidth\bgroup 
%       \llap{\@eqnnum}\hfil%
       \hfil\setbox0=\hbox\bgroup%
       $\m@th\displaystyle
     }%
     {$\egroup\copy0 % $
%        \showthe\linewidth
%        \showthe\displaywidth
		%\def\eqn@label{
		\label@push=\linewidth 
		\advance \label@push by \wd0
		\divide \label@push by 2
		\hbox to0pt{\hss\makeeqnlabel{\theequation}\qquad\hskip\label@push}%
		\hfil\egroup
     	\endtrivlist
     }

\newbox\save@label
\def\margin@show{\relax}  %needed?

\newcounter{eqnplus}

\def\alignment@label#1{%
	\setcounter{eqnplus}{\theequation}%
	\stepcounter{eqnplus}%
	\global\setbox\save@label=
		\vbox{\unvbox\save@label
			\smallskip\footnotesize\itshape\ref{#1}=#1}%
	%Repacement for work done by label
	\@bsphack
	\protected@write\@auxout{}%
		 {\string\newlabel{#1}{{\theeqnplus}{\thepage}}}%
	\@esphack
}
\let\Label=\alignment@label

%\labelsep=0pt
%\def\LBL#1{\leqno{\hbox to 0pt{\hss$<$\ref{#1}$>$\qquad}}\refstepcounter{equation}\protected@write \@auxout {}{\string \newlabel {#1}{{\theequation}{\thepage }}}}

%\def\maketag@@@#1{\llap{\m@th\small\normalfont#1\qquad}}
\def\maketag@@@#1{\llap{\m@th\normalfont#1\qquad}}


\def\tagform@#1{%
	\maketag@@@{\leqn\ignorespaces#1\unskip\@@italiccorr\reqn}%
}
\def\new@tagform@#1{%
	\maketag@@@{%
	\small\LC@{\eqn@label}\,%
	\leqn \ignorespaces#1\unskip\@@italiccorr \reqn
}}%

\let\dbp@tagform@ = \tagform@
\let\old@tagform@\tagform@

%\let\Label=\label  % Use for label within alignment.
					% Changed by Showlabels

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% showlabels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif\ifshowlabels
\showlabelsfalse
\newif\ifShowlabels
\Showlabelsfalse

%defaults with no form of showlabel
\def\showmarginlabels{\relax}
%\usepackage{color}
%\def\LabelColor{red}
%\def\LC@{\textcolor{\LabelColor}}
%\def\label@color{\color{\LabelColor}}
\def\LC@{\relax}
\def\label@color{\relax}

\let\old@label = \label
\def\new@label#1{%
	\gdef\eqn@label{#1}%
	\old@label{#1}%
	\leavevmode\vadjust{%
		\vbox{\kern-\LBLdim\@LBL{#1}\offinterlineskip\ignorespaces}%
	}%
}%

% Hard to get at labels within alignment



\def\@LBL#1{\vtop to\LBLdim{%
	\baselineskip\LBLdim%
	\vss\hbox to 0pt{\llap{\small\LC@{#1}\hskip50pt}}\hss}}%

\def\Showlabels{%
	\Showlabelstrue
%	\oddsidemargin=100pt
%	\evensidemargin=100pt
	\oddsidemargin=60pt
	\evensidemargin=60pt
	 \newdimen\LBLdim
	 \LBLdim=0.01in
	\let\old@label = \label
	\let\old@tagform@ = \tagform@

	\let\tagform@ = \new@tagform@
	\def\label##1{%
		\gdef\eqn@label{##1}%
		\old@label{##1}\leavevmode\vadjust{%
			\vbox{%
				\kern-\LBLdim\@LBL{##1}%
				\offinterlineskip\ignorespaces
	}}}%
	
%	\gdef\bAlignL##1\eAlignL{%
%%	\let\label=\alignment@label
%%	\let\Label=\alignment@label
%	\let\tagform@=\old@tagform@
%	\begin{align}##1\end{align}%
%%	\let\Label=\old@label
%%	\let\Label=\label       % might be wrong
%	\let\tagform@=\new@tagform@
%	\showmarginlabels
%	}% end bAlignL

	\renewcommand{\beq}{%
		\let\label=\new@label
		\begin{equation}%
	}%  
	\renewcommand{\eeq}{\end{equation}\let\label=\new@label}%
	
%	\def\bxAlignat##1##2\exAlignat{%
%		\let\Label=\alignment@label
%		\let\tagform@=\old@tagform@
%		\begin{xalignat}{##1}##2\end{xalignat}%
%		\let\tagform@=\new@tagform@
%		\let\Label=\label
%		\showmarginlabels
%		
%	}%
	\def\showmarginlabels{%
%	\marginpar{\color{\LabelColor}\unvbox\save@label}%
%	\marginpar{\LC@\unvbox\save@label}%
	\marginpar{\label@color \unvbox\save@label}%
}

}% Showlabels



% original version
\def\showlabels{%
	\showlabelstrue
	\oddsidemargin=100pt
	\evensidemargin=100pt
	 \newdimen\LBLdim
	 \LBLdim=0.01in
	\let\LAB=\label
	\def\@LBL##1{\vtop to\LBLdim{%
		\baselineskip\LBLdim%
		\vss\hbox to 0pt{\llap{\small##1\hskip50pt}}\hss}}%
	\def\tagform@##1{%
		\maketag@@@{\small\eqn@label\,\leqn\ignorespaces##1\unskip\@@italiccorr\reqn}}%
	\def\label##1{%
		\gdef\eqn@label{##1}%
		\LAB{##1}\leavevmode\vadjust{%
			\vbox{\kern-\LBLdim\@LBL{##1}\offinterlineskip\ignorespaces
	}}}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Headings, subheadings, ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Bechtolsheim I:310
\newskip\@MaxVskipGlue
\def\MaxVskip#1{%
\par
\@MaxVskipGlue=#1\relax
    \ifdim\lastskip < \@MaxVskipGlue
        \ifdim\lastskip = 0pt
        \else
            \vskip-\lastskip
        \fi
        \vskip\@MaxVskipGlue
    \fi
}

%%\GenericHead{above}{font or baseline}{hangindent}{number}
%%{text}{below}{leftshift}{hsize}
 % hangindent = 0 signals that no extra space added to first line
 % vskip after only if below > 0

\newskip\hangGeneric

\def\styleGeneric{\rightskip=0pt plus 50pt\hyphenpenalty=10000}
\def\RaggedHead{\rightskip=0pt plus 50pt\hyphenpenalty=10000}

 
\def\GenericHead#1#2#3#4#5#6#7#8{
\relax\MaxVskip{#1}
\hangGeneric=#3
   \bgroup
      \hsize=#8
      \let\\=\newline
      \styleGeneric\interlinepenalty=10000
      \ifnum\hangGeneric > 0
         \setbox0=\hbox to\hangGeneric{#2#4\hfil}
      \else\ifnum\hangGeneric < 0
         \setbox0=\hbox to-\hangGeneric{#2#4\hfil}
         \hangGeneric=0
      \else
         \setbox0=\hbox{#2#4} %number
         \hangGeneric=\wd0
      \fi\fi
      \dimen0=#7
      \ifnum\dimen0>0
         \setbox0=
         \vbox{\hangindent\hangGeneric\hangafter1\noindent#2\box0 #5}
         \moveleft#7\copy0
      \else
         \hangindent\hangGeneric\hangafter1\noindent#2\box0 #5
      \fi
      \dimen0=#6
      \ifnum\dimen0>0
         \par\nobreak\vskip#6
      \fi
   \egroup
}   

\newskip\beforeSHeadskip
\beforeSHeadskip=12pt plus2pt minus1pt
\newskip\afterSHeadskip
\afterSHeadskip=4pt

\def\subheading#1{
	\let\styleGeneric=\RaggedHead
	\GenericHead
	{\beforeSHeadskip}{\bf}
	{0pt}{}{#1.}{\afterSHeadskip}{0pt}{\hsize}
	\noindent\ignorespaces
}

\newskip\beforeSSHeadskip
\beforeSSHeadskip=12pt plus2pt minus1pt
\def\hardquad{\kern1em}


\def\subsubheading#1{%
	\MaxVskip\beforeSSHeadskip
	\noindent{\bf\ignorespaces#1} \unskip
	\nobreak\hardquad\ignorespaces
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problems
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newcounter{ProbNum}
%\setcounter{ProbNum}{0}
\newcounter{pPartNum}[ProbNum]

%\def\Problems{\pagestyle{problems}\section*{Problems}\setcounter{ProbNum}{0}}

\def\Problems{%
	\section*{Problems}%
	\setcounter{ProbNum}{0}%
	\mark{{Problems for \ChapTitle/ \ChapterNumber}}%
	\gdef\SectionName{Problems for \ChapTitle/ \ChapterNumber}
	\normalfalse
}

\def\Pref#1{[\ref{Prob.#1}]}

\def\problem[#1]{%
	\gdef\star@{}%
	\problem@[#1]%
}

\def\starproblem[#1]{%
	\gdef\star@{*}%
	\problem@[#1]%
}
	
\def\problem@[#1]{%
	\bigskip
	\stepcounter{ProbNum}%
	\protected@write \@auxout {}{\string \newlabel {Prob.#1}{{\theProbNum}{\thepage}}}%
	\noindent
	\llap{\star@\Pref{#1}\qquad}\ignorespaces%
	\ifshowlabels\marginpar{\small\itshape #1}\fi
}

%\def\ppart{% \smallskip\item{(\romannumeral\thepPartNum)}\stepcounter{pPartNum}}
\def\ppart{\smallskip(\romannumeral\thepPartNum)\stepcounter{pPartNum}}

\def\ppart{\smallskip\stepcounter{pPartNum}\noindent\llap{(\roman{pPartNum})\quad}}

\def\ppart{\smallskip\stepcounter{pPartNum}\noindent\llap{(\roman{pPartNum}) }}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Quotations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newdimen\quotationindent
\quotationindent=3em
\def\Quotation{
\par\bgroup\advance\leftskip by\quotationindent
%\rightskip=0pt plus 1pt minus1pt\spaceskip=0pt\xspaceskip=0pt
\advance\rightskip by\quotationindent
\medskip\noindent\nobreak
\ninerm\baselineskip11pt}

\def\Quotation{
\par\bgroup\small\advance\leftskip by\quotationindent
%\rightskip=0pt plus 1pt minus1pt\spaceskip=0pt\xspaceskip=0pt
\advance\rightskip by\quotationindent
\medskip\noindent\nobreak
\baselineskip11pt}

\def\endQuotation#1{\par\nobreak
\hbox to\hsize{\hfil[#1]\kern\quotationindent}\smallskip
\egroup\noindent\ignorespaces}

\let\quote=\Quotation
\def\endquote{\medskip\egroup\noindent\ignorespaces}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bibliography
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%/Users/pollard/Library/texmf/bibtex/bib/DBP.bib
%\def\References{\bibliographystyle{chicago}\bibliography{DBP}}

%\def\References{\pagestyle{references}\bibliographystyle{chicago}\bibliography{DBP}}

\def\References{%
	\bibliographystyle{chicago}%
	\bibliography{DBP}%
	\gdef\SectionName{References for \ChapTitle/ \ChapterNumber}%
	\normalfalse

}

\def\citeNthree#1#2#3{\citeANP{#1}~(\citeyearNP{#1}, \citeyearNP{#2}, \citeyearNP{#3})}



\makeatother


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%






\newif\ifDRAFT
\DRAFTfalse


\Raggedright
\raggedbottom




\input /Users/pollard/Manuscripts/Asymptopia/asy.GLOBAL.crf

\def\Prereq#1{\getcref{Prereq..Sect.#1}{\smc 
Prerequisites}~[\S\crefsection]}


\def\Prereq#1{\getcref{Prereq..Sect.#1}{{\smc 
Prerequisites}~[\S\crefsection]}}
% \MakeCref (CHAP:)(SECT:4)(PAGE:5)(NUM:5)(KEY:Prereq..unif.Op)
% \MakeCref (CHAP:)(SECT:4)(PAGE:4)(NUM:4)(KEY:Prereq..Sect.uniform.stoch.order)


\def\mod#1{{\rm mod}[#1]}






%% from Paris
\def\UGMTP#1{{\ninerm UGMTP~\S#1}}

\def\elldot{\dot \ell}
\def\ellddot{\ddot \ell}
\def\piln{\prod\NL_{i\le n}}


\def\LLca{\LL^+_\s}
\def\Gam{\Gamma}
\def\rand{\Re}
\def\randbar{\overline\Re}

%\def\frak#1{{\fam\eufmfam\relax#1}}
\def\Leb{{\mathfrak m}}

\PRIVATE
\def\citeNP{\CheckForLeftBracket\citeNP@}
\def\citeNP@[#1]#2{\WriteCite@{#2}\gbd@{#2}\bibAuthor~\bibYear\lb@[#1]}
\PUBLIC

\def\sdim{\text{s-dim}}
\def\VCdim{\text{VC-dim}}


\def\fb{{\bf f}}
\def\Fb{{\bf F}}

\def\co{\text{co}}
\def\rootJn{J_n^{1/2}}
\def\irootJn{J_n^{-1/2}}
\def\siln{\sum_{i\le n}}
\def\that{\hat t}

\def\endQuotation#1{\par\nobreak
\line{\hfil#1\kern\quotationindent}\smallskip
\egroup\noindent\ignorespaces}


\def\BL{{\smc BL}}
\def\BLxx{{\smc BL}(\xx)}
\def\normBL#1{\norm{#1}_{BL}}
