%% Revision 1.0  2014/03/12 16:33:14
%% Jean-Pierre Demailly <jean-pierre.demailly@ujf-grenoble.fr>
%% Initial revision

%%%%%%%%%%%%%%%%%%%%%%
% Useful math packages
%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amssymb} % Include useful math symbols
\usepackage{amsmath} % Include useful math stuff
\usepackage{textcomp} % provide lots of new symbols

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Support for nicer environments to be used
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{verbatim} % Environment for commenting out blocks of text & for better verbatim
\usepackage{subfigure} % make it possible to include more than one captioned figure/table
\usepackage{enumerate} % Customizable enumerate environment
\usepackage{multicol} % Good multi-column support
\usepackage{pdflscape} % Mid-document landscape for PDF's
\usepackage{fancyhdr} % Improved header style

%%%%%%%%%%%%%%%%
% Hyperlinks
%%%%%%%%%%%%%%%%
% hyperlinks, with coloured links
\usepackage[bookmarks,colorlinks]{hyperref}  
% Colors for printing:
\hypersetup{linkcolor=blue,citecolor=red,filecolor=green,urlcolor=magenta} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Layout the page properly according to standard printing guidelines
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\textwidth}{16.9cm} % Standard print size
\setlength{\textheight}{24cm} % Standard print size
\setlength{\headheight}{14pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Customize the report style so that it displays section in place
%     instead of chapter and so forth
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter

\newcommand\forceindent{\strut\indent}

\newcommand{\openbox}{\leavevmode
  \hbox to.77778em{%
  \hfil\vrule
  \vbox to.675em{\hrule width.6em\vfil\hrule}%
  \vrule\hfil}}
\DeclareRobustCommand{\textsquare}{%
  \begingroup \usefont{U}{msa}{m}{n}\thr@@\endgroup
}
\providecommand{\qedsymbol}{\openbox}
\newenvironment{proof}[1][\proofname]{\par
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist
  \item[\hskip\labelsep
        \itshape
    #1\@addpunct{.}]\ignorespaces
}{%
  \endtrivlist\@endpefalse
}
\providecommand{\proofname}{Proof}

\newcommand\TOCname{Contents}

\newenvironment{prelims}[1][]{\par
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist
  \fontsize{8}{10pt}\selectfont
  \def\contentsname{{\normalsize\bf\TOCname}}
  \item[\itshape
  #1]\ignorespaces
}{%
  \endtrivlist\@endpefalse
}

\renewcommand{\abstractname}{Abstract}
\renewcommand{\abstract}[1]{\noindent{\bf\abstractname.} #1\smallskip}

\newcommand{\keywordsname}{Keywords}
\newcommand{\keywords}[1]{\noindent{\bf\keywordsname.} #1\smallskip}

\newcommand{\MSCclassname}{2010 Mathematics Subject Classification}
\newcommand{\MSCclass}[1]{\noindent{\bf\MSCclassname.} #1\smallskip}

\DeclareRobustCommand{\qed}{%
  \ifmmode \mathqed
  \else
    \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
    \quad\hbox{\qedsymbol}%
  \fi
}

\newcommand{\@pithanks}[1]{\xdef\@thefnmark{}\let\hyper@@anchor\@gobble
\@footnotetext{\kern-6.66pt\kern-\columnsep\ignorespaces#1}}

\newcommand{\accepteddate}{}
\newcommand{\journal}[1]{\def\journalname{#1}}
\newcommand{\acceptation}[1]{\def\accepteddate{#1}}

\let\@pititle=\title
\renewcommand{\title}[1]{\def\titl@string{#1}\@pititle{\bf{#1}}}
\newcommand{\titlemark}[1]{\def\titl@string{\bf{#1}}}

\let\@piauthor=\author
\def\author#1{\def\@uthorstring{#1}\@piauthor{\bf{#1}}}
\def\authormark#1{\def\@uthorstring{\bf{#1}}}

\newbox\epi@evenhead{}

%% Disable \MakeUppercase and redefine \markright !!
\renewcommand{\MakeUppercase}[1]{#1}

\renewcommand{\markright}[1]{%
  \begingroup
    \let\label\relax \let\index\relax \let\glossary\relax
    \expandafter\@markright\@themark {#1}%
    \@temptokena \expandafter{\@themark}%
    \mark{\the\@temptokena}%
  \endgroup
  \ifnum \@episecdepth=0 \setbox\epi@evenhead=\hbox{\scriptsize#1}\fi%
  \if@nobreak\ifvmode\nobreak\fi\fi}

\renewcommand{\markboth}[2]{%
  \begingroup
    \let\label\relax \let\index\relax \let\glossary\relax
    \unrestored@protected@xdef\@themark {{#1}{#2}}%
    \@temptokena \expandafter{\@themark}%
    \mark{\the\@temptokena}%
  \endgroup
  \ifnum \@episecdepth=0 \setbox\epi@evenhead=\hbox{\scriptsize#1}\fi%
  \if@nobreak\ifvmode\nobreak\fi\fi}

\fancyfoot{}
\fancyhead[LR]{
\ifnum \c@page=1
{\scriptsize\bf
\ifx\DOIfi@ld\undefined\else
$\smash{\raise-5.5mm\rlap{\url{http://dx.doi.org/\DOIfi@ld}}}$\fi\journalname}\hfill
{\scriptsize\accepteddate}%
\else \ifodd\c@page{\scriptsize\@uthorstring,~\titl@string \hfill{\bf\number\c@page}}\else
{\scriptsize{\bf\number\c@page}\hfill\copy\epi@evenhead}\fi\fi}

%% Modification of \maketitle
\let\@pimaketitle=\maketitle
\def\maketitle{%
\@pimaketitle\let\thanks\@pithanks
\thispagestyle{fancy}
\pagestyle{fancy}
}

%% Allow size change in bibliography
\def\sm@lltag{small}
\newcommand{\bibliographysize}[1]{%
\def\@tmp{#1}%
\ifx \@tmp\sm@lltag
\fontsize{8}{10pt}\selectfont
\normallineskip=2pt
\normalbaselines
\parskip=0pt \fi}

\newcommand{\bibliographymark}[1]{%
\setbox\epi@evenhead=\hbox{{\scriptsize #1}}}

%% Adapt theorem environments
\def\@thmcountersep{}
\def\newtheorem#1{%
  \@ifnextchar[{\@othm{#1}}{\@nthm{#1}}}
\def\@nthm#1#2{%
  \@ifnextchar[{\@xnthm{#1}{#2}}{\@ynthm{#1}{#2}}}
\def\@xnthm#1#2[#3]{%
  \expandafter\@ifdefinable\csname #1\endcsname
    {\@definecounter{#1}\@newctr{#1}[#3]%
     \expandafter\xdef\csname the#1\endcsname{%
       \expandafter\noexpand\csname the#3\endcsname\@thmcountersep%
          {}\@thmcounter{#1}}%
     \global\@namedef{#1}{\@thm{#1}{#2}}%
     \global\@namedef{end#1}{\@endtheorem}}}
\def\@ynthm#1#2{%
  \expandafter\@ifdefinable\csname #1\endcsname
    {\@definecounter{#1}%
     \expandafter\xdef\csname the#1\endcsname{\@thmcounter{#1}}%
     \global\@namedef{#1}{\@thm{#1}{#2}}%
     \global\@namedef{end#1}{\@endtheorem}}}
\def\@othm#1[#2]#3{%
  \@ifundefined{c@#2}{\@nocounterr{#2}}%
    {\expandafter\@ifdefinable\csname #1\endcsname
    {\global\@namedef{the#1}{\@nameuse{the#2}}%
  \global\@namedef{#1}{\@thm{#2}{#3}}%
  \global\@namedef{end#1}{\@endtheorem}}}}
\def\@thm#1#2{%
  \refstepcounter{#1}%
  \@ifnextchar[{\@ythm{#1}{#2}}{\@xthm{#1}{#2}}}
\def\@xthm#1#2{%
  \@begintheorem{#2}{\csname the#1\endcsname.}\ignorespaces}
\def\@ythm#1#2[#3]{%
  \@opargbegintheorem{#2}{\csname the#1\endcsname.}{#3}\ignorespaces}
\def\@thmcounter#1{\noexpand\arabic{#1}}

\def\@begintheorem#1#2{\trivlist
   \item[\hskip \labelsep{\bfseries #1\ #2}]\itshape}
\def\@opargbegintheorem#1#2#3{\trivlist
      \item[\hskip \labelsep{\bfseries #1\ #2\ (#3)}]\itshape}
\def\@endtheorem{\endtrivlist}

% use dots in table of contents

%%%%%%%%%%%%%%%%%%%%%%%%%
% Predefined environments
%%%%%%%%%%%%%%%%%%%%%%%%%

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{example}[theorem]{Example}

%%%%%%%%%%%%%%%%%%
% dedication stuff
%%%%%%%%%%%%%%%%%%
\def\dedication#1{\begin{center}\emph{#1}\end{center}\vskip3ex}

%%%%%%%%%%%%%%%%%%%%%
% Miscellaneous stuff
%%%%%%%%%%%%%%%%%%%%%

\newcommand{\authoraddresses}[1]{\par{\parindent=0cm \parskip=5pt plus 2pt minus 1pt
#1}}

\newcommand{\email}{\emph{e-mail}\/:\ }

\newcommand{\DOIstring}[1]{\gdef\DOIfi@ld{#1}}

\def\@MRExtract#1 #2!{#1}     % thanks to Martin Hairer for this macro
\newcommand{\MR}[1]{% we need to strip the "(...)"
  \xdef\@MRSTRIP{\@MRExtract#1 !}%
  \href{http://www.ams.org/mathscinet-getitem?mr=\@MRSTRIP}{MR-\@MRSTRIP}}
\newcommand{\ARXIV}[1]{\href{http://arXiv.org/abs/#1}{arXiv:#1}}
\newcommand{\HAL}[1]{\href{http://hal.archives-ouvertes.fr/#1}{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paper formats, make A4 default
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\l@ttertype{letter}
\def\Af@urtype{A4}
\newcommand{\setpapertype}[1]{%
\def\@tmp{#1}%
\ifx \@tmp\Af@urtype
\paperwidth=210mm \paperheight=297mm 
\topmargin=-0.65cm\oddsidemargin=-0.4cm\evensidemargin=-0.4cm\fi
\ifx \@tmp\l@ttertype
\paperwidth=8.5in \paperheight=11in 
\topmargin=-1.35cm\oddsidemargin=-0.2cm\evensidemargin=-0.2cm\fi}

\setpapertype{A4}

\makeatother