\ProvidesPackage{ametsoc}
% AMS Latex Style File Version 3.2
% 
% LaTeX style file for American Meteorological Society publications
% (not including BAMS).
%%
% Developed by Brian Papa - American Meteorological Society
%
% Based on the initial style file from Lakshmanan, 
% National Severe Storms Laboratory with modifications to follow 
% all AMS formatting style.
%
% Questions/feedback should be addressed to latex@ametsoc.org
%
% 12/29/06
% Added top documentation block and adjusted indentation for
% subsubsections and subsubsubsections (paragraph) to 4mm to follow
% AMS style. Set version number to 1.0 for initial release in Jan
% 2007.
%
% April 2007
% -Switched from the epsfig to the graphicx package
% -Switched from obsolete times package to mathptmx package for times
% fonts in text and math.
% -Added amsmath, fonts, symbols, and boldface packages
% -Rewrote code for appendices to allow for unlimited appendices using
% a single appendix command with an optional 1 letter argument.
% -Redid the page layout using the geometry package
% -Removed extraneous blank spaces to avoid unpredictable formatting
%
% July 2007
% -Set Reference and Abstract headings to all caps.
% -Added use of the setspace package
% -Updated to new doublespacing method
%
% August 2007
% -Updated amspaper.tex with new instructions, added references template information.
%
% 9/12/2007
% -Removed use of \doublespace and replaced with baselinstretch and removed setspace package
% so captions and text would be double spaced
% -Added dvips option to geometry to guarantee page layout info is passed to the dvi file
%
% August 12, 2008 -- Sarah Cooley, AMS
% - Shortened endfloat commands 
% - Moved \setcounter command here from .tex
% - Removed legacy appendix code for app's A-E
%	- Made captions in list of figures/tables double spaced, cap's under figs/tables single sp.
%	- Removed dotted line from list of figures/tables
%
% August, 2008 -- Brian Papa, AMS
% - Cretaed separate style file for single space double column draft for author use
% - Added doublespacing boolean 
% - Created header for first page to indicate use of Official AMS LaTeX template
% - Corrected usepackage commands to Requirepackage
%
% Februray, 2011 -- Brian Papa, AMS
% - Updated for use with EM.
%
% March, 2011 -- Brian Papa, AMS
% -Added use of the lineno package
%
% June, 2011 -- Brian Papa, AMS
% -Reordered calls to lineno and amsmath so lineno was after amsmath due to conflicts between
% the two packages.
%
% July, 2012 - J. Creilson
% - Added line numbering fix when using {equation} and other amsmath environments
%
\RequirePackage{graphicx}
%
% Seup the page layout using the geometry package
\RequirePackage[dvips,letterpaper,textwidth=16.5cm,textheight=22.9cm]{geometry}
%
% ametsoc.bst is built on top of natbib
\RequirePackage{natbib}

% Use times font in URLs
\RequirePackage{url}

% Define a light gray color for use in the title page header
\RequirePackage{color}
\definecolor{lightgray}{gray}{0.75}
\RequirePackage{fancyhdr}

% Provide the amsmath, fonts, symbol, and boldface math packages for use
\RequirePackage{amsmath,amsfonts,amssymb,bm}

% Line numbers needed
\RequirePackage{lineno}

%Use the indent first package to ensure the first paragraph after each
%section is indented.
\RequirePackage{indentfirst}

%If then options
\RequirePackage{ifthen} 
\newboolean{dc}
\setboolean{dc}{false}

%Ensure both text and captions are double spaced following AMS requirements
\ifthenelse{\boolean{dc}}
{}
{\renewcommand{\baselinestretch}{1.66}}

\renewcommand{\labelenumi}{\roman{enumi}.}
% All the figures and tables should be at the end on their own pages
\RequirePackage[nomarkers, tablesfirst]{endfloat}%
\AtBeginDelayedFloats{\clearpage}
%\renewcommand{\processdelayedfloats}{{%  Change of the original endfloat
%   \let\figure\@bfig
%   \let\table\@btab
%   \processdelayedfloats@hook
%   \if@tablesfirst \processtables\processfigures
%   \else \processfigures\processtables \fi
%   \processotherdelayedfloats}}
%Page numbers.
\pagestyle{plain}

