
\usepackage{theorem,amsmath,amssymb,fancyhdr,epsfig}
\usepackage{ifthen}  % provides conditonals

\def\arrow{{\:\longrightarrow\:}}
\newcommand{\restrict}[1]{{\left|_{{\phantom{|}\!\!}_{#1}}\right.}}
\newcommand{\cntrct}                % contraction with a vector field
{\hspace{2pt}\raisebox{1pt}{\text{$\lrcorner$}}\hspace{2pt}}

\renewcommand{\leq}{\leqslant}
\renewcommand{\geq}{\geqslant}
\renewcommand{\epsilon}{\varepsilon}


%\addtolength{\topmargin}{-5mm}
%\addtolength{\textheight}{40mm}
%\addtolength{\oddsidemargin}{-25mm}
%\addtolength{\textwidth}{45mm}

\setlength{\headheight}{15pt}
\pagestyle{fancy} 
\lhead{\tiny Math in Moscow, HSE, Spring 2013} 
\lfoot{\tiny Issued \firstdate} 
\cfoot{-- \thepage \ -- } \rfoot{\tiny Handout \thesection,\ \ \sc\version}
\rhead{{\tiny  Misha Verbitsky}}


\def\1{\sqrt{-1}}
\def\6{\partial}
\def\rad{\operatorname{\sf rad}}
\def\Alt{\operatorname{\sf Alt}}
\def\Sym{\operatorname{\sf Sym}}
\def\Id{\operatorname{\sf Id}}
\def\rk{\operatorname{\sf rk}}
\def\Hom{\operatorname{Hom}}
\def\im{\operatorname{im}}
\def\Vol{\operatorname{Vol}}
\def\Lie{\operatorname{Lie}}
\def\Map{\operatorname{Map}}
\newcommand{\End}{\operatorname{End}}
\newcommand{\Diff}{\operatorname{Diff}}
\newcommand{\Mat}{\operatorname{Mat}}
\newcommand{\Tot}{\operatorname{Tot}}
\newcommand{\diam}{\operatorname{\sf diam}}
\def\Der{\operatorname{Der}}
\newcommand{\Char}{\operatorname{\sf char}}

\def\calo{{\mathcal O}}
\def\Z{{\mathbb Z}}
\def\R{{\mathbb R}}
\def\C{{\mathbb C}}
\def\Q{{\mathbb Q}}
\def\N{{\mathbb N}}




\newif\ifshaded

\makeatletter
\begingroup
\gdef\th@upshape{\normalfont
  \def\@begintheorem##1##2{%
        \item[\hskip\labelsep \theorem@headerfont ##1\ ##2.]
        \writevedomost{\string\mc{\theExercise} \string & \string & \string 
        \\ \string \hline}
   \shadedfalse
   }%
\def\@opargbegintheorem##1##2##3{%
   \item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3).]
   \writevedomost{\string\mc{\theExercise ##3}  \string & \string \grd \string & \string\grp
   \string \\ \string \hline}
   \shadedtrue
   }}%
\endgroup

\theoremstyle{upshape}

\newtheorem{Exercise}{Exercise}[section]

\begingroup
\gdef\th@generic{\normalfont
  \def\@begintheorem##1##2{%
        \item[\hskip\labelsep \theorem@headerfont ##1\ ##2.]
     }%
\def\@opargbegintheorem##1##2##3{%
   \item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3).]
    }}
\endgroup

\theoremstyle{generic}

\newtheorem{Definition}{Definition}[section]
\newtheorem{Remark}{Remark}[section]

\begingroup
\gdef\th@upshapenonumber{\normalfont
  \def\@begintheorem##1##2{%
        \item[\hskip\labelsep \theorem@headerfont ##1.]}%
\def\@opargbegintheorem##1##2##3{%
   \item[\hskip\labelsep \theorem@headerfont ##1\ (##3).]}}
\endgroup

\theoremstyle{upshapenonumber}

\newtheorem{Hint}{Hint}[section]

\renewcommand{\labelenumi}{\alph{enumi}.}
\newcommand{\subs}[1]{{\bigskip \bf\large {\centerline {#1}}\bigskip}}
\newcommand{\sttr}{{\bf(*)}}
\newcommand{\shrk}{{\bf(!)}}
\newcommand{\doublesttr}{{\bf(**)}}

\newcommand{\listok}[2]{%
\setcounter{page}{1}
\lhead{ \scriptsize #2 }
\section*{#2}
\refstepcounter{section}
\setcounter{section}{#1}
\writevedomost{\string & \string \multicolumn{3}{|c|} { \string \scriptsize
{ issued: %
   \firstdate}}\string \\ \string \hline} %
\renewcommand{\theequation}{\thesection.\arabic{equation}}
}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% VEDOMOST GENERATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newwrite\Vedomost
\immediate\openout\Vedomost = \jobname.vdm
\newcommand{\writevedomost}[1]{\immediate\write\Vedomost{ #1 }}

\newcommand{\NewVedomost}%
{\writevedomost{\string\end{tabular} \string & \string\vedomostsize %
\string\begin{tabular}[t]{|c|c|@{}c@{}|@{}c@{}|} %
\string\hline %
\string\mc{$N^0$}\string&\string\dtt\string&\string\pdp\string\\ \string\hline %
}}

\def\grd{\psboxit{box .7 setgray fill}{\phantom{\dtt}}\vphantom{666}}
\def\grp{\psboxit{box .7 setgray fill}{\phantom{\pdp}}\vphantom{666}}


\def\exercise{\begin{Exercise}}
\def\ez{\end{Exercise}}
\def\remark{\begin{Remark}}
\def\er{\end{Remark}}
\def\hint{\begin{Hint}}
\def\eh{\end{Hint}}
\def\definition{\begin{Definition}}
\def\ed{\end{Definition}}
\def\goth{\mathfrak}
\def\enum{\begin{enumerate}} 
\def\ee{\end{enumerate}}


\newcommand{\ite}[1][{}]{\item %
    \ifthenelse { \equal {#1} {} } 
    { \ifshaded
          {\writevedomost{\string & \alph{enumi}\! #1 \string & \string \grd \string & \string\grp
   \string \\ \string \hline }}
      \else
        \writevedomost{\string & \alph{enumi} \string &\string & \string \\ \string \hline } 
      \fi 
    }
    { (#1) \writevedomost{\string & \alph{enumi}\! #1 \string & \string \grd \string & \string\grp
   \string \\ \string \hline } }
}
