%% This is file `imsart.sty'
%%
%% LaTeX 2e style file for the processing of LaTeX2e files
%% of the following IMS journals:
%%
%%   The Annals of Probability
%%   The Annals of Applied Probability
%%   The Annals of Statistics
%%   Statistical Science
%%   Probability Surveys
%%   IMS Lecture Notes-Monograph Series
%%
%%   Institute of Mathematical Statistics, U.S.A.
%%
%% Macros written by Vytas Statulevicius, VTeX, Lithuania
%% for Institute of Mathematical Statistics, U.S.A.
%% Please submit bugs or your comments to vytas@vtex.lt
%%
%% The original distribution is located at:
%% http://www.e-publications.org/ims/support
%%
%% This style file contains additional macros and is designed to use
%% with standart "article.cls"
%%
%% You are free to use this style file as you see fit, provided 
%% that you do not make changes to the file. 
%% If you DO make changes, you are required to rename this file.
%%
%% It may be distributed under the terms of the LaTeX Project Public
%% License, as described in lppl.txt in the base LaTeX distribution.
%% Either version 1.0 or, at your option, any later version.
%%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%%
%% Bug fixes and changes:

% TeX programming: Vytas Statulevicius, VTeX, Lithuania, vytas@vtex.lt
% Requires Latex2e, ver.2000.06

\def\imsfmt@name{imsart}
\def\imsfmt@version{2005/05/19}

\ProvidesFile{imsart.sty}
        [\imsfmt@version IMS article style (VS)]

% hyperref must be loaded after:
\@ifpackageloaded{hyperref}{\@latex@error{Package 'hyperref' must be loaded after 'imsart'!}\@ehc}{}

% General options:

% Put keywords as footnote
\newif\if@keywordsasfootnote
\DeclareOption{keywordsasfootnote}{\@keywordsasfootnotetrue}

% Put history as footnote
\newif\if@historyasfootnote
\DeclareOption{historyasfootnote}{\@historyasfootnotetrue}                  

% Put address as footnote
\newif\if@addressasfootnote
\DeclareOption{addressasfootnote}{\@addressasfootnotetrue}                  

% Put addresses at end of document
\newif\if@addressatend
\DeclareOption{addressatend}{\@addressatendtrue}                  

% Put "." after inline section headings:
\newif\if@autosecdot 
\DeclareOption{autosecdot}  {\@autosecdottrue}
\DeclareOption{noautosecdot}{\AtBeginDocument{\@autosecdotfalse}}

% Load amsmath style with corerect settings:
\newif\if@load@amsmath
\DeclareOption{amsmath}{\@load@amsmathtrue}

% Load amsthm style with corerect settings:
\newif\if@load@amsthm
\DeclareOption{amsthm}{\@load@amsthmtrue}

% Load amsmath with leqno option 
\newif\if@amsmath@leqno

% Load natbib with correct settings:
\newif\if@load@natbib
\DeclareOption{natbib}{\@load@natbibtrue}

% IMS journals AAP, AOP, AOS has a different layout:
\newif\if@imslayout

% Information about journals
\DeclareOption{ps}{%
   \def\journal@id{-ps}
   \def\@journal{Probability Surveys}
   \def\journal@issn{ISSN: 1549-5787\\}
   \def\journal@url{http://www.i-journals.org/ps}}

\DeclareOption{lnms}{%
   \def\journal@id{-lnms}
   \def\@journal{IMS Lecture Notes--Monograph Series}
   \def\journal@url{http://www.imstat.org/publications/lecnotes.htm}
   \set@page@layout{30pc}{610pt}% 30pc * 51 line
   \@historyasfootnotetrue
   \@keywordsasfootnotetrue
   \@addressatendtrue
   \AtBeginDocument{%
   \setattribute{keywordname}{size}{\itshape}
                   }
}


% Options for the IMS journals:

\DeclareOption{aap}{%
   \def\journal@id{-aap}
   \def\@journal{Submitted to the Annals of Applied Probability}
   \def\journal@url{http://www.imstat.org/aap/}
%   \def\journal@issn{$\copyright$~\ims@href{http://www.imstat.org}{Institute of Mathematical Statistics}, \@copyrightyear}%
   \set@page@layout{30pc}{550pt}% 30pc * 46 line
   \@twosidetrue
   \input{leqno.clo}% formula numbers at left
   \@amsmath@leqnotrue
   \@historyasfootnotetrue
   \@keywordsasfootnotetrue
   \@addressatendtrue
   \@imslayouttrue
   \@autosecdottrue
}

\DeclareOption{aop}{%
   \def\journal@id{-aop}
   \def\@journal{Submitted to the  Annals of Probability}
   \def\journal@url{http://www.imstat.org/aop/}
%   \def\journal@issn{$\copyright$~\ims@href{http://www.imstat.org}{Institute of Mathematical Statistics}, \@copyrightyear}%
   \set@page@layout{30pc}{550pt}% 30pc * 46 line
   \@twosidetrue
   \input{leqno.clo}% formula numbers at left
   \@amsmath@leqnotrue
   \@historyasfootnotetrue
   \@keywordsasfootnotetrue
   \@addressatendtrue
   \@imslayouttrue
   \@autosecdottrue
}

\DeclareOption{aos}{%
   \def\journal@id{-aos}
   \def\@journal{Submitted to the  Annals of Statistics}
   \def\journal@url{http://www.imstat.org/aop/}
%   \def\journal@issn{$\copyright$~\ims@href{http://www.imstat.org}{Institute of Mathematical Statistics}, \@copyrightyear}%
   \set@page@layout{30pc}{550pt}% 30pc * 46 line
   \@twosidetrue
   \input{leqno.clo}% formula numbers at left
   \@amsmath@leqnotrue
   \@historyasfootnotetrue
   \@keywordsasfootnotetrue
   \@addressatendtrue
   \@imslayouttrue
   \@autosecdottrue
}


\DeclareOption{sts}{%
   \def\journal@id{-sts}
   \def\@journal{Submitted to the Statistical Science}
   \def\journal@url{http://www.imstat.org/sts/}
%   \def\journal@issn{$\copyright$~\ims@href{http://www.imstat.org}{Institute of Mathematical Statistics}, \@copyrightyear}%
   \set@page@layout{30pc}{550pt}% 30pc * 46 line
   \@twosidetrue
   \input{leqno.clo}% formula numbers at left
   \@amsmath@leqnotrue
   \@historyasfootnotetrue
   \@keywordsasfootnotetrue
   \@addressatendtrue
   \@imslayouttrue
   \@autosecdottrue
}

% Spacing
\DeclareOption{doublespacing}{\doublespacing}
\DeclareOption{singlespacing}{\singlespacing}

\def\singlespacing{\renewcommand{\baselinestretch}{}\large\normalsize}
\def\doublespacing{\renewcommand{\baselinestretch}{1.6}\large\normalsize}

% Do not print id line at bottom of the page:
\DeclareOption{noinfoline}{\AtBeginDocument{\let\info@line\@empty}}
\DeclareOption{infoline}  {\AtBeginDocument{\let\info@line\infoline@text}}

% Put lines numbers in margins
\newif\ifnumberlines@ \numberlines@false
\DeclareOption{linenumbers}{\numberlines@true}
\DeclareOption{nolinenumbers}{\numberlines@false}

% Initiate some info:
\def\@journal{}
\def\journal@url{}
\def\journal@issn{}
\def\journal@id{}
\def\paper@url{}
\def\info@line{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% set@page@layout

% \set@page@layout{\textwidth}{\textheight}

\def\set@page@layout#1#2{%
%
  \setlength\textwidth{#1}
  \@settopoint\textwidth
  \setlength\textheight{#2}
  \@settopoint\textheight
%
% make side margins equal:
  \setlength\@tempdima        {\paperwidth}
  \addtolength\@tempdima      {-\textwidth}
  \setlength\oddsidemargin    {.5\@tempdima}
  \addtolength\oddsidemargin  {-1in}
  \setlength\evensidemargin   {\oddsidemargin}
  \@settopoint\oddsidemargin
  \@settopoint\evensidemargin
%
% topmargin
  \setlength\topmargin{\paperheight}
  \addtolength\topmargin{-2in}
  \addtolength\topmargin{-\headheight}
  \addtolength\topmargin{-\headsep}
  \addtolength\topmargin{-\textheight}
  \addtolength\topmargin{-\footskip}     % this might be wrong!
  \addtolength\topmargin{-.5\topmargin}
  \@settopoint\topmargin
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Load imsart.cnf with additional options:
\@input{\imsfmt@name.cnf}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Execute options

\ExecuteOptions{infoline}
\ProcessOptions

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% dimensions

\setlength\parindent {12\p@}
\setlength\headsep   {14\p@}
\setlength\footskip  {14\p@}

\setlength\smallskipamount{6\p@ \@plus 1\p@ \@minus 1\p@}
\setlength\medskipamount  {12\p@ \@plus 3\p@ \@minus 3\p@}
\setlength\bigskipamount  {18\p@ \@plus 3\p@ \@minus 3\p@}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% setattribute, getattribute, do@option@list

\def\setattribute{\@ifnextchar[\@setattribute{\@setattribute[]}}
\def\@setattribute[#1]#2#3#4{\expandafter\gdef\csname #2@#3\endcsname{#4}}
\def\getattribute#1#2{\csname #1@#2\endcsname}
\def\sep@key@value#1=#2/?/#3{\setattribute{#3}{#1}{#2}}
\def\do@option@list#1#2{%
  \@for\curr@option:={#2}\do{%
    \expandafter\sep@key@value\curr@option/?/{#1}\relax
  }%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% newpseudoenvironment
% same as \newenvironment, but new environment do not have additional groups \bgroup \egroup
% (i.e. all definitions are not local

\let\org@begin\begin
\let\org@end\end
\def\begin#1{%
  \@ifundefined{pseudo@#1}%
    {\org@begin{#1}}{\csname pseudo@#1\endcsname[0]\relax}%
  }
\def\end#1{%
  \@ifundefined{pseudo@#1}%
    {\org@end{#1}}{\csname pseudo@#1\endcsname[1]\relax}%
  }
\def\newpseudoenvironment#1#2#3{%
  \expandafter\gdef\csname pseudo@#1\endcsname[##1]{%
     \relax\ifcase##1\relax\def\@@next@@{#2}\or\def\@@next@@{#3}\else\let\@@next@@\relax\fi\@@next@@}%
  }




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pubyear, volume, paperno

\def\pubyear#1{\gdef\@pubyear{(#1) }\gdef\@copyrightyear{#1 }}
  \def\@pubyear{}
  \def\@copyrightyear{}

\def\volume#1{\gdef\@volume{Vol. #1 }}
  \gdef\@volume{}

\def\issue#1{\gdef\@issue{No. #1}}
  \gdef\@issue{}

\def\paperno#1{\gdef\@paperno{Paper no. #1 }}
  \gdef\@paperno{00} 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% firstpage, lastpage, pagerange

\newcounter{firstpage}
\newcounter{lastpage}

\def\firstpage#1{\def\@tempa{#1}\ifx\@tempa\@empty\else
  \global\c@firstpage=#1
  \global\c@lastpage=#1
  \global\c@page=#1 \ignorespaces\fi}

\def\lastpage#1{\def\@tempa{#1}\ifx\@tempa\@empty\else
  \global\c@lastpage=#1
  \ignorespaces\fi}

\def\pagerange@sep{--}

\def\set@pagerange{%
  \ifnum\c@firstpage=0%
  \else%
     \ifnum\c@firstpage=\c@lastpage%
        \gdef\@pagerange{\thefirstpage}%
     \else%
        \gdef\@pagerange{\thefirstpage\pagerange@sep\thelastpage}%
     \fi%
   \fi}

\def\@pagerange{}

\def\pagenumbering#1{%
    \gdef\thefirstpage{\csname @#1\endcsname\c@firstpage}%
    \gdef\thelastpage{\csname @#1\endcsname\c@lastpage}%
    \gdef\thepage{\csname @#1\endcsname\c@page}%
}

% hyperref redefines \pagenumbering, so we must override hyperref definition:
\let\ims@pagenumbering\pagenumbering


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% startlocaldefs, endlocaldefs

\def\startlocaldefs{\makeatletter}
\def\endlocaldefs{\makeatother}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% thanksref, thanksmark, thankslabel, thankstext
% to be safe with hyperref we will use original LaTeX definitions:
%

\def\saferef#1{\expandafter\safe@setref\csname r@#1\endcsname\@firstoftwo{#1}}
\let\safe@setref\@setref

\def\safelabel#1{\@bsphack
  \protected@write\@auxout{}%
         {\string\thanksnewlabel{#1}{{\@currentlabel}{\thepage}}}%
  \@esphack}

\let\thanksnewlabel\newlabel

% we want to use various counters:
\def\usethankscounter#1{%
  \@ifundefined{current@thankscounter}{\gdef\previous@thankscounter{#1}}{\xdef\previous@thankscounter{\current@thankscounter}}%
  \def\current@thankscounter{#1}}

\def\restorethankscounter{\xdef\current@thankscounter{\previous@thankscounter}}

\newcounter{thanks}
\def\thethanks{\@fnsymbol\c@thanks}
\usethankscounter{thanks}

% address ref:
\newcounter{addressref}
\def\theaddressref{\arabic{addressref}}


\def\thanksmark@fmt#1{\hbox{$^{#1}$}}
\def\thanksref@sep{,}

% hooks for the hyperref:
\def\thankref@hyperlink#1{\saferef{#1thanks}}
\def\thanks@hypertarget#1{}

% Isvedame zymes
\def\thanksref{\@ifnextchar[{\@tempswatrue\@thanksref}{\@tempswafalse\@thanksref[]}}

\def\@thanksref[#1]#2{%
  \if@tempswa% []
    \thanksmark@fmt{#1}%
  \else%
    \let\@tempa\@empty%
    \thanksmark@fmt{\@for\@tempb:=#2\do{%
       \@tempa\let\@tempa\thanksref@sep%
       \edef\@tempb{\expandafter\@firstofone\@tempb\@empty}%
       \thankref@hyperlink{\@tempb}}}%
   \fi}

% Suformuojame ir isvedame zyme
\def\thanksmark{\@ifnextchar[{\@tempswatrue\@thanksmark}{\@tempswafalse\@thanksmark[]}}

\def\@thanksmark[#1]#2{%  
   \@thankslabel[#1]{#2}%
   \safelabel{#2thanks}%
   \thanksmark@fmt{\expandafter\saferef{#2thanks}\thanks@hypertarget{#2}}}

% Suformuojame tik zyme
\def\thankslabel{\@ifnextchar[{\@tempswatrue\@thankslabel}{\@tempswafalse\@thankslabel[]}}

\def\@thankslabel[#1]#2{%
  \if@tempswa% []
     \protected@edef\@currentlabel{#1}%
   \else% 
      \refstepcounter{\current@thankscounter}%
   \fi%
   \safelabel{#2thanks}}%

% Suformuojame zyme ir idedame teksta i \@thanks:
\def\thankstext{\@ifnextchar[{\@tempswatrue\@thankstext}{\@tempswafalse\@thankstext[]}}

\def\@thankstext[#1]#2#3{%
  \@thankslabel[#1]{#2}%
  \protected@xdef\@thanks{\@thanks\protect\thanks@thefnmark{#2thanks}%
  \protect\@footnotetext{\thanks@hypertarget{#2}#3}}}%

\def\thanks@thefnmark#1{\begingroup\unrestored@protected@xdef\@thefnmark{\saferef{#1}}\endgroup}%



% ST makrosas savo numeracijos sistemos sukurimui
\def\setvaluelist#1#2{\@tempcnta=0\relax
  \@for\@curr@val:=#2\do{%
     \advance\@tempcnta by1\relax
     \expandafter\protected@xdef\csname #1@item@\the\@tempcnta\endcsname{\@curr@val}%
     }%
     \expandafter\protected@xdef\csname #1@item@0\endcsname{\the\@tempcnta}%
}
\xdef\getitemvalue#1#2{\noexpand\csname #1@item@#2\endcsname}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ead, \printead

\RequirePackage{keyval}

\def\email@text{e-mail: }
\def\url@text{url: }
\def\ead@sep{;~}

% naudojame keyval paketa
\define@key{ead}{email}[true]{\def\ead@type{email}}
\define@key{ead}{url}[true]{\def\ead@type{url}}
\define@key{ead}{label}{\def\ead@label{#1}}

\DeclareRobustCommand\ead[2][label= ,email]{{%
  \def\ead@type{email}% default
  \setkeys{ead}{#1}%
  \def\texttildelow{\noexpand\texttildelow}%
   \protected@edef\@currentlabel{#2}%
   \safelabel{\ead@label @\ead@type}}}

\newif\ifnot@ead@star

\DeclareRobustCommand{\printead}{\@ifstar{\not@ead@starfalse\@printead}{\not@ead@startrue\@printead}}

\def\@printead{\@ifnextchar[{\@tempswatrue\@@printead}{\@tempswafalse\@@printead[]}}

\def\@@printead[#1]#2{%
   \if@tempswa% []
     {\ead@size #1}%
   \else% 
     \def\ead@type{email}%
     \def\ead@prefix{mailto:}%
     \let\ead@text\email@text%
     \let\@ead@sep\relax%
     \@for\ead@ref:=#2\do{%
         \@ead@sep\let\@ead@sep\ead@sep%
         \@ifundefined{r@\ead@ref @url}{}{\let\ead@text\url@text\def\ead@type{url}\def\ead@prefix{http://}}%
         \ifnot@ead@star\ead@text\fi{\ead@size\def\null{}\ims@href{\ead@prefix\saferef{\ead@ref @\ead@type}}{\saferef{\ead@ref @\ead@type}}}%
         \let\ead@text\relax}%                        
   \fi%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \copyrightowner, \corref

\def\copyrightowner#1{\def\@copyrightowner{#1}}


% for corresponding author
\def\corref#1{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% normaltext, nohyphen, today

% normalus tekstas (justify)
\def\normaltext{\let\\=\@normalcr%
  \leftskip\z@ \@rightskip\z@ \rightskip\@rightskip%
  \parfillskip\@flushglue}

% skiemenavimo isjungimas
\def\nohyphen{\pretolerance=\@M \tolerance=\@M \hyphenpenalty=\@M \exhyphenpenalty=\@M}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\pagestyle{imsheadings} \thispagestyle{copyright}


\if@twoside

\def\ps@imsheadings{%
      \def\@oddfoot{\hfill\info@line}%
      \let\@evenfoot\@oddfoot%
      \def\@evenhead{\runninghead@size\rlap{\pagenumber@size\thepage}\hfill\leftmark\hfill}%
      \def\@oddhead{\runninghead@size\hfill\rightmark\hfill\llap{\pagenumber@size\thepage}}}
\else
\def\ps@imsheadings{%
      \def\@oddfoot{\hfill\info@line}%
      \let\@evenfoot\@oddfoot%
      \def\@evenhead{\runninghead@size\hfill\leftmark/\rightmark\hfill\llap{\pagenumber@size\thepage}}%
      \def\@oddhead{\runninghead@size\hfill\leftmark/\rightmark\hfill\llap{\pagenumber@size\thepage}}}
\fi

\def\ps@copyright{\let\@mkboth\@gobbletwo%
  \def\@evenhead{\parbox[t]{\textwidth}{\copyright@size\copyright@text}}%
  \let\@oddhead\@evenhead%
  \def\@oddfoot{\hfill\pagenumber@size\thepage\hfill\llap{\info@line}}%
  \let\@evenfoot\@oddfoot}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% url@fmt


\def\journalurl#1{\def\journal@url{#1}}
\def\paperurl#1{\def\paper@url{#1}}

\def\doi#1{%
  \gdef\@doi{#1}%
  \gdef\doi@text{\url@fmt{DOI: }{\ttfamily}{#1}{\doi@base\@doi}}%
}

\def\@doi{}

\def\doi@base{http://dx.doi.org/}

% {url}{text}
\def\ims@href#1#2{#2}

% {prefix}{font}{text}{url}

\def\url@fmt#1#2#3#4{%
   \edef\@tempa{#3}%
   \ifx\@tempa\@empty%
   \else%
     #1{#2\ims@href{#4}{#3}}%
   \fi}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LIST ENVIRONMENTS

\parsep\z@
\topsep\smallskipamount
\partopsep\z@
\itemsep\z@
\labelsep.5em

\def\@listI{\leftmargin\leftmargini
            \parsep\z@
            \topsep\smallskipamount
            \itemsep\z@}

\def\list@parindent{1pc}

% quotation
\let\quotation@size\footnotesize
\def\quotation@itemindent{\list@parindent}
\def\quotation@parindent{\list@parindent}
\def\quotation@leftmargin{\list@parindent}
\let\quotation@rightmargin\z@
\let\quotation@topsep\smallskipamount

\def\quotation{%
        \list{}{\quotation@size%
        \listparindent\quotation@parindent%
        \itemindent   \quotation@itemindent%
        \rightmargin\quotation@rightmargin   \leftmargin\quotation@leftmargin%
        \partopsep\z@ \topsep\quotation@topsep \parsep\z@%
                        }%
        \item[\Q@strut]\relax}

\def\endquotation{\endlist}

\def\Q@strut{\leavevmode\hbox{\vrule height9pt depth1pt width0pt}}

% quote
\let\quote@size\footnotesize
\def\quote@indent{\z@}
\def\quote@leftmargin{2pc}
\def\quote@rightmargin{2pc}
\let\quote@topsep\smallskipamount

\def\quote{%
        \list{}{\quote@size%
        \listparindent\quote@indent%
        \itemindent \listparindent%
        \rightmargin\quote@rightmargin   \leftmargin\quote@leftmargin%
        \partopsep\z@ \topsep\quote@topsep \parsep\z@%
                       }%
        \item\relax}

\def\endquote{\endlist}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% table, figure

\def\fnum@table{\tablename~\thetable}
\setlength\belowcaptionskip{4\p@}

\renewenvironment{table}
               {\let\@makecaption\@maketablecaption\@float{table}}
               {\end@float}
\renewenvironment{table*}
               {\let\@makecaption\@maketablecaption\@dblfloat{table}}
               {\end@dblfloat}

\long\def\@maketablecaption#1#2{%
      \centering\footnotesize\scshape
      \textsc{#1}\endgraf
      \itshape #2\par
  \vskip\belowcaptionskip}

% figure : use \@makecaption:
\renewcommand\figurename{Fig}

\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \footnotesize
  \sbox\@tempboxa{\itshape\textsc{#1}. #2}%
  \ifdim \wd\@tempboxa >\hsize
    \itshape\textsc{#1}. #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}


%
\def\@floatboxreset{%
        \reset@font
        \@setminipage
        \singlespacing
        \footnotesize
        \centering
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FOOTNOTE

\renewcommand\@makefntext[1]{%
    \parindent12pt\@makefnmark #1}

\def\@makefnmark{\@textsuperscript{\normalfont\@thefnmark}}%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION commands:
% from latex.ltx:
% Two improvements:
% 1. if section command is defined as "inline" the '.' will be inserted after heading;
% 2. section* will write to toc and will appear in pdf bookmarks

% dirty trick...
\def\@startsection#1#2#3#4#5#6{%
  \if@noskipsec \leavevmode \fi
  \par
  \@tempskipa #4\relax
  \@afterindenttrue
  \ifdim \@tempskipa <\z@
    \@tempskipa -\@tempskipa \@afterindentfalse
  \fi
  \if@nobreak
    \everypar{}%
  \else
    \addpenalty\@secpenalty\addvspace\@tempskipa
  \fi
  \@ifstar
    {\def\ssection@level{#2}\@ssect{#3}{#4}{#5}{#6}}%
    {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}

% Trick for the hyperref:
\def\setaftersec@dot#1{\if@autosecdot\setbox0=\hbox{#1}\ifdim\wd0>0\p@\def\aftersec@dot{.}\else\def\aftersec@dot{}\fi\fi}
\let\aftersec@dot\relax

% section - will add hook for the dot after section heading
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \ifdim \@tempskipa>\z@
    \begingroup
      #6{%
        \@hangfrom{\hskip #3\relax\@svsec}%
          \interlinepenalty \@M #8\@@par}%
    \endgroup
    \csname #1mark\endcsname{#7}%
    \addcontentsline{toc}{#1}{%
      \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      #7}%
  \else
    \setaftersec@dot{#8}%
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8\aftersec@dot}%
      \csname #1mark\endcsname{#7}%
      \addcontentsline{toc}{#1}{%
        \ifnum #2>\c@secnumdepth \else
          \protect\numberline{\csname the#1\endcsname}%
        \fi
        #7}}%
  \fi
  \@xsect{#5}}

% section* - will add hook for the dot after section heading and \contentsline 
\def\@ssect#1#2#3#4#5{%
  \@tempskipa #3\relax
  \ifdim \@tempskipa>\z@
    \begingroup
      #4{%
        \@hangfrom{\hskip #1}%
          \interlinepenalty \@M #5\@@par}%
    \endgroup
  \else
    \setaftersec@dot{#5}%
    \def\@svsechd{#4{\hskip #1\relax #5\aftersec@dot}}%
  \fi
  \ifnum\ssection@level=1\phantomsection\addcontentsline{toc}{section}{#5}\fi%
  \@xsect{#3}}

% Block adding to contents for the next command only:
\def\nocontentsline{%
  \let\@@addcontentsline\addcontentsline%
  \def\addcontentsline##1##2##3{\let\addcontentsline\@@addcontentsline}}

% \phantomsection is defined in hyperref
\let\phantomsection\relax

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FRONTMATTER 
% FRONT MATTER FORMATTING PARAMETERS

\setattribute{frontmatter} {style} {\centering}
\setattribute{address}     {style} {}
\setattribute{abstract}    {style} {\normaltext}
\setattribute{keyword}     {style} {\normaltext}
\setattribute{history}     {style} {\normaltext}

% FRONT MATTER SKIPS
\setattribute{title}       {skip} {18\p@}
\setattribute{authors}     {skip} {12pt}
\setattribute{dedicated}   {skip} {12\p@}
\setattribute{address}     {skip} {6\p@ plus 1\p@ minus 1\p@}
\setattribute{affiliation} {skip} {6\p@ plus 1\p@ minus 1\p@}
\setattribute{abstract}    {skip} {10\p@}
\setattribute{keyword}     {skip} {10\p@}
\setattribute{history}     {skip} {10\p@}
\setattribute{frontmatter} {cmd}  {\vskip20\p@ plus 3\p@ minus 3\p@
                                   \@afterindentfalse\@afterheading}

% FRONT MATTER DIMENSIONS
\setattribute{abstract}   {width} {.8\textwidth}
\setattribute{abstract}  {indent} {0\p@} 
\setattribute{keyword}    {width} {.8\textwidth}
\setattribute{keyword}   {indent} {0\p@} %
\setattribute{history}    {width} {.8\textwidth}

% FRONT MATTER FONTS 
\setattribute{dochead}    {size} {\Large\bfseries}
\setattribute{title}      {size} {\LARGE\bfseries}
\setattribute{author}     {size} {\normalsize\bfseries}
\setattribute{address}    {size} {\footnotesize\itshape\mdseries}
\setattribute{affiliation}{size} {\footnotesize\itshape\mdseries}
\setattribute{dedicated}  {size} {\normalsize\itshape}
\setattribute{ead}        {size} {\upshape\ttfamily}
\setattribute{abstract}   {size} {\footnotesize\upshape\mdseries}
\setattribute{abstractname}{size} {\bfseries}
\setattribute{keyword}    {size} {\footnotesize\upshape\mdseries}
\setattribute{keywordname}{size} {\bfseries}
\setattribute{history}    {size} {\footnotesize\mdseries}
\setattribute{copyright}  {size} {\footnotesize\raggedright}
\setattribute{runninghead}{size} {\footnotesize\itshape}
\setattribute{pagenumber} {size} {\footnotesize\upshape}
\setattribute{thebibliography}{size}{\normalsize}

% FRONT MATTER CASE
\setattribute{dochead}    {case} {}
\setattribute{title}      {case} {}
\setattribute{runninghead}{case} {}

% TEXT, etc.
\setattribute{volume}     {text} {Vol.}
\setattribute{doi}        {text} {\url@fmt{url: }{\ttfamily}{\paper@url}{\paper@url}}
\setattribute{copyright}  {text} {\url@fmt{}{\bfseries}{\@journal}{\journal@url}\leavevmode\hbox{}\\
                                  \@volume\@pubyear\@pagerange\leavevmode\hbox{}\\
                                  \journal@issn%
                                  \doi@text}
\setattribute{infoline}   {text} {\lower12pt \hbox{\footnotesize\ttfamily\imsfmt@name\journal@id\ ver. \imsfmt@version\ file: \jobname.tex\ date: \today}}
\setattribute{copyright} {owner} {$\copyright$~\@copyrightyear \@copyrightowner}
\setattribute{author}   {prefix} {}
\setattribute{keyword} {postfix} {\unskip.}

\def\abstractname{Abstract:\ }

% HISTORY
\setattribute{history}  {prefix}  {}
\setattribute{history}  {postfix} {.}
\setattribute{received} {prefix}  {Received~}
\setattribute{received} {postfix} {}
\setattribute{revised}  {prefix}  {; revised~}
\setattribute{revised}  {postfix} {}
\setattribute{accepted} {prefix}  {; accepted~}
\setattribute{accepted} {postfix} {}

% COUNTERS, ETC
\newcounter{author}
\newcounter{address}
\newdimen\sv@mathsurround
%
% RUNNING HEAD
\def\runtitle#1{\gdef\@runtitle{\runninghead@case{#1}}}                      \def\@runtitle{}
\def\runauthor#1{{\def\etal{et al.}\gdef\@runauthor{\runninghead@case{#1}}}} \def\@runauthor{}

\newdimen\sv@parindent
\sv@parindent\parindent

\newbox\fm@box
\newdimen\fm@size
%
\let\hy@frontmatter\relax
\let\hy@endfrontmatter\relax

\def\frontmatter{%
  \global\c@author\z@
  \global\c@address\z@
  \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
  \sv@mathsurround\mathsurround \m@th
  \parindent\z@
  \hy@frontmatter
  \open@fm \ignorespaces}
%
%
% ENDFRONTMATTER
%
\def\endfrontmatter{%
  \global\@topnum\z@
  \set@pagerange
  \markboth{\@runauthor}{\@runtitle}%
  \thispagestyle{copyright}%
%
  \put@fmt@data%
%
  \close@fm
  \write@pdfinfo{\hy@author}{\the\authors@list}
  \write@pdfinfo{\hy@keywords}{\the\keywords@list}
  \hy@endfrontmatter
  \global\mathsurround\sv@mathsurround
  \global\c@footnote\z@
  \global\let\@thanks\@empty  
  \let\title\relax       
  \let\author\relax
  \let\address\relax
  \let\frontmatter\relax \let\endfrontmatter\relax
  \let\@maketitle\relax  \let\@@maketitle\relax
  \aftergroup\frontmatter@cmd
  }
%

\def\put@fmt@data{%
  \copyright@fmt%
  \@thanks%
  \abstract@fmt%
  \keyword@fmt%
  \history@fmt}


%
\let\maketitle\relax
%
\newdimen\t@xtheight
\def\init@settings{
\splittopskip=\topskip \splitmaxdepth=\maxdepth
\t@xtheight\textheight \advance\t@xtheight-\splittopskip}

\def\no@harm{\let\thanks=\@gobble\let\thanksref=\@gobble\let~\space\def\ead[##1]##2{}\let\\=\@empty \def\protect{\noexpand\protect\noexpand}}

\def\open@fm{%
  \global\setbox\fm@box=\vbox\bgroup
  \hsize=\textwidth
  \frontmatter@style}
%
\def\close@fm{%
  \par \egroup
  \fm@size=\dp\fm@box \advance\fm@size by \ht\fm@box
  \@whiledim\fm@size>\t@xtheight \do{%
    \global\setbox\@tempboxa=\vsplit\fm@box to \t@xtheight
    \unvbox\@tempboxa %\newpage
    \fm@size=\dp\fm@box \advance\fm@size by \ht\fm@box}
  \if@twocolumn
    \emergencystretch=1pc \twocolumn[\unvbox\fm@box]
  \else
    \unvbox\fm@box
  \fi}
%
%
% DOCHEAD
\def\dochead#1{%
  \bgroup
    \dochead@size
    \leavevmode\vphantom{\strut}\dochead@case{#1}\par
  \egroup
  \setattribute{title}{skip}{8\p@}}

% TITLE
%
\def\title#1{%
  \vglue\title@skip%
  \bgroup%
    \no@harm%
    \let\protect\relax%
    \xdef\@argi{#1}%
  \egroup%
  \write@pdfinfo{\hy@title}{\@argi}
  \bgroup%
    \title@size\title@case{#1}\par%
  \egroup}

%
% AUG - author block
\def\smart@par{\ifhmode\par\fi}
\newenvironment{aug}{}{\smart@par}

% AUTHOR
%
\def\and{\unskip~and~}

\def\author{\@ifnextchar[{\author@fmt}{\author@fmt[]}}
%
\def\author@fmt[#1]#2{%
  \stepcounter{author}%
  \author@fmt@init%
  \let\author@fmt@init\relax
  \bgroup% 
     \def\degs##1{##1}\def\fnms##1{##1}\def\inits##1{##1}\def\snm##1{##1}\def\roles##1{##1}%
     \ifnum\c@author=1\addto@authors@list{#2}\else\addto@authors@list{, #2}\fi%
     #2\thanksref{#1}%
  \egroup}
%
\def\author@fmt@init{%
   \vskip\authors@skip%
   \leavevmode\author@size\author@prefix}
%
\let\author@fmt@init@def\author@fmt@init

% DEDICATED
\def\dedicated#1{%
  \vskip\dedicated@skip
  \bgroup
    \dedicated@size #1\par
  \egroup}

% ADDRESS
\def\address{\@ifnextchar[{\address@fmt}{\address@fmt[]}}

\def\address@fmt[#1]#2{%
  \smart@par%
  \let\author@fmt@init\author@fmt@init@def
  \vskip\address@skip%
  {\address@style\address@size\leavevmode\ifx.#1.\else\usethankscounter{addressref}\thanksmark{#1}\restorethankscounter\fi#2\par}}

% AFFILIATION
\def\affiliation#1{%
  \smart@par%
  \let\author@fmt@init\author@fmt@init@def
  \vskip\affiliation@skip
  \bgroup
    \affiliation@size #1\par
  \egroup}


% COPYRIGHTOWNER

\def\copyright@fmt{%
  \@ifundefined{@copyrightowner}{}{%
  \bgroup%
    \def\thempfn{}%
    \footnotetext{\copyright@owner}%
  \egroup}}

% ABSTRACT

\newbox\abstract@box

\def\abstract{%
     \global\setbox\abstract@box=\vbox\bgroup%
     \@tempdima\textwidth%
     \advance\@tempdima by-\abstract@width%
     \divide\@tempdima by2%
     \abstract@style%
     \leftskip\@tempdima\rightskip\@tempdima%
     \abstract@size%
     \parindent\sv@parindent%
     \noindent\hskip\abstract@indent{\abstractname@size\abstractname}\ignorespaces}
\def\endabstract{\par\egroup}

\def\abstract@fmt{%
  \ifvoid\abstract@box\else
    \vskip\abstract@skip%
    \unvbox\abstract@box
  \fi}


% HISTORY: received, revised, accepted

\def\history@exist{0}

\def\received#1{\def\@tempa{#1}\ifx\@tempa\@empty\else\gdef\@received{#1}\gdef\history@exist{1}\fi}
  \def\@received{\@nil}
\def\revised#1{\def\@tempa{#1}\ifx\@tempa\@empty\else\gdef\@revised{#1}\gdef\history@exist{1}\fi}
  \def\@revised{\@nil}
\def\accepted#1{\def\@tempa{#1}\ifx\@tempa\@empty\else\gdef\@accepted{#1}\gdef\history@exist{1}\fi}
  \def\@accepted{\@nil}

\def\empty@data{\@nil}

\def\history@fmt{%
  \ifcase\history@exist\else%
  \bgroup
    \nobreak%
    \vskip\history@skip%
    \nobreak%
    \history@style%
    \history@size%
    \@tempdima\textwidth%
    \advance\@tempdima by-\history@width%
    \divide\@tempdima by2%
    \leftskip\@tempdima
    \rightskip\@tempdima
    \leavevmode
    \history@prefix
    \ifx\@received\empty@data \else
      \received@prefix\@received \received@postfix%
    \fi
    \ifx\@revised\empty@data \else
      \revised@prefix\@revised \revised@postfix%
    \fi
    \ifx\@accepted\empty@data \else
      \accepted@prefix\@accepted \accepted@postfix%
    \fi
  \history@postfix\par%
  \egroup%
  \gdef\history@exist{0}
\fi
}

\def\sday#1{#1}
\def\smonth#1{\@ifundefined{month@item@#1}%
     {\@latex@error{Nera tokio menesio, kurio numeris #1!}{??}}%
     {\getitemvalue{month}{#1}}%
  }%
\def\syear#1{#1}
\setvaluelist{month}{January,February,March,April,May,June,July,August,September,October,November,December}

% KEYWORDS

\newbox\keyword@box
\newdimen\pre@kwd@depth

\setattribute{keyword}{AMS}{AMS 2000 subject classifications:}
\setattribute{keyword}{KWD}{Keywords and phrases:}
% raktas=class
\setattribute[default]{keyword}{class}{KWD}

%  \keyword@class-> KWD
%  \keyword@KWD  -> AMS 2000... 

\gdef\keyword{\@ifnextchar[{\@keyword}{\@keyword[class=KWD]}}

\gdef\@keyword[#1]{%
  \do@option@list{keyword}{#1}%
  \def\keyword@name{\csname keyword@\keyword@class\endcsname}%
  \let\kwd@sep\relax
%
  \global\setbox\keyword@box=\vbox\bgroup%
     \ifvoid\keyword@box\else%
        \unvbox\keyword@box
        \vskip-\pre@kwd@depth\vtop to\pre@kwd@depth{}%
     \fi
     \@tempdima\textwidth%
     \advance\@tempdima by-\keyword@width%
     \divide\@tempdima by2%
     \keyword@style%
     \leftskip\@tempdima\rightskip\@tempdima%
     \keyword@size%
     \parindent\sv@parindent%
     \noindent\hskip\keyword@indent{\keywordname@size\keyword@name}\space\hskip.1pt}

\def\endkeyword{\keyword@postfix\par\global\pre@kwd@depth\prevdepth\egroup}

\def\keyword@fmt{%
  \ifvoid\keyword@box\else
    \vskip\keyword@skip%
    \unvbox\keyword@box
  \fi}


% \kwd[; ]{foo}
  \def\sep{\unskip\string, }%

  \DeclareRobustCommand*\kwd{\@ifnextchar[\@kwd{\@kwd[\kwd@sep]}}%
  \def\@kwd[#1]#2{\unskip#1{#2}\addto@keywords@list{#2, }\let\kwd@sep\sep}%  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% process layout options

% Put keywords as footnote
\if@keywordsasfootnote

  \newtoks\keyword@toks

  \newpseudoenvironment{keyword}{\gdef\keyword@exist{1}\get@keyword@toks}{}

  \def\get@keyword@toks#1\end{\keyword@toks=\expandafter{\the\keyword@toks\keyword#1\endkeyword}\@gobble}

  \def\keyword@exist{0}
  
  \gdef\keyword#1{\@ifnextchar[{\@keyword}{\@keyword[class=KWD]}}

  \gdef\@keyword[#1]{%
    \do@option@list{keyword}{#1}%
    \def\keyword@name{\csname keyword@\keyword@class\endcsname}%
    \let\kwd@sep\relax%
    \keyword@style%
    \keyword@size%
    \parindent\sv@parindent%
    \pre@kwd%
    \hbox{\keywordname@size\keyword@name}\space\hskip.1pt}%

  \gdef\endkeyword{\gdef\pre@kwd{\par\leavevmode}}

  \let\pre@kwd\relax

  \def\keyword@fmt{\ifcase\keyword@exist\else\bgroup\def\thefootnote{}\footnotetext{\the\keyword@toks}\egroup\fi}

\fi

% Put history as footnote
\if@historyasfootnote

  \def\history@fmt{%
    \ifcase\history@exist\else%
    \bgroup
      \def\thefootnote{}\footnotetext
      \bgroup
        \nobreak%
        \history@style%
        \history@size%
        \leavevmode
        \history@prefix
        \ifx\@received\empty@data \else
          \received@prefix\@received \received@postfix%
        \fi
        \ifx\@revised\empty@data \else
          \revised@prefix\@revised \revised@postfix%
        \fi
        \ifx\@accepted\empty@data \else
          \accepted@prefix\@accepted \accepted@postfix%
        \fi
        \history@postfix\par%
      \egroup%
   \egroup
  \fi
  }

\fi

% Put address as footnote
\if@addressasfootnote
  \def\address@fmt[#1]#2{%
     \ifx.#1.%
       \bgroup
         \def\thefootnote{}\footnotetext{#2}
       \egroup
     \else%
       \usethankscounter{addressref}%
       \thankstext{#1}{#2}%
       \restorethankscounter%
     \fi%
                        }
\fi

% Put address at end
\if@addressatend
\def\address{\@ifnextchar[{\address@fmt}{\address@fmt[default]}}
%
% \def\address@ref@A=1
% \newtoks\@address@1
% \@address@1={#2}
%
\def\address@fmt[#1]#2{%
  \stepcounter{address}%
  \expandafter\protected@xdef\csname address@ref@#1\endcsname{\the\c@address}%
  \expandafter\newtoks\csname @address@\the\c@address\endcsname
  \expandafter\expandafter\expandafter\global\csname @address@\the\c@address\endcsname={#2}}

% print address by number: \printaddressnum{1}
\def\printaddressnum#1{%
\xdef\@tmp{#1}%
\bgroup
\@ifundefined{@address@#1}{\@latex@error{Klaida: nera adreso su numeriu '#1'!}{??}}{
  \address@size
  \begin{tabular}[t]{@{}l@{}}
  \expandafter\expandafter\expandafter\the\csname @address@\@tmp\endcsname
  \end{tabular}}
\egroup
}

% print all addresses:
\def\address@par{\par\vskip3pt}

\def\printaddresses{%
\vskip\address@skip%
%\addcontentsline{toc}{section}{Author's addresses}%
\def\last@right@glue{\par}%
\ifodd\c@address   \def\last@right@glue{\hfill\hbox{}\address@par} \fi%
\ifnum\c@address=1 \def\last@right@glue{\address@par}\fi%
\@tempcnta=0%
\bgroup\parindent\z@
\@whilenum{\@tempcnta<\c@address}%
  \do{%
    \advance\@tempcnta\@ne
    \ifodd\@tempcnta \def\left@glue{} \def\right@glue{} %     nelyginis
       \else \def\left@glue{\hfill} \def\right@glue{\address@par}\fi % lyginis
    \ifnum\@tempcnta=\c@address \let\left@glue\hfill \let\right@glue\last@right@glue\fi %paskutinis narys
    \left@glue\expandafter\printaddressnum{\the\@tempcnta}\right@glue%
     }
\egroup
}

% invoke \printaddresses at end of document:
\let\old@enddocument\enddocument
\def\enddocument{\printaddresses\old@enddocument}

\fi

% Set up parameters for the IMS journals layout:
\if@imslayout

  \setattribute{title}       {skip} {12\p@}
  \setattribute{frontmatter} {cmd}  {\vskip20\p@ plus 3\p@ minus 3\p@}

  \setattribute{abstract} {width}  {23pc}
  \setattribute{abstract} {indent} {16pt} %2em

  \setattribute{title}      {size} {\normalsize\bfseries\mathversion{bold}\spaceskip.5em}
  \setattribute{author}     {size} {\normalsize\scshape}
  \setattribute{affiliation}{size} {\normalsize\itshape}
  \setattribute{address}    {size} {\scriptsize\scshape}
  \setattribute{ead}        {size} {\upshape}
  \setattribute{abstractname}{size}{\itshape}
  \setattribute{keywordname}{size} {\itshape}
  \setattribute{runninghead}{size} {\footnotesize}
  \setattribute{pagenumber} {size} {\small}
  \setattribute{copyright}  {size} {\fontsize{6}{7}\selectfont\raggedright}
  \setattribute{thebibliography}{size}{\footnotesize}

  \setattribute{dochead}    {case} {\MakeUppercase}
  \setattribute{title}      {case} {\MakeUppercase}
  \setattribute{runninghead}{case} {\MakeUppercase}

  \setattribute{author}   {prefix} {By~}

  \setattribute{copyright}  {text} {\url@fmt{}{\itshape}{\@journal}{\journal@url}\\
                                    \@copyrightyear\@volume\@issue\@pagerange}

  \def\volume#1{\gdef\@volume{Vol. #1, }}
  \def\issue#1 {\gdef\@issue{No. #1, }}
  \def\pubyear#1{\gdef\@pubyear{#1,}\gdef\@copyrightyear{#1}}

  \def\abstractname{}

  \def\put@fmt@data{%
    \copyright@fmt%
    \history@fmt
    \@thanks%
    \keyword@fmt%
    \abstract@fmt%
    }



\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% interaction with hyperref

\def\test@hyperref{\@ifundefined{Hy@SetCatcodes}{}{\imsart@hyperref@settings}}

\AtBeginDocument{\test@hyperref}

\def\imsart@hyperref@settings{%
% from hyperref maketitle
  \def\hy@frontmatter{%
    \let\H@@origfootnotemark\@footnotemark
    \let\H@@origfootnotetext\@footnotetext
    \let\@footnotemark\H@@footnotemark
    \let\@footnotetext\H@@footnotetext}
  \def\hy@endfrontmatter{
    \ifx\@footnotemark\H@@footnotemark
      \let\@footnotemark\H@@origfootnotemark
    \fi
    \ifx\@footnotetext\H@@footnotetext
      \let\@footnotetext\H@@origfootnotetext
    \fi}
% hooks for the \thanksref, \thankstext:
  \def\thankref@hyperlink##1{%
     \edef\@tempx{##1thanks}%
     \hbox{\hyperlink{##1}{\saferef{\@tempx}}}}
  \def\thanks@hypertarget##1{\smash{\raise\baselineskip\hbox{\protect\hypertarget{##1}{}}}}
% redefine pagenumbering
  \let\pagenumbering\ims@pagenumbering
% activate href
   \let\ims@href\href%
% put document info
   \def\write@pdfinfo##1##2{\protected@write\@auxout{\no@harm}{\string\gdef\string##1{##2}}}
   \@ifundefined{hy@title}{}{\pdfstringdef\@pdftitle{\hy@title}}
   \@ifundefined{hy@author}{}{\pdfstringdef\@pdfauthor{\hy@author}}
   \@ifundefined{hy@keywords}{}{\pdfstringdef\@pdfkeywords{\hy@keywords}}
% MathSciNet:
   \def\MR##1{\href{http://www.ams.org/mathscinet-getitem?mr=##1}{MR##1}}
}

\def\write@pdfinfo#1#2{}

\newtoks\authors@list
\def\addto@authors@list#1{%
  \begingroup%
    \no@harm%
    \xdef\@act{\global\noexpand\authors@list{\the\authors@list#1}}\@act%
  \endgroup}

\newtoks\keywords@list
\def\addto@keywords@list#1{%
  \begingroup%
    \no@harm%
    \xdef\@act{\global\noexpand\keywords@list{\the\keywords@list#1}}\@act%
  \endgroup}

% MathSciNet:
\def\MR#1{MR#1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% section, subsection etc.
% we do not like article appearance:

\if@imslayout
  \renewcommand\section{\@startsection {section}{1}{\parindent}%
                                     {\medskipamount}%
                                     {-10pt}%
                                     {\normalsize\upshape\bfseries\mathversion{bold}}}

  \renewcommand\subsection{\@startsection {subsection}{2}{\parindent}%
                                     {\medskipamount}%
                                     {-10pt}%
                                     {\subsection@shape}}
  \def\subsection@shape{\normalsize\itshape}
  \def\subsection@prefix{\upshape}

  \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\parindent}%
                                       {\medskipamount}%
                                       {-10pt}%
                                       {\normalsize\itshape}}
  \def\subsubsection@prefix{\upshape}

  \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                      {\smallskipamount}%
                                      {-1em}%
                                      {\normalsize\itshape}}
  \renewcommand\subparagraph{\@startsection{subparagraph}{5}{\z@}%
                                         {0.1pt}%
                                         {-1em}%
                                         {\normalsize\itshape}}

% must be used for thea ppendix \section and \thebibliography
  \newcommand\specialsection{\@startsection {section}{1}{\z@}%
                                   {\medskipamount}%
                                   {\smallskipamount}%
                                   {\normalsize\centering\MakeUppercase}}

% appendix mess up everything in this layout:

  \renewcommand\appendix{\par
    \def\subsection@shape{\normalsize\upshape\bfseries\mathversion{bold}}
    \let\section\specialsection
    \def\section{\@ifnextchar*{\@appsectionstar}{\@appsectionnostar}}%
    \def\section@prefix{\appendixname\ }%
    \def\section@dot{:}%
    \setcounter{section}{0}%
    \setcounter{subsection}{0}%
    \gdef\thesection{\@Alph\c@section}}

% \section*{Appendix} -> APPENDIX
  \def\@appsectionstar*#1{%
     \specialsection*{#1}%
     \setcounter{section}{1}%
%     \addcontentsline{toc}{section}{#1}
}

% \section{}      -> APPENDIX A
% \section{proof} -> APPENDIX A: PROOF
  \def\@appsectionnostar#1{%
     \ifx.#1.% 
       \def\section@dot{}\specialsection[\appendixname\ \thesection]{}%
     \else%
       \def\section@dot{:}\specialsection{#1}%
     \fi}

%  dirty trick with \thebibliography
  \let\old@thebibliography\thebibliography
  \def\thebibliography{\let\section\specialsection\old@thebibliography}

\else

  \renewcommand\section{\@startsection {section}{1}{\z@}%
                                     {-\bigskipamount}%
                                     {\medskipamount}%
                                     {\raggedright\bfseries\mathversion{bold}}}

  \renewcommand\subsection{\@startsection {subsection}{2}{\z@}%
                                     {-\bigskipamount}%
                                     {\medskipamount}%
                                     {\raggedright\bfseries\itshape\mathversion{bold}}}

  \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-\bigskipamount}%
                                     {\medskipamount}%
                                     {\raggedright\itshape}}

  \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                     {\medskipamount}%
                                     {-1em}%
                                     {\bfseries}}

  \renewcommand\subparagraph{\@startsection{subparagraph}{5}{\z@}%
                                     {\medskipamount}%
                                     {-1em}%
                                     {\itshape}}

\fi

% Format for the counter:
  \def\section@numbersep{.}
  \def\subsection@numbersep{.}
  \def\subsubsection@numbersep{.}
  \def\paragraph@numbersep{.}
  \def\subparagraph@numbersep{.}

  \def\@seccntformat#1{{\csname #1@prefix\endcsname\csname the#1\endcsname\csname#1@numbersep\endcsname\enspace}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% loading of amsmath, amsthm
% Loading of amsmath
\if@load@amsmath
  \if@amsmath@leqno
     \PassOptionsToPackage{leqno}{amsmath}
  \fi
  \RequirePackage[cmex10]{amsmath}
\fi
% Loading of amsthm 

\if@load@amsthm
  \RequirePackage{amsthm}
  \if@imslayout

     \thm@notefont{\upshape}
     \newtheoremstyle{plain}     {\medskipamount}{\medskipamount}{\itshape}{\parindent}{\scshape}{.}{1em}{}
     \newtheoremstyle{definition}{\medskipamount}{\medskipamount}{\normalfont}{\parindent}{\scshape}{.}{1em}{}
     \newtheoremstyle{remark}    {\medskipamount}{\medskipamount}{\normalfont}{\parindent}{\scshape}{.}{1em}{}

     \renewenvironment{proof}[1][\proofname]{\par
       \pushQED{\qed}%
       \normalfont \topsep\medskipamount%
       \trivlist
       \labelsep.5em%
       \item[\hskip\labelsep\hskip\parindent
       \scshape #1\@addpunct{.}]\ignorespaces
     }{%
       \popQED\endtrivlist\@endpefalse
     }
    
  \fi
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% thebibliography, loading natbib

\if@load@natbib
   \RequirePackage[numbers,sort&compress]{natbib}
   \let\bibfont\thebibliography@size
   \setlength\bibsep{0pt}
\else 
  \let\xxx@thebibliography\thebibliography
  \def\thebibliography{\thebibliography@size\xxx@thebibliography}
  \g@addto@macro\@openbib@code{\itemsep\z@}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% appendix

\if@imslayout

% appendix mess up everything in this layout:

  \renewcommand\appendix{\par
    \def\subsection@shape{\normalsize\upshape\bfseries\mathversion{bold}}
    \let\section\specialsection
    \def\section{\@ifnextchar*{\@appsectionstar}{\@appsectionnostar}}%
    \def\section@prefix{\appendixname\ }%
    \def\section@numbersep{:}%
    \setcounter{section}{0}%
    \setcounter{subsection}{0}%
    \gdef\thesection{\@Alph\c@section}}

% \section*{Appendix} -> APPENDIX
  \def\@appsectionstar*#1{%
     \specialsection*{#1}%
     \setcounter{section}{1}%
%     \addcontentsline{toc}{section}{#1}
}

% \section{}      -> APPENDIX A
% \section{proof} -> APPENDIX A: PROOF
  \def\@appsectionnostar#1{%
     \ifx.#1.% 
       \def\section@numbersep{}\specialsection[\appendixname\ \thesection]{}%
     \else%
       \def\section@numbersep{:}\specialsection{#1}%
     \fi}

%  dirty trick with \thebibliography
  \let\old@thebibliography\thebibliography
  \def\thebibliography{\let\section\specialsection\old@thebibliography}


\else

  \renewcommand\appendix{\par
    \let\old@section\section%
    \def\section{\@ifnextchar*{\@appsectionstar}{\@appsectionnostar}}%
    \def\section@prefix{\appendixname\ }%
    \def\section@numbersep{:}%
    \setcounter{section}{0}%
    \setcounter{subsection}{0}%
    \gdef\thesection{\@Alph\c@section}}

  \def\@appsectionstar*#1{%
     \old@section*{#1}%
     \setcounter{section}{1}%
%     \addcontentsline{toc}{section}{#1}
}

  \def\@appsectionnostar#1{%
     \ifx.#1.% 
       \def\section@numbersep{}\old@section[\appendixname\ \thesection]{}%
     \else%
       \def\section@numbersep{:}\old@section{#1}%
     \fi}


\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% number lines

\ifnumberlines@

   \long\def\l@addto@macro#1#2{%
       \toks@\expandafter{#1#2}%
       \edef#1{\the\toks@}}

   \setattribute{numberlines}{size}{\scriptsize\ttfamily}
   \setattribute{numberlines}{skip}{24\p@}

   \def\numberlines@hook{%
       \l@addto@macro\@evenhead\put@numberlines@box%
       \l@addto@macro\@oddhead\put@numberlines@box}

   \g@addto@macro\ps@imsheadings\numberlines@hook
   \g@addto@macro\ps@copyright\numberlines@hook

   \newbox\numberlines@box
   \newskip\numberlines@box@skip

   \def\set@numberlines@box{%
     \setlength\numberlines@box@skip\headsep
     \addtolength\numberlines@box@skip{5\p@}
   %
     \setbox\numberlines@box\vtop to\textheight{%
       \parindent\z@    
       \vskip\z@   
       \@tempcnta=0
       \@tempdima=\z@
       \loop
         \advance\@tempcnta by1
         \advance\@tempdima by\baselineskip
         \hbox to\textwidth{%
            \llap{\numberlines@size\the\@tempcnta\kern\numberlines@skip}
            \hfill
            \rlap{\numberlines@size\kern\numberlines@skip\the\@tempcnta}}
       \ifdim\@tempdima<\textheight\repeat
       \vss
     }%
   %
       \ht\numberlines@box\z@
       \dp\numberlines@box\z@
   }

   \def\put@numberlines@box{\lower\numberlines@box@skip\hbox to\z@{\hss\copy\numberlines@box}}

   \AtBeginDocument{\set@numberlines@box}

\fi



%**************** INICIALIZATION

% Read local configuration file (if exist):
% imsart.cnf imsart-ps.cnf imsart-lnms.cnf

\@input{\imsfmt@name\journal@id.cnf}


\@twosidetrue
\pagenumbering{arabic}
\frenchspacing
\init@settings
\pagestyle{imsheadings}

\endinput
%%
%% History:

2005.05.19 New options singlespacing, doublespacing, linenumbers, nolinenumbers introduced;
           Table and figure captions changed

%% End of file `imsart.sty'.