\setcounter{secnumdepth}{4}
% Article's default is to provide arabic numerals for everything.
% Change the formatting of section and lower to follow AMS style.
\renewcommand{\@seccntformat}[1]{{\csname the#1\endcsname}.~~}%1

%section definitions
\renewcommand{\section}{%
\renewcommand{\@seccntformat}[1]{{\csname the##1\endcsname}.~~}%1
\@startsection
{section}%
{1}% 1 is the level for subsection
{0mm}% NO indent, starts immediately
{-\baselineskip}% skips 1 baseline after end of previous subsection
{0.5\baselineskip}% half baseline and the first paragraph starts
{\Large\bf}%the style, Large and boldface
}
\renewcommand{\thesection}{\arabic{section}} % numbers

% subsection definitions
\renewcommand{\subsection}{%
\renewcommand{\@seccntformat}[1]{{\csname the##1\endcsname}.~~}%1
\@startsection
{subsection}%
{2}% 2 is the level for subsection
{0mm}% NO indent, starts immediately
{-\baselineskip}% skips 1 baseline after end of previous subsection
{0.5\baselineskip}% half baseline and the first paragraph starts
{\normalfont\normalsize\itshape}%the style, all italics
}
\renewcommand{\thesubsection}{\alph{subsection}} % letters

% subsubsection definitions
\renewcommand{\subsubsection}{%
\renewcommand{\@seccntformat}[1]{{\csname the##1\endcsname})~~}%1
\@startsection
{subsubsection}%
{3}% 3 is the level for subsubsection
{5mm}% Indent subsubsections
{-\baselineskip}% skips 1 baseline after end of previous subsubsection
{0.5\baselineskip}% half baseline and the first paragraph starts
{\normalfont\normalsize\sc}%
}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}

% paragraph (subsubsubsection) definitions
\renewcommand{\paragraph}{%
\renewcommand{\@seccntformat}[1]{({\csname the##1\endcsname})~~}%1
\@startsection
{paragraph}%
{4}% 4 is the level for subsubsubsection (paragraph)
{5mm}% indent paragraph/subsubsubsections the same as subsubsections
{-\baselineskip}% skips 1 baseline after end of previous subsubsection
{0.5\baselineskip}% half baseline and the first paragraph starts
{\normalfont\normalsize\itshape}%
}
\renewcommand{\theparagraph}{\roman{paragraph}}

% Acknowledgments is defined as an unnumbered section.
\newenvironment{acknowledgment}
{\subsubsection*{\textit{Acknowledgments.}}}
{}

\renewenvironment{appendix}[1][1]%
{\ifthenelse{\equal{#1}{1}}%
{\renewcommand\theequation{A\arabic{equation}}%
\setcounter{equation}{0}% reset counter
\setcounter{subsection}{0}% reset counter
\begin{center}%
\section*{\textnormal{APPENDIX}}%
\end{center}}%
{\renewcommand\theequation{{#1}\arabic{equation}}%
\setcounter{equation}{0}% reset counter
\setcounter{subsection}{0}% reset counter
\begin{center}%
\section*{\textnormal{APPENDIX {#1}}}%
\end{center}}}%

%
% Remove colon in \caption, AMS style is to have a period after the
% figure number
\long\def\@makecaption#1#2{%
% Create the proper style for the figure and table captions.
\renewcommand{\figurename}{\textsc{Fig.}}
\renewcommand{\tablename}{\textsc{Table}}
\renewcommand{\thefigure}{\arabic{figure}.}
\renewcommand{\thetable}{\arabic{table}.}
\vskip\abovecaptionskip
\sbox\@tempboxa{#1~~#2}%
\ifdim \wd\@tempboxa >\hsize
#1~~#2\par%
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
%
\renewcommand{\abstractname}{\uppercase{Abstract}}%
%
\renewenvironment{abstract}{
\normalfont% Used under normal template conditions
\begin{center}%
{\abstractname\vspace{-.5em}\vspace{\z@}}%
\end{center}
}

% Define the amstitle
\newcommand{\amstitle}{
   \date{}% No date
   \maketitle%Make the title
   \thispagestyle{fancy}% title page doesn't have page number
   \lhead{\textcolor{lightgray}{\footnotesize{Generated using version 3.2 of the official AMS \LaTeX\ template}}}
   \newpage%Title page is separate from rest of article
   \pagenumbering{arabic}%Start pagination from this point
   \newpage%Title page is separate from rest of article
}
%
%Citations should be of the form ``author year''  not ``author, year''
\bibpunct{(}{)}{;}{a}{}{,}
%
% Adjust the spacing for two column papers
\ifthenelse{\boolean{dc}}
{\setlength{\columnsep}{.25in}}
{}
% Center the References section title
\renewcommand{\refname}{\begin{center}\uppercase{References}\end{center}}

%Change the way the list of figures and tables operates
\renewcommand\listoffigures{
    \section*{\listfigurename}%
    \renewcommand{\baselinestretch}{1.66}
    \small\normalsize
    \@starttoc{lof}%
}
%
\renewcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\renewcommand{\@dotsep}{1000}

\renewcommand\listoftables{
    \section*{\listtablename}%
    \renewcommand{\baselinestretch}{1.66}
    \small\normalsize
    \@starttoc{lot} \renewcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\renewcommand{\@dotsep}{1000}
}
% The following section defines a new command that helps to resolve the issue of missing line numbers preceding some 
% equations when using various math display environments
%
\newcommand*\patchAmsMathEnvironmentForLineno[1]{%
  \expandafter\let\csname old#1\expandafter\endcsname\csname #1\endcsname
  \expandafter\let\csname oldend#1\expandafter\endcsname\csname end#1\endcsname
  \renewenvironment{#1}%
     {\linenomath\csname old#1\endcsname}%
     {\csname oldend#1\endcsname\endlinenomath}}% 
\newcommand*\patchBothAmsMathEnvironmentsForLineno[1]{%
  \patchAmsMathEnvironmentForLineno{#1}%
  \patchAmsMathEnvironmentForLineno{#1*}}%
\AtBeginDocument{%
\patchBothAmsMathEnvironmentsForLineno{equation}%
\patchBothAmsMathEnvironmentsForLineno{align}%
\patchBothAmsMathEnvironmentsForLineno{flalign}%
\patchBothAmsMathEnvironmentsForLineno{alignat}%
\patchBothAmsMathEnvironmentsForLineno{gather}%
\patchBothAmsMathEnvironmentsForLineno{multline}%
\patchBothAmsMathEnvironmentsForLineno{eqnarray}%
}