%%
%% This is file `jeea.cls'.
%%
%% 2011/06/07, version 1.0
%%
%% LaTeX2e document class for articles for the
%%     Journal of the European Economic Association
%%
%% Documentation:  jeeadoc.pdf
%%
%% Credits:
%%  - Doris Escobar, JEEA Production Office
%%  - Alistairs Smith, Sunrise Setting Ltd
%%  - Timothy Van Zandt, INSEAD and JEEA Associate Editor
%%
%% Support:  jeea.production@insead.edu
%%
%% This file is derived from article.cls of the LaTeX base system.
%%
%% --------------------------------------------------------------
%%
%% Copyright 2011, European Economic Association
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% Short summary: This file may be distributed and modified freely,
%% but a modified version that is distributed:
%%  (a) should not have the same file name jeea.cls;
%%  (b) should mention its relationship to the original.
%%
%% -------------------------------------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 1. PRELIMINARIES 

\newcommand{\jeeaversion}{1.0}
\newcommand{\jeeadate}{2011/06/07}
\newcommand{\jeeaname}{Journal of the European Economic Association}
\newcommand{\jeeaupdate}{\jeeadate\space v\jeeaversion}

% Not sure of exact requirements but this is probably safe:
\NeedsTeXFormat{LaTeX2e}[2005/12/01]

\ProvidesClass{jeea}[\jeeaupdate.]
\typeout{JEEA Document class.}
		
\DeclareRobustCommand{\JEEA@Warning}[1]{%
	\begingroup
		\def\MessageBreak{^^J(jeea)\@spaces}%
	\set@display@protect
	\immediate\write\@unused{^^JJEEA Class Warning \on@line:\MessageBreak #1}%
	\endgroup}

\def\JEEA@Error#1{%
	\GenericError
		{(jeea)\@spaces\@spaces}
		{JEEA Class Error: #1}
		{See the JEEA Class documentation for explanation.}
		{\@ehc}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 2. OPTIONS AND DEFAULTS

% We use a key=value system, based on
% xkeyval.sty, v2.6a (2008/08/13)

\RequirePackage{xkeyval}

% These keys should only be used as class options.
% We suppress the family. The leading @ in the prefix will distinguish the xkeyval
% commands from others. For example, \@jeea@textwidth is the xkeyval command
% for setting the textwidth; it saves the value in \jeea@textwidth.

% \JEEA@OptionA is for "abbreviated" options that should take no value.

\def\JEEA@Option{\define@key[@jeea]{}}
\def\JEEA@OptionA#1#2{\define@key[@jeea]{}{#1}[]{#2}}
\def\JEEA@BoolOption#1#2{\define@boolkey[@jeea]{}{#1}[true]{#2}}


%% 2.1. Paper Sizes
%
% We define all the standard article.cls paper sizes, but only support those
% that make sense for articles. We save but don't use the dimensions yet,
% because we don't want to use true dimen before the \mag has been set.

%  - If the default jeea paper size is used, then the TeX dimension stays constant,
%    and so the true paper size gets larger as \mag gets larger.
%
%  - If instead the letterpaper or a4paper size is used, then the true paper size stays constant,
%    and the TeX dimension gets smaller as \mag gets larger.

% For backward compatibility, we define the paper sizes as both stand-alone options
% and as key=val pairs.

\JEEA@OptionA{jeeapaper}{%
	\def\thepaperheight {246mm}%
	\def\thepaperwidth  {171mm}}
	
\JEEA@OptionA{a4paper}{%
	\def\thepaperheight {297truemm}%
	\def\thepaperwidth  {210truemm}}

\JEEA@OptionA{letterpaper}{%
	\def\thepaperheight {11truein}%
	\def\thepaperwidth  {8.5truein}}

\JEEA@OptionA{executivepaper}{%  Defined but not documented
	\def\thepaperheight {10.5truein}%
	\def\thepaperwidth  {7.25truein}}

% Remember that, e.g., \@jeea@a4paper sets size to a4.

\define@choicekey*[@jeea]{}{paper}[\val]
	{jeea,a4,letter,executive}
	{\@nameuse{@jeea@\val paper}{}}

% For backward compatibility:

\JEEA@OptionA{legalpaper}
	{\JEEA@Warning{Option "legalpaper" not supported.}}
\JEEA@OptionA{a5paper}
	{\JEEA@Warning{Option "a5paper" not supported.}}
\JEEA@OptionA{b5paper}
	{\JEEA@Warning{Option "b5paper" not supported.}}
\JEEA@OptionA{landscape}
	{\JEEA@Warning{Option "landscape" not supported.}}

% Allow user to micromanage paperwidth and height

\JEEA@Option{paperwidth}{\def\thepaperwidth{#1}}
\JEEA@Option{paperheight}{\def\thepaperheight{#1}}


%% 2.2.  Height and width of the column

\JEEA@Option{textwidth}{\def\jeea@textwidth{#1}}
\JEEA@BoolOption{wider}{}

\JEEA@Option{textheight}{\def\jeea@textheight{#1}}
\JEEA@BoolOption{fullheight}{}

\define@choicekey*+[@jeea]{}{topmargin}
	{auto}
	{\def\jeea@topmargin{}}
	{\def\jeea@topmargin{#1}}

\JEEA@Option{headheight}{\def\jeea@headheight{#1}}
\JEEA@Option{headsep}{\def\jeea@headsep{#1}}
\JEEA@Option{footskip}{\def\jeea@footskip{#1}}

% We do not support two column as an option, but we retain the commands for compatibility
% (and \twocolumn should  still work in an index).

\newif\if@restonecol
\@twocolumnfalse
\JEEA@OptionA{onecolumn}{}
\JEEA@OptionA{twocolumn}{\JEEA@Warning{Option "twocolumn" not supported.}}


%% 2.3. Font Sizes

% The standard JEEA font size is 10.5pt. Other sizes are implemented through magnification.

% The command \jeea@pttomag converts a pt size to a \mag value.
% We are using the fact that a dimen register can also be treated as an integer (in sp units)
% The value of size should not be a "true" dimen 
\def\jeea@pttomag#1{
	\begingroup
		\@tempdima=#1\relax
		\@tempdima=95.2381\@tempdima  % Now 10pt has been converted to 950.2381 pts.
		\divide\@tempdima\p@          % Divide by 1, and we get 950.
		\global\mag\@tempdima
	\endgroup}

\JEEA@Option{fontsize}{\jeea@pttomag{#1}}

% For backware compatibility:

\JEEA@OptionA{10pt}{\mag=952\relax} 
\JEEA@OptionA{11pt}{\mag=1047\relax} 
\JEEA@OptionA{12pt}{\mag=1142\relax}

% For setting mag, convert to the ptsize (multiple of 10.5pt) and then use \jeea@pttomag.

\JEEA@Option{mag}{{\@tempdima=10.5pt \@tempdima=#1\@tempdima \jeea@pttomag\@tempdima}}

% A number of packages are expecting \@ptsize to be defined. This is the best match:

\def\@ptsize{0}


%% 2.3 Layouts

% There are three possible layouts, which differ only in the front matter:
%
%   JEEA Preprint [preprint] - Simulates an article as printed in JEEA.
%   Working Paper [wp]       - Provides a generic layout, using the jeea commands.
%   Article Class [article]  - Uses the "article" class commands and layout.
%
% The default is "wp"; we don't want to encourage people to use the JEEA "look" for
% articles not accepted for publication.
%
% The wp and article layouts can be with or without (default) a separate title page.
%
% (See the "FRONT MATTER" section of this class or the class documentation for details.)

\newif\ifpreprint
\newif\ifarticlecomp % stands for "compatibility with article class"

\JEEA@BoolOption{titlepage}{}

\JEEA@OptionA{preprint}{\preprinttrue\articlecompfalse\@jeea@titlepagefalse}
\JEEA@OptionA{wp}{\preprintfalse\articlecompfalse}
\JEEA@OptionA{article}{\preprintfalse\articlecomptrue}

\define@choicekey*[@jeea]{}{layout}[\val]
	{preprint,wp,article}
	{\@nameuse{@jeea@\val}{}}

%% 2.4 Fonts

% Some basic font options.
% Authors can include the commands in their preamble, but better to include here
% because of various incompatibilities, such as between amssybm.sty and mtpro.sty.
% Also, for the supported options, we can avoid loading fix-cm.sty.
%
% Font support needs to take care of the following:
%  - Set up text fonts.
%  - Set up math fonts, including those in amsfonts.sty and amssymb.sty.
%  - Make sure that all fonts are scalable, including the math extension font.
%      E.g., include fix-cm.sty, unless sure that no Computer Modern fonts will be used.
%  - Load bm.sty in the right place, if compatible.
%  - Define non-standard command \sbdefault; to be used for the code of the font series
%  - for the subsections.

% Default is to assume that there is no semi-bold font.

\JEEA@OptionA{cmr}{\def\jeeafonts{%
	\RequirePackage{fix-cm,amsfonts,amssymb,bm}%    % exscale implemented in amsfonts.sty
	\RequirePackage{textcomp}%
	}}

\JEEA@OptionA{mathptmx}{\def\jeeafonts{%
	\RequirePackage[T1]{fontenc}%
	\RequirePackage{fix-cm}%
	\RequirePackage{textcomp}%
	\renewcommand{\rmdefault}{ptm}%
	\RequirePackage{amsfonts,amssymb,mathptmx,bm}%
	}}

\JEEA@OptionA{mtpro2}{\def\jeeafonts{%
	\RequirePackage[T1]{fontenc}%
	\RequirePackage{textcomp}%
	\renewcommand{\rmdefault}{ptm}%
	\RequirePackage[amsbb,mtpfrak,zswash,mtphrb,straightbraces]{mtpro2}%
	\RequirePackage{bm}}}
	
\JEEA@OptionA{mtpro2lite}{\def\jeeafonts{%
	\RequirePackage[T1]{fontenc}%
	\RequirePackage{textcomp}%
	\renewcommand{\rmdefault}{ptm}%
	\RequirePackage{amsfonts,amssymb}
	\RequirePackage[lite]{mtpro2}%
	\RequirePackage{bm}}}

% The + here means that last argument is executed when value is not in list.
% So if one of the predefined font options is not given, it is assumed
% that the argument is the name of a style file.

\define@choicekey*+[@jeea]{}{fonts}[\val]
	{cmr,mathptmx,mtpro2,mtpro2lite}
	{\@nameuse{@jeea@\val}{}}
	{\def\jeeafonts{\usepackage{#1}}}

\newcommand{\sbdefault}{\bfdefault}
\JEEA@BoolOption{sb}{%
	\if@jeea@sb
			\def\sbdefault{sb}%
	\else
		\def\sbdefault{\bfdefault}%
	\fi}

\def\jeea@blocklabelfont{\scshape}%
\def\jeea@floatlabelfont{sc}%
\define@choicekey*[@jeea]{}{labelfont}[\val\nr]
	{sc,bf}
	{\ifcase\nr
	   \def\jeea@blocklabelfont{\scshape}%
	   \def\jeea@floatlabelfont{sc}%
	 \or
	   \def\jeea@blocklabelfont{\bfseries}%
	   \def\jeea@floatlabelfont{bf}%
	 \fi}

% An undocumented feature is that user can define \jeeafonts before \documentclass.

\@ifundefined{jeeafonts}{\@jeea@fonts{cmr}}{}


%% 2.5. Misc options

% JEEA bib

\JEEA@BoolOption{jeeabib}{}

% Default input encoding is utf8.

\define@choicekey*+[@jeea]{}{inputenc}
	{none}
	{\def\jeea@inputenc{}}
	{\def\jeea@inputenc{\RequirePackage[#1]{inputenc}}}

% Option to suppress the jeea.cls theorems, so that users can do whatever they want.

\JEEA@BoolOption{notheorems}{}

\JEEA@BoolOption{numberbysection}{}

% Integrate doublespacing etc into the package.

\JEEA@Option{spacing}{\def\baselinestretch{#1}}

\JEEA@OptionA{doublespace}{\def\baselinestretch{\setspace@doublespace}}
\JEEA@OptionA{onehalfspace}{\def\baselinestretch{\setspace@onehalfspace}}

\JEEA@BoolOption{ssfootnotes}{}

% Parskip and parindent

% The reason for making this an option is that we will adjust the
% spacing before/after lists and before/after sections so that they
% do not increase even though \parskip>0. It is optimized for
% \parskip=6.5pt.

\newlength\@parindent
\@parindent=16pt
\parskip=\z@
\parindent=\@parindent

\JEEA@Option{parskip}[6.5\p@ \@plus 1.5\p@ minus 0.5\p@]{%
  \setlength{\parskip}{#1}%
  \parindent\z@}

% Twoside

\JEEA@OptionA{oneside}{\@twosidefalse \@mparswitchfalse}
\JEEA@BoolOption{twoside}{%
	\if@jeea@twoside
		\@twosidetrue  \@mparswitchtrue
	\else
		\@jeea@oneside
	\fi}
 
% Leave this as a supported feature, but don't document. No one cares.

\JEEA@OptionA{final}{\setlength\overfullrule{0pt}}

\JEEA@BoolOption{draft}{%
	\if@jeea@draft
		\setlength\overfullrule{5pt}%
	\else
		\@jeea@final
	\fi}

% Equation number position

\define@choicekey*[@jeea]{}{eqno}[\val\nr]
	{left,right}
	{\ifcase\nr \def\jeea@eqno{leqno}\or \def\jeea@eqno{reqno}\fi}

\JEEA@OptionA{leqno}{\def\jeea@eqno{leqno}}
\JEEA@OptionA{reqno}{\def\jeea@eqno{reqno}}

\JEEA@BoolOption{fleqn}{}


%% 2.7. Execute defaults and process options

% This is for use by the JEEA production office:
% For some reason, if I used \ExecuteOptionX or \setkeys it does not work(?)

\JEEA@OptionA{prod}{%
  \def\jeeafonts{%
	  \RequirePackage[LY1]{fontenc}%
	  \RequirePackage{textcomp}%
	  \renewcommand{\rmdefault}{TimesRoman}%
	  \RequirePackage[subscriptcorrection,amsbb,mtpfrak,zswash,mtphrb,straightbraces]{mtpro2}%
	  \RequirePackage{bm}}%
  \@jeea@preprint{}%
  \def\sbdefault{sb}}

% Defaults:

\ExecuteOptionsX[@jeea]<>{
	jeeapaper,
	wp,
	final,
	eqno=right,
	inputenc=utf8,
	textwidth=126mm,
	textheight=572pt,
	topmargin=auto,     % Let it be determined automatically
	headheight=15\p@,  % Larger than needed, on purpose
	headsep=18\p@,
	footskip=30\p@}

\ProcessOptionsX[@jeea]<>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 3. VERTICAL SPACING PARAMETERS

% \linespace = standard leading or \baselineskip of the body text font.
% It is a useful unit for vertical spacing.
% Not a standard command.

\newdimen\linespace
\linespace=13\p@

% 1/4, 1/2, and 1/1 of \baselineskip

\setlength\bigskipamount{\linespace \@plus 0.3\linespace \@minus 0.2\linespace}
\medskipamount=\bigskipamount
\divide\medskipamount\tw@
\smallskipamount=\bigskipamount
\divide\smallskipamount 4

% \lineskiplimit is the minimum distance between adjacent lines based
% on \baselineskip before this calculation is discarded and \lineskip is added instead.
% So that adjacent lines are always 0.5pt apart if otherwise they would be closer,
% both \lineskiplimit and \lineskip should be set 0.5.
%
% This is different from the default (plain tex and latex) of setting
% \lineskiplimit to 0pt and \lineskip to 1pt. That default has the effect that
% adjacent lines can nearly touch, but if they do touch then they are
% pushed apart by 1pt. However, that default has the advantage that adding a strut typically
% does not push lines apart. In contrast, because  multiple lines with a strut in each
% one will have boxes that exactly touch and hence get pushed apart with our settings, we
% have to be careful about the use of struts.
% one will have boxes that exactly touch.

\normallineskip=0.5\p@
\normallineskiplimit=0.5\p@

\lineskip=\normallineskip
\lineskiplimit=\normallineskiplimit

% These affect mainly spacing around objects in math; we slightly reduce the default
% values and reduce the stretchable amount

\thinmuskip = 2.75mu                         % TeX default: 3mu
\medmuskip = 3.75mu plus 1mu minus 1mu       % TeX default: 4mu + 2mu - 4mu
\thickmuskip = 4.75mu plus 3mu minus 1mu     % TeX default: 5mu + 5mu

% Not a standard parameter

\newdimen\hairlinethickness
\hairlinethickness=0.4pt

% These two lines are irrelevant because
% these are the default values in latex.ltx.

\setlength\fboxsep{3\p@}
\setlength\fboxrule{\hairlinethickness}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 4. LINE SPACING

% Much of this is adapted from setspace.sty because this is a commonly used package.
% We want to be compatible with that interface (but thus not compatible with the package).
% Only exception is that setspace.sty has an environment "singlespace*" of unknown use,
% which we don't implement.
%
% Why not just call setspace.sty?
% If you really want to force switches back to singlespace in certain environments (such
% as floats and footnotes) the way setspace does, then it is better to incorporate the
% code into the document class. Otherwise there are too many conflicts.


%% 4.1 Basics

\newcommand{\setstretch}[1]{%
	\def\baselinestretch{#1}%
	\selectfont}

% \setspacing also tries to create the right transition.
% You basically want the spacing between lines at transition to be
% that of the larger of the two \baselinestretch, rather than
% always that of the new \baselinestretch. So if old>new, we add
% a space equal to the different.

\def\@setspacing#1{%
	\par
	\edef\@oldbaselineskip{\the\baselineskip}%
	\edef\baselinestretch{#1}%
	\selectfont
	\@setfootnotesep
	\begingroup
		\@tempdima=\@oldbaselineskip\relax
		\ifdim\@tempdima>\baselineskip
			\advance\@tempdima-\baselineskip
			\addvspace{\@tempdima}%
		\fi
	\endgroup}

% But don't need to do that until the body of the document, and we don't
% want to explain to the user about a different command for use in the preamble.

\let\setspacing\setstretch
\AtBeginDocument{%
	\let\setspacing\@setspacing
	\@setfootnotesep}

% Users can redefine what these spacings mean

\newcommand{\SetSinglespace}[1]{\def\setspace@singlespace{#1}}
\newcommand{\SetOnehalfspace}[1]{\def\setspace@onehalfspace{#1}}
\newcommand{\SetDoublespace}[1]{\def\setspace@doublespace{#1}}

% Default values:

\SetSinglespace{1}
\SetOnehalfspace{1.4}
\SetDoublespace{1.8}

% The \@singlespacing command is for our use in the places where
% we want to neutralize the non-single spacing, such as tables.
% These are all places where we don't want to add a \vskip
% to adjust for the transition between paragraphs.

\newcommand\@singlespacing{\setstretch{\setspace@singlespace}}

\newcommand\singlespacing{\setspacing{\setspace@singlespace}}
\newcommand\onehalfspacing{\setspacing{\setspace@onehalfspace}}
\newcommand\doublespacing{\setspacing{\setspace@doublespace}}

% This is analogous to \@setspacing, but it used for when
% the spacing is automatically reset because of the end of
% a group. We conveniently use \xdef\@tempg -- not sure
% why this has become taboo in latex3.

\newcommand{\restore@spacing}{%
		\par
		\xdef\@tempg{\the\baselineskip}%
	\endgroup
 	\@tempdima=\@tempg\relax
	\ifdim\@tempdima>\baselineskip
		\advance\@tempdima-\baselineskip
		\addvspace{\@tempdima}
	\fi}

\newenvironment{spacing}[1]
	{\begingroup\setspacing{#1}}
	{\restore@spacing}

\newenvironment{singlespace}
	{\begingroup\singlespacing}
	{\restore@spacing}
	
\newenvironment{onehalfspace}
	{\begingroup \onehalfspacing}
	{\restore@spacing}

\newenvironment{doublespace}
	{\begingroup \doublespacing}
	{\restore@spacing}


%% 4.2 Spacing in equations

% It would be safer, and perhaps a good idea, to not worry about this.
% It is hard to get right and requires several hacks. % Thus, there is
% the option of shutting all this off with \setdisplaystretch{1}.

% setspace.sty has several problems in its approach:
%
% (1) It multiplies \abovedisplayskip etc by \baselinestretch.
% This ends up working as an approximation because the main skips
% are roughly equal to \baselineskip. But it is the wrong idea, because
% these are vertical skips not baseline-to-baseline measurements. We should
% be adding only the extra space between typical lines of text.
%
% (2) The code there also kills the rubber space in those skips (by multiplying
% by a non-integer).
%
% (3) Finally, setspace.sty does not adjust \jot, which controls the spacing
% between multiple lines of an equation.
%
% But changing \jot has a problem because of a bug in the definition of
% the multline environment in amsmath.sty, at least v2.13. It adds \jot as an
% extra space before the environment (like an extra \abovedisplayskip).
% We add a patch when inputing amsmath.sty (see end of this class) and
% hope for the best.

\newcommand{\displaystretch}{\baselinestretch}
\newcommand{\setdisplaystretch}[1]{\def\displaystretch{#1}}

% For compatibility with setspace.sty interface, we include \setdisplayskipstretch.

\let\setdisplayskipstretch\setdisplaystretch

% We only do anything if \displaystretch != 1:

\everydisplay\expandafter{%
	\the\everydisplay
	\ifdim\displaystretch\p@=\p@\else\stretch@displays\fi}

% In principle, we want to increase \jot and the skips by the EXTRA space between
% lines. This is calculated as \dimen@ in the first two lines. But that ends
% up being too much for the displayskip, as they already leave a good amount
% of space. So we use half.
% Also, \jot is used in \openup, which increases the \baselineskip; we don't want
% to double count, so we redefine \openup (actually, \@openup) to stop this ...
% another hack.

\def\stretch@displays{%
	\dimen@=\displaystretch\baselineskip
	\advance\dimen@-\baselineskip
	\advance\jot\dimen@
	\def\@penup{\advance\lineskip\dimen@
		%\advance\baselineskip\dimen@
		\advance\lineskiplimit\dimen@}
	\divide\dimen@\tw@
	\advance\abovedisplayskip\dimen@
  \advance\belowdisplayskip\dimen@
  \advance\abovedisplayshortskip\dimen@
  \advance\belowdisplayshortskip\dimen@}

	
%% 4.3. Spacing in footnotes

% There is no elegant way to handle \footins if the spacing is going to
% to be changed throughout the document. Furthermore, it really only needs to be
% changed if the footnotes will also be doublespaced. We don't even try.

% Unlike in setspace.sty, the default is that footnotes get the same linespacing
% as the body. But it can be changed with the class option ssfootnotes.

% This sets the stretch used when the ssfootnotes option is given;
% otherwise \baselinestretch is used.

\def\footnotestretch{\setspace@singlespace}

\def\@footnotespacing{%
	\if@jeea@ssfootnotes
		\setstretch{\footnotestretch}%
	\fi}

% So this can be changed mid stream:

\def\singlespacefootnotes{\@jeea@ssfootnotestrue}

% We have to take care of the space between footnotes, which is not affected
% by \baselinestretch.

% \footnotesep is the height of a strut place at the beginning of each footnote,
% rather than an extra space between footnotes. So we calculate the usual
% strut height (taking into account the spacing) and increase it by \jfootnotesep.

\newcommand\@setfootnotesep{%
	\begingroup
		\footnotesize
		\@footnotespacing
		\xdef\@tempg{\the\ht\strutbox}%
	\endgroup
	\footnotesep=\@tempg
	\advance\footnotesep\jfootnotesep}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 5. FONT SIZES


% This is not really necessary because it is set by font size commands.

\normalbaselineskip=\linespace

% Standard LaTeX sizes

\renewcommand\normalsize{%
	\@setfontsize\normalsize{10.5\p@}{\linespace}%
	\abovedisplayskip 10.5\p@ \@plus2\p@ \@minus5\p@
	\abovedisplayshortskip \z@ \@plus3\p@
	\belowdisplayshortskip 6.25\p@ \@plus3\p@ \@minus3\p@
	\belowdisplayskip \abovedisplayskip}

\newcommand\small{%
	\@setfontsize\small{9.5pt}{11\p@}%
	\abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@
	\abovedisplayshortskip \z@ \@plus2\p@
	\belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
	\belowdisplayskip \abovedisplayskip}
	
\newcommand\footnotesize{%
	\@setfontsize\footnotesize{8.5pt}{\@xpt}%
	\abovedisplayskip 6\p@ \@plus2\p@ \@minus3\p@
	\abovedisplayshortskip \z@ \@plus\p@
	\belowdisplayshortskip 3\p@ \@plus\p@ \@minus1.5\p@
	\belowdisplayskip \abovedisplayskip}

\newcommand\scriptsize{\@setfontsize\scriptsize{7.5pt}{8.5pt}}
\newcommand\tiny{\@setfontsize\tiny{5.5pt}{6.5pt}}

% Left in for compatibility.

\newcommand\large{\@setfontsize\large\@xiipt{15\p@}}
\newcommand\Large{\@setfontsize\Large\@xivpt{18\p@}}
\newcommand\LARGE{\@setfontsize\LARGE\@xviipt{22\p@}}
\newcommand\huge{\@setfontsize\huge\@xxpt{25\p@}}
\newcommand\Huge{\@setfontsize\Huge\@xxvpt{30\p@}}

% JEEA-Specific sizes

% \smaller used for:  tables and figures (legends and bodies);
%                     abstract
%                     references

\newcommand\smaller{%
	\@setfontsize\smaller{\@ixpt}{10.5\p@}%
	\abovedisplayskip 7.5\p@ \@plus2\p@ \@minus3\p@
	\abovedisplayshortskip \z@ \@plus2\p@
	\belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
	\belowdisplayskip \abovedisplayskip}

\newcommand\tablenotesize{%
	\@setfontsize\tablenotesize{8\p@}{9.5\p@}
	\abovedisplayskip 6.5\p@ \@plus2\p@ \@minus3.5\p@
	\abovedisplayshortskip \z@ \@plus\p@
	\belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@
	\belowdisplayskip \abovedisplayskip}

\ifpreprint
	\newcommand\titlesize{\@setfontsize\titlesize{15.5\p@}{16\p@}}
\else
	\newcommand\titlesize{\Large}
\fi
\newcommand\authorsize{\@setfontsize\authorsize{11\p@}{12\p@}}
\newcommand\affiliationsize{\@setfontsize\affiliationsize{10\p@}{11\p@}}

% These are not new sizes; just applications of the other sizes

\newcommand\extractsize{\small}
\newcommand\headersize{\small}
\newcommand\refsize{\smaller}
\newcommand\tablesize{\smaller}
\newcommand\abstractsize{\smaller}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 6. FONTS

% Times-Roman fonts are recommended for JEEA, but fonts are site-dependent that
% we leave it up to the author to figure this out. Also, this class is meant
% to be  useful for non-JEEA authors.

% Must come after the definition of \normalsize because, e.g. mtpro2.sty
% uses the value of \normalsize. But the first invokation of \normalsize
% must come after the definition of the fonts.

\jeeafonts

\jeea@inputenc

\normalsize

% These commands are redefined by many font packages, so their
% definitions must come here:

\DeclareMathSizes{5.5}{5.5}{5}{5}
%\DeclareMathSizes{6.5}{6.5}{5.5}{5}
\DeclareMathSizes{7.5}{7.5}{6}{5}
\DeclareMathSizes{8}{8}{6.25}{5}
\DeclareMathSizes{8.5}{8.5}{6.5}{5}
\DeclareMathSizes{9}{9}{6.75}{5}
\DeclareMathSizes{9.5}{9.5}{7}{5}
\DeclareMathSizes{10.5}{10.5}{7.5}{5.5}
% Standard
\DeclareMathSizes{\@xipt}{\@xipt}{8}{6}
\DeclareMathSizes{\@xiipt}{\@xiipt}{8}{6}
\DeclareMathSizes{\@xivpt}{\@xivpt}{\@xpt}{7}
\DeclareMathSizes{\@xviipt}{\@xviipt}{\@xiipt}{\@xpt}
\DeclareMathSizes{\@xxpt}{\@xxpt}{\@xivpt}{\@xiipt}
\DeclareMathSizes{\@xxvpt}{\@xxvpt}{\@xxpt}{\@xviipt}

% For the body font of 10.5pt and subscript and subsubscript font sizes of 7.5pt and 5.5pt,
% resp., these values are 0.714 and 0.524. We have rounded up because these ratios would 
% typically be used for smaller font sizes.
\def\defaultscriptratio{.73}
\def\defaultscriptscriptratio{.54}

%
\let\nonvarepsilon\epsilon
\let\nonvarphi\phi
\let\phi\varphi
\let\epsilon\varepsilon


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 7. HORIZONTAL AND VERTICAL DIMENSIONS

% Default JEEA sizes are \jeea@textwidth=126mm and \jeea@textheight=572pt
% A basic idea is that: jeea paper size expands to fit the text,
% whereas text has to fit the paper for letter and A4.

% Now that \mag has been set, we can use \paperwidth and \paperheight

\paperwidth=\thepaperwidth\relax
\paperheight=\thepaperheight\relax

% Get rid of TeX's ridiculous 1-inch margins

\setlength\voffset{-1truein}
\setlength\hoffset{-1truein}

%% Horizontal:

% The "wider" option is meant to be used with CMR fonts, which are about 8% wider
% than Times Roman.

\setlength{\textwidth}{\jeea@textwidth}

\if@jeea@wider
	\textwidth=1.08\textwidth % Increase by 8%
\fi

% Adjust the jeea paper width if the text column width is changed.

\ifdim\paperwidth=171mm    % Then we are using paper size adapted for 126mm column
	\begingroup
		\@tempdima=126mm
		\ifdim\textwidth>\@tempdima  % Then we better increase paper width
			\advance\textwidth-\@tempdima
			\global\advance\paperwidth\textwidth
		\fi
	\endgroup
\fi

% Set side margins evenly for one-sided, 
% and with 5mm larger gutter than thumb for two-sided.

\oddsidemargin=\paperwidth
\advance\oddsidemargin-\textwidth
\divide\oddsidemargin 2
\evensidemargin=\oddsidemargin
\if@twoside
	\advance\oddsidemargin 2.5mm
	\advance\evensidemargin -2.5mm
\fi

% \marginpar's are not very robust. We set them to adjust to the size of the margin,
% minus 0.8cm from the edge of the paper. But we avoid ridiculously small or large
% marginpars, even if they are then the wrong size for the paper (e.g., jeea paper)

\setlength\marginparsep{12\p@} % Gap between marginpar's and column
\marginparwidth\oddsidemargin
\advance\marginparwidth-\marginparsep
\advance\marginparwidth-0.8cm

\ifdim\marginparwidth<2.8cm
	\marginparwidth=2.8cm
\else
	\ifdim\marginparwidth>6cm
		\marginparwidth=6cm
	\fi
\fi

\setlength\marginparpush{5\p@} % min vertical distance btwn marginpars

% These would only be used in an index.

\setlength\columnsep{10\p@}
\setlength\columnseprule{0\p@}

%% Vertical

\setlength\headheight{\jeea@headheight}
\setlength\headsep   {\jeea@headsep}
\setlength\footskip  {\jeea@footskip}
\setlength\textheight{\jeea@textheight}

% Ignore the fullheight spec if using JEEA paper size

\ifdim\paperheight=242mm\else
	\if@jeea@fullheight
		% Then we ignore \jeea@textheight and set it as as a residual
		\begingroup
			\@tempdima=\paperheight
			\advance\@tempdima-26mm  % Maintain margins of 14mm/12mm, which scale up
			\advance\@tempdima-\headheight
			\advance\@tempdima-\headsep
			\advance\@tempdima-\footskip
			\global\textheight=\@tempdima
		\endgroup
	\fi
\fi

\setlength\topskip   {10\p@}    % Irrelevant?
\setlength\maxdepth{.5\topskip} % Irrelevant?

% Now adjust the top and bottom margins to be almost equal

\ifx\jeea@topmargin\@empty
	\topmargin=\paperheight\relax
	\advance\topmargin-\headheight
	\advance\topmargin-\headsep
	\advance\topmargin-\textheight
	\advance\topmargin-\footskip
	\divide\topmargin 2
	\advance\topmargin 1mm  % Slightly larger top margin
\else
  \topmargin=\jeea@topmargin\relax
\fi


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 8. PAPER HANDLING

% Now we need to communicate the paper size to the driver.
% We are confounded by the fact that different drivers have different ways
% of handling the paper size.
% It is then made worse if we want to allow \mag to be used, which we do.
%
% We implement for several drivers:  dvips, dvipdfm, pdftex, xetex, vtex
%
% Tested with TeXLive 2010 (except for vtex). We generally implement all methods
% that seem to be available, in the assumption that a driver won't get confused.
% The exception is with XeTeX. If we use the dvips \special, it will set the
% paper size incorrectly for the first page. (After that,
% the \pdfpagewidth,\pdfpageheight take over.) Must be a bug.


%% 8.1. pdfTeX, XeTeX

% pdfTeX obeys the magnification of TeX dimensions,
% so we just set \pdfpagewidth to \thepagewidth, etc.

\@ifundefined{pdfpagewidth}{}{%
	\pdfpagewidth=\paperwidth
	\pdfpageheight=\paperheight}

% \pdfvorigin and \pdfhorigin have already been set to 1in, but this
% ends up wrong if \mag has been used.

\ifnum\mag=\@m\else
	\@ifundefined{pdfhorigin}{}{%
		\pdfhorigin=1truein
		\pdfvorigin=\pdfhorigin}
\fi


%% 8.2. dvips, dvipdfm

% dvips expects the paper size to be communicated as a \special.
% This has been tested with dvips(k) 5.99, which seems to be able to handle
% arbitrary paper sizes such as our jeea paper. (Some earlier versions could
% only handle paper sizes defined in a dvips configuration file.)

% dvips interprets the paper size as true values.
% So we need to scale the paper dimensions from TeX values to true values.

\begingroup
% Avoid using if XeTeX is being used. Our crude method for checking
% (copied from geometry.sty) is to see if \XeTeXrevision is defined.
\@ifundefined{XeTeXrevision}{%
	% Crude, but the rounding error is barely 0.01pt.
	\ifnum\mag=\@m\else
			\divide\paperwidth 1000
			\multiply\paperwidth\mag
		\divide\paperheight 1000
		\multiply\paperheight\mag
	\fi
	% This is expanded immediately; don't have to worry about the group.
	\AtBeginDvi{\special{papersize=\the\paperwidth,\the\paperheight}}
	}{}
\endgroup

%% 8.3. VTeX

% Can't test this; just copying what geometry.sty does.

\@ifundefined{mediawidth}{}{%
	\mediawidth=\paperwidth
	\mediaheight=\paperheight}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 9. PENALTIES

% These are standard values that affect breaks.
\@lowpenalty   51
\@medpenalty  151
\@highpenalty 301

% Set by Alistair at Sunset
\hyphenpenalty=1000
\pretolerance=8000
\tolerance=9500
\hbadness=8000
\vbadness=9000
\displaywidowpenalty=0
\clubpenalty=10000
\widowpenalty=10000
\lefthyphenmin=3%
\righthyphenmin=3%
\brokenpenalty=10000%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 10. FOOTNOTES

% See also the section on line spacing, which contains the macro
% for setting \footnotesep. Here is the explanation.

% \footnotesep is the height of a strut place at the beginning of each footnote,
% rather than an extra space between footnotes. But we prefer to work in terms
% of the extra space. We define this to be a new parameters, \jfootnotesep
% Then we will calculate the usual strut height, increase it by \jfootnotesep,
% and set \footnotesep equal to the result. See the definition of
% \@setfootnotesep in the footnotes subsection of the the LINE SPACING section.

\newlength\jfootnotesep
\setlength\jfootnotesep{3\p@}

\skip\footins 22pt plus  8pt

% The footnoterule should take zero space; hence the first kern.
% The JEEA width is 42mm, or 1/3 of the textwidth.

\def\footnoterule{%
	\kern -\hairlinethickness
	\hrule height \hairlinethickness \@width 0.3333\columnwidth}

\long\def\@@makefntext#1{%
	\@footnotespacing
	\@footnotelists
	\parindent 16pt
	\parskip\z@
	\noindent #1}

\long\def\@makefntext#1{\@@makefntext{\@thefnmark.\quad#1}}

\long\def\unmarkedfootnote#1{%
	\begingroup%
		\let\@makefntext\@@makefntext
		\footnotetext{#1}%
	\endgroup}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 11. TITLES ETC

% We define the preamble commands so that they work with any format,
% though the jeea commands are ignored in the article format etc.
% Exception: The abstract environment and \Abstract environment


%% 11.1. textcase.sty

% The preprint layout sets the title in upper case. We load textcase.sty
% to make sure this happens properly. This also improves the implementation
% of \MakeUppercase that is used in some of the headers.

\RequirePackage{textcase}


%% 11.2. The preamble commands


\def\JEL#1{\gdef\@JEL{#1}}
\def\@JEL{}

\def\Keywords#1{\gdef\@Keywords{#1}}
\def\@Keywords{}

% These command are ignored in the article format.

\let\Date\date
% Default value of \@date already set in latex.ltx to \today.

\let\Title\title
\def\@title{}  % Instead of generating an error, we work around a missing title

\newcounter{Author}
\def\Author#1#2#3#4{%
	\addtocounter{Author}{1}
	\expandafter\gdef\csname FirstName@\the\c@Author\endcsname{#1}%
	\expandafter\gdef\csname LastName@\the\c@Author\endcsname{#2}%
	\expandafter\gdef\csname Affiliation@\the\c@Author\endcsname{#3}%
	\expandafter\gdef\csname Email@\the\c@Author\endcsname{#4}}

\def\@GetFirstName#1{\csname FirstName@#1\endcsname}
\def\@GetLastName#1{\csname LastName@#1\endcsname}
\def\@GetEmail#1{\csname Email@#1\endcsname}

% Affiliations we treat differently in case they have a \\ that should
% not be expanded. Don't think this is necessary for the other stuff.

% \jeea@get{foo}{\bar} assumes the value of \foo to \bar
\def\jeea@get#1#2{\expandafter\let\expandafter#2\csname #1\endcsname}
\def\@GetAffiliation#1#2{\jeea@get{Affiliation@#1}#2}


\def\Runninghead#1#2{\def\@ShortAuthors{#1}\def\@ShortTitle{#2}}
\def\@ShortTitle{}
\def\@ShortAuthors{}

\def\@GetRunningHead{%
	\ifx\@ShortTitle\@empty
		\xdef\@ShortAuthors{%
			\ifnum\c@Author=0\else
				\ifnum\c@Author=1
					\@GetLastName{1}%
				\else
					\ifnum\c@Author=2
						\@GetLastName{1} and \@GetLastName{2}%
					\else
						\@GetLastName{1} et al.%
					\fi
				\fi
			\fi}%
		\ifx\@title\@undefined
			\def\@ShortTitle{}%
		\else
			\global\let\@ShortTitle\@title
		\fi
	\fi}

\AtBeginDocument{\@GetRunningHead}

\def\@GetEmails{%
	\@GetEmail{\the\@tempcnta}\space(\@GetLastName{\the\@tempcnta})%
	\ifnum\@tempcnta<\c@Author
		;\space
		\advance\@tempcnta 1
		\expandafter\@GetEmails
	\fi}

\def\@Email{%
	\ifnum\c@Author=0\else
		\ifnum\c@Author=1
			\unmarkedfootnote{\raggedright \@hangfrom{E-mail: }\@GetEmail{1}}%
		\else
			\@tempcnta=1
			\unmarkedfootnote{\raggedright \@hangfrom{E-mail: }\@GetEmails}%
		\fi
	\fi}


\newcounter{Editor}
\def\Editor#1{%
	\addtocounter{Editor}{1}
	\expandafter\gdef\csname Editor@\the\c@Editor\endcsname{#1}}

\def\@GetEditor#1{\csname Editor@#1\endcsname}

\def\@GetEditors{%
	\ifnum\@tempcnta=\c@Editor and\space \fi
	\@GetEditor{\the\@tempcnta}
	\ifnum\@tempcnta<\c@Editor
		,\space
		\advance\@tempcnta 1
		\expandafter\@GetEditors
	\fi}

\ifpreprint

	\def\@Editor{%
		\ifnum\c@Editor=0\else
			\ifnum\c@Editor=1
				\unmarkedfootnote{\textit{The editor in charge of this paper was \@GetEditor{1}.}}%
			\else
				\ifnum\c@Editor=2
					\unmarkedfootnote{\textit{The editors in charge of this paper were
							\@GetEditor{1} and \@GetEditor{2}.}}%
				\else
					\@tempcnta=1
					\unmarkedfootnote{\textit{The editors in charge of this paper were \@GetEditors.}}%
				\fi
			\fi
		\fi}

\else

	\let\@Editor\relax

\fi

\def\Thanks#1{\gdef\@Thanks{\unmarkedfootnote{\thanksname: #1}}}
\let\@Thanks\@empty

% Not sure what I intend for this.

\def\Beforeabstract#1{\gdef\@Beforeabstract{#1}}
\def\Afterabstract#1{\gdef\@Afterabstract{#1}}
\def\@Beforeabstract{}
\def\@Afterabstract{}


%% 11.3. Titlepage environment

% Similar to the article.cls version

\newenvironment{titlepage}
	{%
		\thispagestyle{empty}%
		\pagenumbering{roman}
		\setcounter{page}{0}%
	}%
	{\clearpage
	\if@twoside\ifeven\c@page\null\clearpage\fi
		\pagenumbering{arabic}
	}


%% 11.4. ARTICLE.CLS COMPATIBLE TITLES

\ifarticlecomp
	
	% From the standard article class.
	% It is based on the preamble commmands \author, \date, \title, \thanks,
	% which retain their usual definitions from latex.ltx.
	
	\if@jeea@titlepage
		\newenvironment{abstract}{%
			\titlepage
			\null\vfil
			\@beginparpenalty\@lowpenalty
			\begin{center}%
				\bfseries \abstractname
				\@endparpenalty\@M
			\end{center}}%
		{\par\vfil\null\endtitlepage}
	\else
		\newenvironment{abstract}{%
			\if@twocolumn
				\section*{\abstractname}%
			\else
				\small
				\begin{center}%
					{\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
				\end{center}%
				\quotation
			\fi}
			{\if@twocolumn\else\endquotation\fi}
	\fi
	
	\def\Abstract#1{\JEEA@Error{With the "article" option, use the "abstract"\MessageBreak
		environment rather than the "\string\Abstract" command.}}
		
	\if@jeea@titlepage
	
		\newcommand\maketitle{%
			\begin{titlepage}%
				\let\footnotesize\small
				\let\footnoterule\relax
				\let \footnote \thanks
				\null\vfil
				\vskip 60\p@
				\begin{center}%
					\@singlespacing
					{\LARGE \@title \par}%
					\vskip 3em%
					{\large
					\lineskip .75em%
						\begin{tabular}[t]{c}%
							\@author
						\end{tabular}\par}%
						\vskip 1.5em%
					{\large \@date \par}%       % Set date in \large size.
				\end{center}\par
				\@thanks
				\vfil\null
			\end{titlepage}%
			\setcounter{footnote}{0}}

	\else    % matches \if@jeea@titlepage
	
		\newcommand\maketitle{%
			\par
			\begingroup
				\renewcommand\thefootnote{\@fnsymbol\c@footnote}%
				\def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
				\long\def\@makefntext##1{\@footnotespacing\parindent 1em\noindent
								\hb@xt@1.8em{%
										\hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
				\if@twocolumn
					\ifnum \col@number=\@ne
						\@maketitle
					\else
						\twocolumn[\@maketitle]%
					\fi
				\else
					\newpage
					\global\@topnum\z@   % Prevents figures from going at top of page.
					\@maketitle
				\fi
				\thispagestyle{plain}\@thanks
			\endgroup
			\setcounter{footnote}{0}}
		
		\def\@maketitle{%
			\null
			\vskip 2em%
			\begin{center}%
			\@singlespacing
			\let \footnote \thanks
				{\LARGE \@title \par}%
				\vskip 1.5em%
				{\large
					\lineskip .5em%
					\begin{tabular}[t]{c}%
						\@author
					\end{tabular}\par}%
				\vskip 1em%
				{\large \@date}%
			\end{center}%
			\par
			\vskip 1.5em}

	\fi   % ends \if@jeea@titlepage

\else  % matches \ifarticlecomp

%% 11.5. JEEA.CLS  TITLES

% In several places we set \lineskiplimit=0pt because we often use
% struts to force certain spacing.

\ifpreprint
  \@jeea@titlepagefalse
\fi

	\def\Abstract#1{\gdef\@Abstract{#1}}
	\def\@Abstract{}

	\ifpreprint
	
		\let\@PrintBeforeabstract\relax
		\let\@PrintAfterabstract\relax
		
	\else
	
	  \def\@PrintBeforeabstract{%
	  		\ifx\@Beforeabstract\@empty\else
				{\@Beforeabstract\par}%
				\if@jeea@titlepage
					\vfil
				\else
					\addvspace{\linespace}%
				\fi
			\fi}
			
		\def\@PrintAfterabstract{%
			\ifx\@Afterabstract\@empty\else
				\if@jeea@titlepage
					\vfil
				\else
					\addvspace{\linespace}%
				\fi
				{\@Afterabstract\par}%
			\fi}

	\fi
	
	\def\@PrintAbstract{%
	  \@tempcnta=\@ne
		\ifx\@Abstract\@empty
		  \ifx\@JEL\@empty
		    \ifx\@Keywords\@empty
		      \@tempcnta=\z@
		    \fi
		  \fi
		\fi
		\ifnum\@tempcnta=\@ne
			\vbox{%
			  \@tempcnta=\z@
				\parindent\z@ \parskip\z@
				\abstractsize\normalfont%
				\ifx\@Abtract\@empty\else
				  \textbf{\abstractname}\par
				  {\@Abstract}%
				  \unskip
				  \@tempcnta=\@ne
				\fi
				\ifx\@JEL\@empty\else
				  \ifnum\@tempcnta=\@ne
						\ (JEL:~\expandafter\ignorespaces\@JEL\unskip)%
				  \else
				    JEL:~\expandafter\ignorespaces\@JEL\unskip
				  \fi
				  \@tempcnta=\@ne
				\fi
				\ifx\@Keywords\@empty\else
				  \ifnum\@tempcnta=\@ne
				    \par
				    \smallskip
				  \fi
				  Keywords:~\expandafter\ignorespaces\@Keywords\unskip\jeea@addperiod
				\fi
				\vrule \@height 0pt \@depth\dp\strutbox \@width\z@
				\par}%
		\fi}
	
	\def\abstract{\JEEA@Error{%
		Use the "\string\Abstract" command rather than the "abstract" environment.}}

	\ifpreprint

		\def\@SetTitle#1#2{%
			\setbox#1=\vbox{%
				\titlesize
				\bfseries
				\raggedright
				\noindent
				\leavevmode
				\vrule \@height\ht\strutbox  \@depth\z@ \@width\z@
				\MakeTextUppercase{#2}%
				\vrule \@height\z@ \@depth\dp\strutbox \@width\z@
				\par}}

		\def\@PrintTitle{%
			\ifx\@title\@empty\else
				\begingroup
					\@singlespacing
					\@SetTitle\@tempboxa{\@title}%
					\@SetTitle\z@{J\newline J\newline J}%
					\ifdim\ht\@tempboxa>\ht\z@
						\JEEA@Warning{In JEEA style, title should only be three lines.}%
					\else
					% The following does the right thing because of the way TeX changes the
					% height of a \vbox. It keeps the glue at the top the same, so the extra
					% space is added at the bottom of the box instead of at the top.
					% There is no effect on the depth of the box, even though now this depth
					% is completely artificial. It would be very different if the box had
					% been created with an \hbox.
						\ht\@tempboxa=\ht\z@
					\fi
					\dp\@tempboxa=12.5pt
					\box\@tempboxa
					\hrule height 3pt
				\endgroup
			\fi}
		
	\else
	
		\def\@PrintTitle{%
			\ifx\@title\@empty\else
				\begin{center}
					\@singlespacing
					\titlesize\bfseries\@title
				\end{center}
			\fi}
	
	\fi

	\def\@PrintAuthors{%
		\ifnum\c@Author>0
			\kern 1.5\linespace
			\@tempcnta=1
			\begingroup
				\@singlespacing
				\lineskiplimit=0pt  % Because of use of struts
				\ifpreprint\else\centering\fi
				\@MakeAuthors
				\par
			\endgroup
		\fi
		\addvspace{3\linespace}}
	
	% We handle empty first name, but empty last name wouldn't make sense.
	
	\def\@MakeAuthor#1{%
		\noindent
		\parbox[t]{0.47\hsize}{%
			\ifpreprint\raggedright \else\centering\fi
			\begingroup
				\authorsize
				\bfseries
				\strut
				\edef\@tempa{\@GetFirstName{#1}}%
				\ifx\@tempa\@empty\else
					\@tempa~%
				\fi
				\@GetLastName{#1}\strut
				\par
			\endgroup
			\@GetAffiliation{#1}\@tempa
			\ifx\@tempa\@empty\else
			  \affiliationsize
				\leavevmode\strut\@tempa
			\fi
			}}
	
	\def\@MakeAuthors{%
		\@MakeAuthor{\the\@tempcnta}%
		\ifnum\@tempcnta<\c@Author
			\ifodd\@tempcnta \kern 0.03\hsize \else \par\kern 0.5\linespace \fi
			\advance\@tempcnta 1
			\expandafter\@MakeAuthors
		\fi}

\ifpreprint

	\def\@PrintDate{\addvspace{3\linespace}}

\else

	\def\@PrintDate{%
		\ifx\@date\@empty
			\addvspace{3\linespace}%
		\else
			\addvspace{\bigskipamount}%
			\centerline{\normalfont\normalsize\@date}%
			\addvspace{\bigskipamount}%
		\fi}

\fi

	\def\maketitle{%
		\@maketitle
		\setcounter{footnote}{0}}

	\if@jeea@titlepage
	
		\def\@maketitle{%
			\begin{titlepage}
				\@Thanks
				\@Email
				\@PrintTitle
				\@PrintAuthors
				\@PrintDate
				\vfil
				\@PrintBeforeabstract
				\@PrintAbstract
				\@PrintAfterabstract
				\vfil
			\end{titlepage}}

	\else
	
		\def\@maketitle{%
			\global\@topnum\z@   % Prevents figures from going at top of page.
			\thispagestyle{title}%
			\ifpreprint\@Editor\fi
			\@Thanks
			\@Email
			\@PrintTitle
			\@PrintAuthors
			\@PrintDate
			\@PrintBeforeabstract
			\@PrintAbstract
			\@PrintAfterabstract
			\kern 4pt
			\hrule height \hairlinethickness
			\addvspace{\bigskipamount}}
	
	\fi
			
\fi % end of \ifarticlecomp \else


%% 11.6. Clearing out the preamble commands

% We don't do it. saving this small amount of memory can't matter these days.
% Then we don't have to be fussy about whether these are used in the preamble
% or after \begin{document} but before \maketitle. Furthermore, we can use
% values of saved information at any time.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 12. FLOATS


%% 12.1 Basics, slightly adapted from article.sty

% Unadjusted values from size10.clo

\setlength\floatsep    {14\p@ \@plus 2\p@ \@minus 2\p@}
\setlength\textfloatsep{20\p@ \@plus 2\p@ \@minus 4\p@}
\setlength\intextsep   {12\p@ \@plus 2\p@ \@minus 2\p@}
\setlength\dblfloatsep    {12\p@ \@plus 2\p@ \@minus 2\p@}
\setlength\dbltextfloatsep{20\p@ \@plus 2\p@ \@minus 4\p@}
\setlength\@fptop{0\p@ \@plus 1fil}
\setlength\@fpsep{8\p@ \@plus 2fil}
\setlength\@fpbot{0\p@ \@plus 1fil}
\setlength\@dblfptop{0\p@ \@plus 1fil}
\setlength\@dblfpsep{8\p@ \@plus 2fil}
\setlength\@dblfpbot{0\p@ \@plus 1fil}
\setlength\partopsep{2\p@ \@plus 1\p@ \@minus 1\p@}

% Values from Alistair at Sunset:

\setcounter{topnumber}{10}
\def\topfraction{1}
\setcounter{bottomnumber}{10}
\def\bottomfraction{0.8}
\setcounter{totalnumber}{10}
\def\textfraction{0}
\renewcommand{\floatpagefraction}{0.95}
\setcounter{dbltopnumber}{10}
\renewcommand{\dblfloatpagefraction}{0.95}
\renewcommand{\dbltopfraction}{1}

% Tables

\setlength\arraycolsep{5\p@}
\setlength\tabcolsep{0.5em}  % so space is one quad
\setlength\arrayrulewidth{.4\p@}
\setlength\doublerulesep{2\p@}
\setlength\tabbingsep{\labelsep}


% From article.cls

\newcounter{figure}
\renewcommand \thefigure {\@arabic\c@figure}
\def\fps@figure{tbp}
\def\ftype@figure{1}
\def\ext@figure{lof}
\def\fnum@figure{\figurename\nobreakspace\thefigure}
\newenvironment{figure}
	{\@float{figure}}
	{\end@float}
\newenvironment{figure*}
	{\@dblfloat{figure}}
	{\end@dblfloat}
\newcounter{table}
\renewcommand\thetable{\@arabic\c@table}
\def\fps@table{tbp}
\def\ftype@table{2}
\def\ext@table{lot}
\def\fnum@table{\tablename\nobreakspace\thetable}
\newenvironment{table}
	{\@float{table}}
	{\end@float}
\newenvironment{table*}
	{\@dblfloat{table}}
	{\end@dblfloat}
							

%% 12.2. General formating of the body:

% Add a hook to floats to reset the spacing and set the font.
% Hopefuly it won't break anything:

\expandafter\def\expandafter\@floatboxreset\expandafter{%
	\@floatboxreset
	\@singlespacing
	\tablesize
	\centering}

%% 12.3. Captions

\newlength\abovecaptionskip
\newlength\belowcaptionskip
\setlength\abovecaptionskip{\linespace}
\setlength\belowcaptionskip{0\p@}

% The next line, which is from article.cls, is to fool caption.sty into
% thinking we are using article.cls. Otherwise, the package generates a warning.
% Do not modify in any way.

\long\def\@makecaption#1#2{%
	\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}

\usepackage{caption}

\DeclareCaptionLabelSeparator{jperiod}{.\hspace*{0.5em}}
\DeclareCaptionFont{tablesize}{\tablesize}

\captionsetup{%
	position=auto,
	font=tablesize,
	labelfont=\jeea@floatlabelfont,
	labelsep=jperiod,
	justification=justified,
	singlelinecheck=true}

% Without this, caption.sty tries to guess the position.

\ifpreprint
	\captionsetup[figure]{position=bottom}
	\captionsetup[table]{position=top,skip=2.6pt}
\fi


%% 12.4. Booktabls.sty

%\RequirePackage{array}  % Incompatible with sgame.sty by Martin Osborne
\RequirePackage{booktabs}
\heavyrulewidth=1.0pt
\lightrulewidth=1.0pt
\cmidrulewidth=1.0pt

%% 12.5. Table notes

% minipage should not be used to insert footnotes in tables, but we set this
% parameter anyway.

\skip\@mpfootins = \skip\footins

% Now the right way (or a better way).

\newcommand\tnmark[1]{\textsuperscript{#1}}

\def\tablenotesep{2pt}

\newcounter{tablenote}
\def\thetablenote{\alph{tablenote}}
\def\tablenotemark{\thetablenote.\hskip 0.75em}

\def\tablenotes{%
  \par
  % This is needed to get the 2pt space following a table that has large depth.
  \prevdepth\z@
  % These lines are adapted from caption.sty:
	\let\if@nobreak\iffalse
	\let\if@noskipsec\iffalse
	\let\par\@@par
	\parindent 14pt % Smaller than default value for body because font is smaller.
	\parskip\z@skip
	\everypar{}%
	\leftmargin\z@
	\rightmargin\z@
	\linewidth\hsize
	\@totalleftmargin\z@
	\leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip
	\parfillskip\@flushglue
	\sloppy
	\let\\\@normalcr
  %
  	\@tablenotelists
	\normalfont
	\tablenotesize\selectfont
	\setcounter{tablenote}{0}}
\def\endtablenotes{\par}

\def\tablenote{\@ifstar{\@tablenote}{\@@tablenote}}
\def\@tablenote{%
  \par
  \addvspace{1.5\p@}%   % Should this just be \vskip 2pt?
  \noindent\ignorespaces}
\def\@@tablenote{%
  \refstepcounter{tablenote}%
  \@tablenote
  \thetablenote.\hskip 0.75em
  \ignorespaces}
 

%% 12.6. Fitting tables to \linewidth

% Default \tabcolsep is 6pt

\newdimen\mintabcolsep
\newdimen\maxtabcolsep
\mintabcolsep=4pt
\maxtabcolsep=0.75cm

\long\def\fittable#1{%
	\begingroup
		\tabcolsep=\mintabcolsep
		\setbox\@tempboxa=\hbox{\ignorespaces #1\unskip}%
		\@tempdima=\wd\@tempboxa
		\ifdim\@tempdima<\linewidth
			% We are estimating the number of times \tabcolsep is inserted.
			% This should be an integer, but just in case some weird thing is
			% using non-integer values, we take some precautions.
			\advance\tabcolsep 1pt
			\setbox\@tempboxa=\hbox{\ignorespaces #1\unskip}%
			\@tempdimb=\wd\@tempboxa
			\advance\@tempdimb-\@tempdima
			\multiply\@tempdimb 10
			\divide\@tempdimb\p@
			% Now \@tempdimb, which can also be treated as an integer counter, equals
			% 10 x the number of instances of \tabcolsep.
			% Next we calculate the total extra space to be inserted
			\@tempdimc=\linewidth
			\advance\@tempdimc-\@tempdima
			% Divide by the number of instances of \tabcolsep
			\multiply\@tempdimc 10
			\divide\@tempdimc\@tempdimb
			% So we increase \tabcolsep by that amount
			\advance\tabcolsep-1pt
			\advance\tabcolsep\@tempdimc
			% But we con't want \tabcolsep to exceed \maxtabcolsep
			\ifdim\tabcolsep>\maxtabcolsep
				\tabcolsep=\maxtabcolsep
			\fi
			% Set the table one more time, with the new value of \tabcolsep
			\setbox\@tempboxa=\hbox{\ignorespaces #1\unskip}%
		\fi
		\leavevmode\box\@tempboxa
	\endgroup}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 13. HEADERS / FOOTERS

% We retain generic article.cls headings for compatibility;
% They are unmodified except for fonts.

\if@twoside

	\def\ps@headings{%
			\let\@oddfoot\@empty\let\@evenfoot\@empty
			\def\@evenhead{\headersize\thepage\hfil{\leftmark}}%
			\def\@oddhead{\headersize{\rightmark}\hfil\thepage}%
			\let\@mkboth\markboth
		\def\sectionmark##1{%
			\markboth {\MakeUppercase{%
				\ifnum \c@secnumdepth >\z@
					\thesection\quad
				\fi
				##1}}{}}%
		\def\subsectionmark##1{%
			\markright {%
				\ifnum \c@secnumdepth >\@ne
					\thesubsection\quad
				\fi
				##1}}}
				
\else

	\def\ps@headings{%
		\let\@oddfoot\@empty
		\def\@oddhead{\headersize{\rightmark}\hfil\thepage}%
		\let\@mkboth\markboth
		\def\sectionmark##1{%
			\markright {\MakeUppercase{%
				\ifnum \c@secnumdepth >\m@ne
					\thesection\quad
				\fi
				##1}}}}
				
\fi

\def\ps@myheadings{%
		\let\@oddfoot\@empty\let\@evenfoot\@empty
		\def\@evenhead{\headersize\thepage\hfil{\leftmark}}%
		\def\@oddhead{\headersize{\rightmark}\hfil\thepage}%
		\let\@mkboth\@gobbletwo
		\let\sectionmark\@gobble
		\let\subsectionmark\@gobble}
		
% These are JEEA-specific

\def\footer#1{\@dblarg{\@footer{#1}}}
\def\@footer#1[#2]#3{%
	\ifnum#1=\@ne
		\def\firstpage@footeri{#2}%
		\def\@footeri{#3}%
	\else
		\ifnum#1=\tw@
			\def\firstpage@footerii{#2}%
			\def\@footerii{#3}%
		\else
			\JEEA@Error{First argument of \string\footer\ should be "1" or "2".}
		\fi
	\fi}

\ifpreprint
  \footer1{}
  \footer2{\textit{Preprint prepared \ifx\@date\@empty\else on \@date\space\fi}}
\else
  \footer1{}
  \footer2{}
\fi

\def\ps@title{%
	\def\@oddhead{}%
	\let\@evenhead\@oddhead
	\def\@oddfoot{\vtop{%
		\footnotesize
		\@singlespacing
		\hbox to \hsize{\strut\firstpage@footeri\hfil}%
		\hbox to \hsize{\strut\firstpage@footerii\hfil}}}%
	\let\@evenfoot\@oddfoot}

\if@twoside
		
	\def\ps@jeea{%
		\let\@mkboth\@gobbletwo
		\ifpreprint
			\def\@evenhead{\headersize\thepage\hfil{\textit{\jeeaname}}}%
			\def\@oddhead{\headersize
				\ifx\@ShortAuthors\@empty\else{\@ShortAuthors}\quad\fi
				{\@ShortTitle}\hfil\thepage}%
	  \else
			\def\@evenhead{\headersize\thepage\hfil{\@ShortAuthors}}
			\def\@oddhead{\headersize{\@ShortTitle}\hfil\thepage}
		\fi	  
		\def\@evenfoot{\footnotesize\hfil\strut\@footeri}}%
		\def\@oddfoot{\footnotesize\strut\@footerii\hfil}}}

\else

	\def\ps@jeea{%
		\let\@mkboth\@gobbletwo
			\def\@oddhead{\headersize
				\ifx\@ShortAuthors\@empty\else{\@ShortAuthors}\quad\fi
				{\@ShortTitle}\hfil\thepage}%
			\let\@evenhead\@oddhead
		\def\@oddfoot{\vtop{%
			\footnotesize
			\@singlespacing
			\hbox to \hsize{\strut\@footeri\hfil}%
			\hbox to \hsize{\strut\@footerii\hfil}}}%
		\let\@evenfoot\@oddfoot}

\fi

\ifarticlecomp
	\pagestyle{myheadings}
\else
	\pagestyle{jeea}
\fi


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 14. SECTIONS

% Only 3 levels of headings are meant to be used:
% \section, \subsection, \subsubsection.
%
% \paragraph can also be used to add an italic heading to any paragraph.
%
% The other article.cls headings -- \part,  \subparagraph --
% are implemented to make it easier to get files running, but they generate errors
% if used with preprint.


%% 14.1. Basics

\renewcommand{\@seccntformat}[1]{{\csname the#1\endcsname.}\hspace{0.5em}}

% The stuff that is supposed to be used. The \paragraph counter will never be used
% but needs to be defined.

\setcounter{secnumdepth}{3}
\newcounter {section}
\newcounter {subsection}[section]
\newcounter {subsubsection}[subsection]
\newcounter {paragraph}[subsubsection]

\renewcommand\thesection {\@arabic\c@section}
\renewcommand\thesubsection   {\thesection.\@arabic\c@subsection}
\renewcommand\thesubsubsection{\thesubsection.\@arabic\c@subsubsection}
\renewcommand\theparagraph    {\thesubsubsection.\@arabic\c@paragraph}

% Syntax:
% \@startsection{counter}{depth}{indent}{before_skip}{after_skip}{font}

\newskip\sectionskipi
\newskip\sectionskipii

\sectionskipi = \linespace \@plus 0.2\linespace minus 0.1\linespace
\sectionskipii =\sectionskipi
\multiply\sectionskipii\tw@

\advance\sectionskipi-\parskip
\advance\sectionskipii-\parskip

\newcommand\section{\@startsection{section}{1}
	{\z@}%
	{\sectionskipii}%
	{\sectionskipi\@afterindentfalse}%
	{\normalfont\normalsize\bfseries\raggedright}}
	
\newcommand\subsection{\@startsection{subsection}{2}
	{\z@}%
	{\sectionskipi}%
	{\sectionskipi\@afterindentfalse}%
	{\normalfont\normalsize\fontseries{\sbdefault}\itshape\raggedright}}
	
\newcommand\subsubsection{\@startsection{subsubsection}{3}
	{\z@}%
	{\sectionskipi}%
	{-1em}%
	{\normalfont\normalsize\itshape}}

\newcommand\paragraph{\@startsection{paragraph}{4}
	{\parindent}%
	{\z@}%
	{-0.5em}%
	{\normalfont\normalsize\itshape}}

%% 14.2. Compatibility with article.cls

% \part and \subparagraph aren't supported except with the article option
% (for compatibility)

\ifarticlecomp

	% Copied from article.cls, except font sizes reduced

	\newcounter {part}
	\newcounter {subparagraph}[paragraph]

	\renewcommand\thepart {\@Roman\c@part}
	\renewcommand\thesubparagraph {\theparagraph.\@arabic\c@subparagraph}
		
	\newcommand\part{%
		\if@noskipsec \leavevmode \fi
		\par
		\addvspace{4ex}%
		\@afterindentfalse
		\secdef\@part\@spart}
	
	\def\@part[#1]#2{%
			\ifnum \c@secnumdepth >\m@ne
				\refstepcounter{part}%
				\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
			\else
				\addcontentsline{toc}{part}{#1}%
			\fi
			{\parindent \z@ \raggedright
			\interlinepenalty \@M
			\normalfont
			\ifnum \c@secnumdepth >\m@ne
				\large\bfseries \partname\nobreakspace\thepart
				\par\nobreak
			\fi
			\Large \bfseries #2%
			\markboth{}{}\par}%
			\nobreak
			\vskip 3ex
			\@afterheading}
	\def\@spart#1{%
			{\parindent \z@ \raggedright
			\interlinepenalty \@M
			\normalfont
			\Large \bfseries #1\par}%
			\nobreak
			\vskip 3ex
			\@afterheading}
	
	% Identical to \paragraph:
	
	\newcommand\subparagraph{\@startsection{subparagraph}{5}
		{\parindent}%
		{\parskip}%
		{-\enspace}%
		{\normalfont\normalsize\itshape}}

\else

	\def\part{\JEEA@Error{\string\part\space not supported.}}
	\def\subparagraph{\JEEA@Error{\string\subparagraph\space not supported.}}

\fi


%% 14.3. Some hacks for in-line headings and appendices

% We modify \@sect and \@@sect with two purposes:
%   (a) Add a period to run-in headings (\subsubsection)
%   (b) Keep track of heading style for appendices

\def\jeea@addperiod{\ifnum\spacefactor>1000\else .\fi}

\newif\ifmultipleappendices
\newif\if@appendixtitle

\def\jeea@appendix#1#2{%
	\ifnum#1=1
		\ifnum\c@section=\tw@
			\global\multipleappendicestrue
			\immediate\write\@mainaux{\string\global\string\multipleappendicestrue}%
		\fi
		\def\@tempa{#2}%
		\ifx\@tempa\@empty\else
			\@appendixtitletrue
		\fi
	\fi}
\let\jeea@@appendix\@gobbletwo  % Will be set to \jeea@appendix in an appendix

\def\@appcntformat{%
	Appendix\ifmultipleappendices~\thesection\fi
	\if@appendixtitle :\kern 0.5em\fi}

% This is from latex.ltx, with the sole modifications shown below

\def\@sect#1#2#3#4#5#6[#7]#8{%
	\ifnum #2>\c@secnumdepth
		\let\@svsec\@empty
	\else
		\refstepcounter{#1}%
		\jeea@@appendix{#2}{#8}%         % \jeea@appendix inserted here
		\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
		\def\@svsechd{%
			#6{\hskip #3\relax
			\@svsec #8\jeea@addperiod}%    \jeea@addperiod inserted here
			\csname #1mark\endcsname{#7}%
			\addcontentsline{toc}{#1}{%
				\ifnum #2>\c@secnumdepth \else
					\protect\numberline{\csname the#1\endcsname}%
				\fi
				#7}}%
	\fi
	\@xsect{#5}}

\def\@ssect#1#2#3#4#5{%
	\@tempskipa #3\relax
	\ifdim \@tempskipa>\z@
		\begingroup
			#4{%
				\@hangfrom{\hskip #1}%
					\interlinepenalty \@M #5\@@par}%
		\endgroup
	\else
		\def\@svsechd{#4{\hskip #1\relax #5}\jeea@addperiod}%    \jeea@addperiod inserted here
	\fi
	\@xsect{#3}}
		

%% 14.4. Appendices

\def\appendix{%
	\par
	\setcounter{section}{0}
	\setcounter{equation}{0}
	\ResetAll{section}
	\renewcommand{\thesection}{\Alph{section}}%
	\global\let\jeea@@appendix\jeea@appendix
	\def\@seccntformat##1{%
		\ifnum\the\c@subsection=0
			\@appcntformat
		\else
			\csname the##1\endcsname.\hspace{0.5em}%
		\fi}}

\def\appendices{\global\multipleppendicestrue\appendix}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 14a. RESETTING NUMBERS

% The main purpose is for the appendices

\def\jeea@addcounterprefix#1#2{%
	\edef\next##1{%
		\noexpand\gdef
		\expandafter\noexpand\csname the#1\endcsname{%
				\expandafter\noexpand\csname the#2\endcsname
			\@thmcountersep##1}}%
	\expandafter\let\expandafter\@tempa\csname the#1\endcsname
	\expandafter\next\expandafter{\@tempa}}

% \AddToReset{counter}{master}

\def\AddToReset#1#2{%
	\@addtoreset{#1}{#2}%              % This is a latex.ltx command
	\jeea@addcounterprefix{#1}{#2}}

\def\ResetAll#1{%
	\if@jeea@notheorems\else
		\ResetTheorems{#1}%
	\fi
	\AddToReset{equation}{#1}%
	\AddToReset{figure}{#1}%
	\AddToReset{table}{#1}}

\def\ResetEvenFootnotes#1{\ResetAll{#1}\@addtoreset{footnote}{#1}}

\AtBeginDocument{%
	\if@jeea@numberbysection
		\ResetAll{section}%
		\global\let\ResetAll\@gobble%
	\fi}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 15. LISTS

% We are using enumitem package, which overrides many of these things.

\setlength\leftmargini{1.75em}
\leftmargin\leftmargini
\setlength\leftmarginii  {1.667em}
\setlength\leftmarginiii {1.59em}
\setlength\leftmarginiv  {1.5em}
	\setlength\leftmarginv  {.5em}
	\setlength\leftmarginvi {.5em}
\setlength  \labelsep  {.5em}
\setlength  \labelwidth{\leftmargini}
\addtolength\labelwidth{-\labelsep}
\@beginparpenalty -\@lowpenalty
\@endparpenalty   -\@lowpenalty
\@itempenalty     -\@lowpenalty
\renewcommand\theenumi{\@arabic\c@enumi}
\renewcommand\theenumii{\@alph\c@enumii}
\renewcommand\theenumiii{\@roman\c@enumiii}
\renewcommand\theenumiv{\@Alph\c@enumiv}
\newcommand\labelenumi{\theenumi.}
\newcommand\labelenumii{(\theenumii)}
\newcommand\labelenumiii{\theenumiii.}
\newcommand\labelenumiv{\theenumiv.}
\renewcommand\p@enumii{\theenumi}
\renewcommand\p@enumiii{\theenumi(\theenumii)}
\renewcommand\p@enumiv{\p@enumiii\theenumiii}
\newcommand\labelitemi{\normalfont\textbullet}
\newcommand\labelitemii{\normalfont \textendash}
\newcommand\labelitemiii{\textasteriskcentered}
\newcommand\labelitemiv{\textperiodcentered}


% Needs fine-tuning. E.g., what are the right paragraph indents?
% I had to insert to move the change in font size to after \item;
% otherwise it affects the leading of the previous part. Odd.

\newenvironment{verse}
	{\let\\\@centercr
		\list{}{%
			\itemindent -1.5em%  
			\listparindent\itemindent
			\advance\leftmargin 1.5em
			\parsep\parskip \divide\parsep2
			}%
		\item\relax\extractsize}
	{\endlist}

\newenvironment{quotation}
	{\list{}{%
		\listparindent\@parindent
		\itemindent\listparindent
		\parsep\parskip \divide\parsep2}%
		\item\relax\extractsize}
	{\endlist}

\newenvironment{quote}
	{%
		\list
			{}
			{\parsep\parskip \divide\parsep2}
			\item\relax\extractsize    % When this comes before 
	}
	{\endlist}

% These are always 0pt

\setlength\itemsep{\z@}
\setlength\parsep{\z@}
\setlength\partopsep{\z@}

% We want to be able to set this to zero in footnotes and tablenotes

\def\jeea@topsep{\medskipamount}

\def\@listi{%
	\labelsep=0.5em
	\listparindent\@parindent
	\leftmargin\leftmargini
	\setlength\topsep\jeea@topsep % It would be nice if this adapted to the font size
	\ifdim\topsep>\parskip
		\advance\topsep-\parskip
	\else
	  \topsep=\z@
	\fi}
\let\@listI\@listi
\@listi
\def\@listii {\leftmargin\leftmarginii
							\labelwidth\leftmarginii
							\advance\labelwidth-\labelsep
							\topsep    \z@}
\def\@listiii{\leftmargin\leftmarginiii
							\labelwidth\leftmarginiii
							\advance\labelwidth-\labelsep}
\def\@listiv {\leftmargin\leftmarginiv
							\labelwidth\leftmarginiv
							\advance\labelwidth-\labelsep}
% These two are defined even though lists with depth >4 are not supported
\def\@listv  {\leftmargin\leftmarginv
							\labelwidth\leftmarginv
							\advance\labelwidth-\labelsep}
\def\@listvi {\leftmargin\leftmarginvi
							\labelwidth\leftmarginvi
							\advance\labelwidth-\labelsep}

% This % will be overridden by enumitem.sty (and then by us again) but needs to
% be defined before loading that package.

\newenvironment{description}{}{}
\newcommand{\descriptionlabel}{}

% enumitem.sty

\usepackage[shortlabels]{enumitem}

% We tie together the counting of levels for itemize and enumerate
% We allow lists up to 4 levels deep, in case they are being used for outlines
% (but intent is to have max 2 levels in regular text).

\let\@itemdepth\@enumdepth

% 1.75em means that "25." would be flush left.
% (Each digit is 0.5em and the period is 0.25em, plus labelsep=0.5em)

\setenumerate{font=\upshape}
\setenumerate[1]{label=\arabic*.,ref=\arabic*,leftmargin=1.75em,labelsep=0.5em}
\setenumerate[2]{label=(\alph*),ref=\alph*,leftmargin=*,widest=g,labelsep=0.5em}
\setenumerate[3]{label=\roman*.,ref=\roman*,leftmargin=*,widest=iii,labelsep=0.5em}
\setenumerate[4]{label=\Alph.,ref=\Alph*,leftmargin=*,widest=G,labelsep=0.5em}

% Levels 2-4 are identical. The expectation is at most one of these levels is used.
\setitemize[1]{label=\normalfont\textbullet,leftmargin=1.75em,labelsep=0.5em}
\setitemize[2]{label=\normalfont\textendash,
	labelindent=0pt,labelwidth=0.5em,leftmargin=*,labelsep=0.5em}
\setitemize[3]{label=\normalfont\textendash,
	labelindent=0pt,labelwidth=0.5em,leftmargin=*,labelsep=0.5em}
\setitemize[4]{label=\normalfont\textendash,
	labelindent=0pt,labelwidth=0.5em,leftmargin=*,labelsep=0.5em}

% In itemize and enumerate, the depth counter is advance after checking for the depth,
% so maxdepth is actually the true max depth minus 1. Not here.
\renewenvironment{description}[1][]
  {%
    \advance\@enumdepth\@ne
    \enit@description\@enumdepth{desc}{4}{#1}}%  \@enumdepth was \z@,4 was \M@
  {\enit@enddescription}

\setdescription{font=\normalfont\itshape,labelsep=0pt,labelwidth=0pt,
	labelindent=1.75em,leftmargin=1.75em,listparindent=\parindent,itemsep=0pt}

\renewcommand*\descriptionlabel[1]{{\emph{#1\jeea@addperiod}}\kern0.5em}


% In footnotes, we restrict lists to a single level and we use the formatting
% of level-2 lists
\def\@footnotelists{%
  \let\@listI\@listii
  \let\@listi\@listii
  \@listii
  % The only change here (from its def'n in enumitem.sty) is the maximum level is 1
  \renewenvironment{enumerate}[1][]
    {\enit@enumerate\@enumdepth{enum}\z@{##1}}
    {\enit@endenumerate}
  \renewenvironment{itemize}[1][]
    {\enit@itemize\@itemdepth{item}\z@{##1}}
    {\enit@enditemize}
  % This is copied from the \setitemize[2], except margin is set to 2.5em
  \setitemize[1]{label=\normalfont\textendash,
	  labelindent=0pt,labelwidth=0.5em,leftmargin=2.5em,labelsep=0.5em}
	% This is copied from \setenumerate[2], except margin is set to 2.5em
	\setenumerate[1]{label=(\alph*),ref=\alph*,leftmargin=2.5em,labelsep=0.5em}}

\def\@tablenotelists{%
  \@footnotelists
	% Change label from letter to roman because table note markers are letters
	\setenumerate[1]{label=(\roman*),ref=\roman*,leftmargin=2.5em,labelsep=0.5em}}

% Paragraph items

% This is more complicated than it needs to be because we want to allow the
% optional argument from enumitem.sty or enumerate.sty for adding an enumerator.

\newenvironment{paritems}[1][]
  {\ifnum\@enumdepth>0 \@toodeep\fi\@paritems{#1}}
  {\par\addvspace{\medskipamount}}

\@definecounter{paritemi}

\def\@@paritems{%
   \let\enit@before\@empty
   \let\enit@after\@empty
   \let\enit@format\@empty}

\def\@paritems#1{%
  \par
  \def\enit@type{enum}%
  \addvspace{\medskipamount}%
  \def\labelenumi{}%
  \def\@itemlabel{\labelenumi}%
  \def\@enumctr{paritemi}
  \usecounter\@enumctr%
  \let\enit@ref\relax
  \let\enit@saveref\relax
  %\enit@normlabel{\@itemlabel}% Returns \enit@a
  %\expandafter\let\@itemlabel\enit@a
  \let\enit@before\@empty
  \let\enit@after\@empty
  \let\enit@format\@empty
  \enit@setkeys{enit@@paritem}%
  \enit@setkeys{enit@@\@enumctr}%
  \enit@resumeset\enit@shl@enum{#1}}

\def\paritem{%
  \par
  \addvspace{\medskipamount}%
  \refstepcounter{paritemi}
  \ifx\labelenumi\@empty\else{\enit@format\labelenumi}\enspace\fi
  \@ifnextchar[{\@paritem}{}}

\def\@paritem[#1]{%
  \textit{#1\jeea@addperiod}\enspace}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 16. TABLE OF CONTENTSS

% This hasn't been adapted much.

\newcommand\@pnumwidth{1.55em}
\newcommand\@tocrmarg{2.55em}
\newcommand\@dotsep{4.5}
\setcounter{tocdepth}{3}
\newcommand\tableofcontents{%
	
		\section*{\contentsname
				\@mkboth{%
					\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
	\begingroup
		\parskip = 0pt
			\@starttoc{toc}%
	\endgroup}

\newcommand*\l@section[2]{%
	\ifnum \c@tocdepth >\z@
		\addpenalty\@secpenalty
		\addvspace{0.5\linespace \@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
		\endgroup
	\fi}
\newcommand\l@subsection[2]{\@dottedtocline{2}{1.5em}{2.3em}{#1}{#2}}
\newcommand*\l@subsubsection[2]{\@dottedtocline{3}{3.8em}{3.2em}{{\small #1}}{{\small #2}}}

% Eliminate since such entries never appear?
\newcommand*\l@paragraph{\@dottedtocline{4}{7.0em}{4.1em}}
\newcommand*\l@subparagraph{\@dottedtocline{5}{10em}{5em}}

\newcommand\listoffigures{%
		\section*{\listfigurename}%
			\@mkboth{\MakeUppercase\listfigurename}%
							{\MakeUppercase\listfigurename}%
		\@starttoc{lof}%
		}
\newcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand\listoftables{%
		\section*{\listtablename}%
			\@mkboth{%
					\MakeUppercase\listtablename}%
				{\MakeUppercase\listtablename}%
		\@starttoc{lot}%
		}
\let\l@table\l@figure



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 17. INDEX

% Not modfied, not tested: JEEA articles aren't supposed to have indices.

\newenvironment{theindex}
	{\if@twocolumn
			\@restonecolfalse
		\else
			\@restonecoltrue
		\fi
		\twocolumn[\section*{\indexname}]%
		\@mkboth{\MakeUppercase\indexname}%
						{\MakeUppercase\indexname}%
		\thispagestyle{plain}\parindent\z@
		\parskip\z@ \@plus .3\p@\relax
		\columnseprule \z@
		\columnsep 35\p@
		\let\item\@idxitem}
	{\if@restonecol\onecolumn\else\clearpage\fi}
	
\newcommand\@idxitem{\par\hangindent 40\p@}
\newcommand\subitem{\@idxitem \hspace*{20\p@}}
\newcommand\subsubitem{\@idxitem \hspace*{30\p@}}
\newcommand\indexspace{\par \vskip 10\p@ \@plus5\p@ \@minus3\p@\relax}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 18. REFERENCES


\newcommand\refname{References}

\if@jeea@jeeabib

  \newenvironment{thebibliography}{}{}
	\usepackage{natbib}
	\renewcommand\bibname{\refname}
	\renewcommand\bibfont{\refsize}
	\renewcommand\bibhang{12pt}
	\bibpunct{(}{)}{;}{}{}{,}
	\setlength{\bibsep}{1pt}
  \newcommand\newblock{\ }
	\bibliographystyle{jeea}
	
\else

% Otherwise we make no assumptions about the bibliography,
% and simply include the code from article.cls.

	\newdimen\bibindent
	\setlength\bibindent{1.5em}
	\newenvironment{thebibliography}[1]
			{\section*{\refname}%
				\@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
				\list{\@biblabel{\@arabic\c@enumiv}}%
						{\settowidth\labelwidth{\@biblabel{#1}}%
							\leftmargin\labelwidth
							\advance\leftmargin\labelsep
							\@openbib@code
							\usecounter{enumiv}%
							\let\p@enumiv\@empty
							\renewcommand\theenumiv{\@arabic\c@enumiv}}%
				\sloppy
				\clubpenalty4000
				\@clubpenalty \clubpenalty
				\widowpenalty4000%
				\sfcode`\.\@m}
			{\def\@noitemerr
				{\@latex@warning{Empty `thebibliography' environment}}%
				\endlist}
	\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}
	\let\@openbib@code\@empty

\fi


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 19. MISC GENERIC STUFF

% Old compatibility stuff for LaTeX pre-2e:

\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc}
\DeclareRobustCommand*\cal{\@fontswitch\relax\mathcal}
\DeclareRobustCommand*\mit{\@fontswitch\relax\mathnormal}

\newcommand\contentsname{Contents}
\newcommand\listfigurename{List of Figures}
\newcommand\listtablename{List of Tables}
%\newcommand\indexname{Index}  % Defined in natbib
\newcommand\figurename{Figure}
\newcommand\tablename{Table}
\newcommand\partname{Part}
\newcommand\appendixname{Appendix}
\newcommand\abstractname{Abstract}
\newcommand\thanksname{Acknowledgments}

\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}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 20. AMSMATH

\edef\next{\jeea@eqno \if@jeea@fleqn ,fleqn\fi}
\expandafter\RequirePackage\expandafter[\next]{amsmath}

% A patch to amsmath. In the multline environment, \jot adds this
% space before the equation. It is particularly noticeable if we
% increase \jot as a part of double spacing. Requires inserting
% an \everycr{} in the definition of \mmeasure@

% Safest way to do this. First define \next to be the definition
% of \mmeasure@ from amsmath.sty 2.13, 2000/07/18. If it matches
% \mmeasure@, then we redefine \mmeasure@ to include the patch.

% DON'T MODIFY THIS WITHOUT MAKING SURE IT MATCHES AMSMATH.STY

\def\next#1{%
    \begingroup
        \measuring@true
        \def\label##1{%
          \begingroup\measuring@false\label@in@display{##1}\endgroup}%
        \def\math@cr@@@{\cr}%
        \let\shoveleft\@iden \let\shoveright\@iden
        \savecounters@
        \global\row@\z@
        \setbox\@ne\vbox{%
            \global\let\df@tag\@empty
            \halign{%
                \setboxz@h{\@lign$\m@th\displaystyle{}##$}%
                \iftagsleft@
                    \ifnum\row@=\@ne
                        \global\totwidth@\wdz@
                        \global\lineht@\ht\z@
                    \fi
                \else
                    \global\totwidth@\wdz@
                    \global\lineht@\dp\z@
                \fi
                \crcr
                #1%
                \crcr
            }%
        }%
        \ifx\df@tag\@empty\else\global\tag@true\fi
        \if@eqnsw\global\tag@true\fi
        \iftag@
            \setboxz@h{%
                \if@eqnsw
                    \stepcounter{equation}%
                    \tagform@\theequation
                \else
                    \df@tag
                \fi
            }%
            \global\tagwidth@\wdz@
            \dimen@\totwidth@
            \advance\dimen@\tagwidth@
            \advance\dimen@\multlinetaggap
            \iftagsleft@\else
                \if@fleqn
                    \advance\dimen@\@mathmargin
                \fi
            \fi
            \ifdim\dimen@>\displaywidth
                \global\shifttag@true
            \else
                \global\shifttag@false
            \fi
        \fi
        \restorecounters@
    \endgroup
}

\ifx\next\mmeasure@
\def\mmeasure@#1{%
    \begingroup
        \measuring@true
        \def\label##1{%
          \begingroup\measuring@false\label@in@display{##1}\endgroup}%
        \def\math@cr@@@{\cr}%
        \let\shoveleft\@iden \let\shoveright\@iden
        \savecounters@
        \global\row@\z@
        \setbox\@ne\vbox{%
            \global\let\df@tag\@empty
            \everycr{}% ADDED THIS LINE TO KEEP \jot from adding extra space before eqn.
            \halign{%
                \setboxz@h{\@lign$\m@th\displaystyle{}##$}%
                \iftagsleft@
                    \ifnum\row@=\@ne
                        \global\totwidth@\wdz@
                        \global\lineht@\ht\z@
                    \fi
                \else
                    \global\totwidth@\wdz@
                    \global\lineht@\dp\z@
                \fi
                \crcr
                #1%
                \crcr
            }%
        }%
        \ifx\df@tag\@empty\else\global\tag@true\fi
        \if@eqnsw\global\tag@true\fi
        \iftag@
            \setboxz@h{%
                \if@eqnsw
                    \stepcounter{equation}%
                    \tagform@\theequation
                \else
                    \df@tag
                \fi
            }%
            \global\tagwidth@\wdz@
            \dimen@\totwidth@
            \advance\dimen@\tagwidth@
            \advance\dimen@\multlinetaggap
            \iftagsleft@\else
                \if@fleqn
                    \advance\dimen@\@mathmargin
                \fi
            \fi
            \ifdim\dimen@>\displaywidth
                \global\shifttag@true
            \else
                \global\shifttag@false
            \fi
        \fi
        \restorecounters@
    \endgroup
}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 21. BLOCKS

% Unfortunately, it is difficult to adapt amsthm.sty or ntheorem.sty
% to our exact purposes, so we create theorem macros from scratch.
% They are not compatabile with amsthm.sty or ntheorem.sty
%
% We define a specific style and do not attempt to allow easy user
% customization. However, users can suppress the definitions and load,
% e.g., amsthm.sty or ntheorem.sty, by using the notheorems class option.
%
% There are four types of "blocks" or "enunciations".
%
% 1. Theorem  (numbered, labeled, italic body)
% 2. Remark (numbered, labeled, roman body)
% 3. Example (numbered, labeled, roman body, end-of-example symbol)
% 4. Proof (labeled, roman body, end-of-proof symbol)
%
% See the documentation of jeea.cls for explanations of intended uses.

% Remarks and Theorem are identical except for the body font.
% Remarks and Examples are identical except for the end-of-example symbol.


\if@jeea@notheorems\else


%% 21.1 Counters

\def\@thmcounter#1{\noexpand\arabic{#1}} % Formatting of counter

% The rest of this is for resetting counters so that they are numbered within sections
% or appendices. We don't allow for flexibility -- either they are all reset or not.

\def\@thmcounters{}                      % Accumulate list of counters to be reset
\def\@thmcountersep{.}                   % Goes between section number and counter
\def\@thethmcounter#1{\@nameuse{the#1}}  % So it can be redefined to add section numbers

\def\@newthmcounter#1{%
	\xdef\@thmcounters{\@thmcounters#1,}%
	\@definecounter{#1}%
	\expandafter\xdef\csname the#1\endcsname{\@thmcounter{#1}}}

\def\ResetTheorems#1{%
	\ifx\@thmcounters\@empty\else
		\def\next{\@ResetTheorems{#1}}%
		\expandafter\next\@thmcounters\@nil
	\fi}

% \AddToReset is defined in section on counters.

\def\@ResetTheorems#1#2,{%
	\AddToReset{#2}{#1}%
	\@ifnextchar\@nil{\@gobble}{\@ResetTheorems{#1}}}


%% 21.2 Basics common to all types

% Internal syntax:
%   \jeea@block{type}{counter}{head}[extra label]
%   ...
%   \jeea@endblock{type}

% Beginning of a theorem

\def\jeea@block#1#2#3{%
	\@ifnextchar[%
		{\jeea@@block{#1}{#2}{#3}}
		{\jeea@@block{#1}{#2}{#3}[]}%
	}

\def\jeea@@block#1#2#3[#4]{%
	\startblock@all
	\csname startblock@#1\endcsname{#2}{#3}{#4}%
	\ignorespaces}%
	
% End of a theorem

\def\end@jeeablock#1{%
	\csname endblock@#1\endcsname
	\endblock@all}


% This comes from amsthm.sty. Not sure about it.

\newtoks\dth@everypar
\dth@everypar={%
	\@minipagefalse \global\@newlistfalse
	\@noparitemfalse
	\if@inlabel
		\global\@inlabelfalse
		\begingroup \setbox\z@\lastbox
		\ifvoid\z@ \kern-\itemindent \fi
		\endgroup
		\unhbox\@labels
	\fi
	\if@nobreak \@nobreakfalse \clubpenalty\@M
	\else \clubpenalty\@clubpenalty \everypar{}%
	\fi
}%
\let\adjust@parskip@nobreak=\@nbitem

\def\startblock@all{%
	\trivlist
	\thm@skip@setup
	\if@nobreak
		\adjust@parskip@nobreak
	\else
		\addpenalty\@beginparpenalty
		\addvspace\@topsep
		\addvspace{-\parskip}%
	\fi
	\global\@inlabeltrue
	\everypar\dth@everypar
	\item[]\normalfont}

% This is adding the \linespace (with some rubber size) before/after the theorem.

\newskip\theoremskip
\theoremskip = \linespace \@plus 0.2\linespace minus 0.1\linespace
\advance\theoremskip-\parskip
\ifdim\theoremskip<0pt \theoremskip=\z@ \@plus 2pt \fi

\def\thm@skip@setup{%
  	\@topsep=\theoremskip
	\@topsepadd=\@topsep}

\def\endblock@all{%
	\endtrivlist
	\@endpefalse}


%% 21.3. Set up of the different types.

% Then each theorem type has to define two commands:
%
%   \startblock@<type>{counter}{head}{extra label}
%   \endblock@<type>
%
% Counter is empty if block is unnumbered; extra label is empty if there is none.
%
% This should be implemented using amsthm.sty and thmtools.sty, but that will
% be for another day.
% Advantages: Compatibility with authors' source files; use of \qedhere

\def\@makethmhead#1#2#3#4#5{%
	\def\@tempa{#1}%
	\ifx\@tempa\@empty\else
		\refstepcounter{#1}%
	\fi
	\noindent{\jeea@blocklabelfont #2\ifx\@tempa\@empty\else~\@thethmcounter{#1}\fi}%
	\def\@tempa{#3}%
	\ifx\@tempa\@empty\else
		\kern 0.5em ({#4#3})%
	\fi
	.\kern 0.75em #5}

% Type = thm

\def\startblock@thm#1#2#3{\@makethmhead{#1}{#2}{#3}{\upshape}{\itshape}}
\def\endblock@thm{}

% Type = rmk

\def\startblock@rmk#1#2#3{\@makethmhead{#1}{#2}{#3}{\itshape}{\upshape}}
\def\endblock@rmk{}

% Type = exm

\def\startblock@exm#1#2#3{%
  \let\@qedsymbol\exmsymbol
  \pushQED{\qed}%
  \@makethmhead{#1}{#2}{#3}{\itshape}{\upshape}}
\def\endblock@exm{\popQED}
\def\exmsymbol{$\blacksquare$}

% Type = proof

\def\startblock@proof#1#2#3{%
	\let\@qedsymbol\qedsymbol
	\pushQED{\qed}%
	\def\@tempa{#3}%
	\ifx\@tempa\@empty\def\@tempa{#2}\fi
	\noindent{\itshape \@tempa.}%
	\kern .75em}
\def\endblock@proof{\popQED}
\def\qedsymbol{$\square$}

% Ad hoc versions; no counter.

\def\adhoctheorem#1{\jeea@block{thm}{}{#1}}%
\def\endadhoctheorem{\end@jeeablock{thm}}

\def\adhocremark#1{\jeea@block{rmk}{}{#1}}%
\def\endadhocremark{\end@jeeablock{rmk}}

\def\adhocexample#1{\jeea@block{exm}{}{#1}}%
\def\endadhocexample{\end@jeeablock{exm}}


%% 21.4. Interface for creating new theorems.

% For creating numbered blocks:
% \newnumberedblock{type}{envname}[counter]{label}
%
% No checking to see if command already defined; just overwrite old def.

\def\newnumberedblock#1#2{%
	\@ifnextchar[{\@oblock{#1}{#2}}{\@nblock{#1}{#2}}}
	
% Has own counter
\def\@nblock#1#2#3{%
	\@newthmcounter{#2}%
	\global\@namedef{#2}{\jeea@block{#1}{#2}{#3}}%
	\global\@namedef{end#2}{\end@jeeablock{#1}}}
		
% Uses the counter [#3]
\def\@oblock#1#2[#3]#4{%
	\@ifundefined{c@#3}{\@nocounterr{#3}}{%
		\global\@namedef{the#2}{\@nameuse{the#3}}%
		\global\@namedef{#2}{\jeea@block{#1}{#3}{#4}}%
		\global\@namedef{end#2}{\end@jeeablock{#1}}%
	}}

\def\newunnumberedblock#1#2#3{%
	\global\@namedef{#2}{\jeea@block{#1}{}{#3}}%
	\global\@namedef{end#2}{\end@jeeablock{#1}}}

\def\newtheorem{\@ifstar{\newunnumberedblock{thm}}{\newnumberedblock{thm}}}
\def\newremark{\@ifstar{\newunnumberedblock{rmk}}{\newnumberedblock{rmk}}}
\def\newexample{\@ifstar{\newunnumberedblock{exm}}{\newnumberedblock{exm}}}

\def\newproof#1#2{%
	\global\@namedef{#1}{\jeea@block{proof}{}{#2}}%
	\global\@namedef{end#1}{\end@jeeablock{proof}}}

\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}
\newtheorem{conjecture}{Conjecture}

\newremark{assumption}{Assumption}
\newremark{axiom}{Axiom}
\newremark{definition}{Definition}
\newremark{remark}{Remark}

\newexample{example}{Example}

\newproof{proof}{Proof}


% 21.5 QED

% This is copied from amsthm.sty, then modified to be compatible
% Pretty complicated for its simple purpose, and I'm not sure even why
% it works, especially the way it gets the choice of \exmsmbol and \qedsymbol right.

\let\@nx\noexpand

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

\let\QED@stack\@empty
\let\qed@elt\relax

\newcommand{\pushQED}[1]{%
  \toks@{\qed@elt{#1}}%
  \@temptokena\expandafter{\QED@stack}%
  \xdef\QED@stack{\the\toks@\the\@temptokena}}

\newcommand{\popQED}{%
  \begingroup
    \let\qed@elt\popQED@elt
    \QED@stack\relax\relax
  \endgroup}

\def\popQED@elt#1#2\relax{#1\gdef\QED@stack{#2}}

\newcommand{\qedhere}{%
  \begingroup
    \let\mathqed\math@qedhere
    \let\qed@elt\setQED@elt
    \QED@stack\relax\relax
  \endgroup}

% These are defined in amsmathy.sty
%\newif\ifmeasuring@
%\fi\show\iffirstchoice@
\firstchoice@true

\def\setQED@elt#1#2\relax{%
  \ifmeasuring@\else
    \iffirstchoice@ \gdef\QED@stack{\qed@elt{}#2}\fi
  \fi
  #1}

\def\qed@warning{%
  \JEEA@Warning{The \string\qedhere\space command may not work correctly here.}}

\newcommand{\mathqed}{\quad\hbox{\@qedsymbol}}

\def\linebox@qed{\hfil\hbox{\@qedsymbol}\hfilneg}

% Didn't touch this at all except to replace \qedsymbol by \@qedsymbol

\@ifpackageloaded{amsmath}{%
  \def\math@qedhere{%
    \@ifundefined{\@currenvir @qed}{%
      \qed@warning\quad\hbox{\@qedsymbol}%
    }{%
      \@xp\aftergroup\csname\@currenvir @qed\endcsname
    }%
  }
  \def\displaymath@qed{%
    \relax
    \ifmmode
      \ifinner \aftergroup\linebox@qed
      \else
        \eqno
        \let\eqno\relax \let\leqno\relax \let\veqno\relax
        \hbox{\@qedsymbol}%
      \fi
    \else
       \aftergroup\linebox@qed
    \fi
  }
  \@xp\let\csname equation*@qed\endcsname\displaymath@qed
  \def\equation@qed{%
    \iftagsleft@
      \hbox{\phantom{\quad\@qedsymbol}}%
      \gdef\alt@tag{%
        \rlap{\hbox to\displaywidth{\hfil\@qedsymbol}}%
        \global\let\alt@tag\@empty
      }%
    \else
      \gdef\alt@tag{%
        \global\let\alt@tag\@empty
        \vtop{\ialign{\hfil####\cr
                \tagform@\theequation\cr
                \@qedsymbol\cr}}%
        \setbox\z@
      }%
    \fi
  }
  \def\qed@tag{%
    \global\tag@true \nonumber
    &\omit\setboxz@h {\strut@ \@qedsymbol}\tagsleft@false
    \place@tag@gather
    \kern-\tabskip
    \ifst@rred \else \global\@eqnswtrue \fi \global\advance\row@\@ne \cr
  }
  \def\split@qed{%
    \def\endsplit{\crcr\egroup \egroup \ctagsplit@false \rendsplit@
      \aftergroup\align@qed
    }%
  }
  \def\align@qed{%
    \ifmeasuring@ \tag*{\@qedsymbol}%
    \else \let\math@cr@@@\qed@tag
    \fi
  }
  \@xp\let\csname align*@qed\endcsname\align@qed
  \@xp\let\csname gather*@qed\endcsname\align@qed
%% Needs some patching up for amsmath 1.2
}{% end of amsmath branch, start plain LaTeX branch
  \def\math@qedhere{%
    \@ifundefined{\@currenvir @qed}{%
      \qed@warning \aftergroup\displaymath@qed
    }{%
      \@xp\aftergroup\csname\@currenvir @qed\endcsname
    }%
  }
  \def\displaymath@qed{%
    \relax
    \ifmmode
      \ifinner \aftergroup\aftergroup\aftergroup\linebox@qed
      \else
        \eqno \def\@badmath{$$}%
        \let\eqno\relax \let\leqno\relax \let\veqno\relax
        \hbox{\@qedsymbol}%
      \fi
    \else
       \aftergroup\linebox@qed
    \fi
  }
  \@ifundefined{ver@leqno.clo}{%
    \def\equation@qed{\displaymath@qed \quad}%
  }{%
    \def\equation@qed{\displaymath@qed}%
  }
  \def\@tempa#1$#2#3\@nil{%
    \def\[{#1$#2\def\@currenvir{displaymath}#3}%
  }%
  \expandafter\@tempa\[\@nil
}
\@ifpackageloaded{amstex}{%
  \def\@tempa{TT}%
}{%
  \@ifpackageloaded{amsmath}{%
    \def\@tempb#1 v#2.#3\@nil{#2}%
    \ifnum\@xp\@xp\@xp\@tempb\csname ver@amsmath.sty\endcsname v0.0\@nil
       <\tw@
      \def\@tempa{TT}%
    \else
      \def\@tempa{TF}%
    \fi
  }{%
    \def\@tempa{TF}
  }%
}
\if\@tempa
  \renewcommand{\math@qedhere}{\quad\hbox{\@qedsymbol}}%
\fi

\fi  % This ends \if@jeea@notheorems\else ...


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 23. MISC MATH STUFF

%% 23.1 ubar

\RequirePackage{ubar}

%% 23.2. Variable names

\define@choicekey*{jeea}{vnstyle}[\val\nr]
	{up,it,sc,fakesc}
	{\expandafter\let\expandafter\@vn\csname vn@\val\endcsname}
\def\vnstyle#1{\setkeys{jeea}{vnstyle=#1}}

\def\vn@up#1{\textup{#1}}
\def\vn@it#1{\textit{#1}}
\def\vn@sc#1{\textsc{\lowercase{#1}}}
\def\vn@fakesc#1{\scalebox{0.8}[0.75]{\textsc{\uppercase{#1}}}}

\def\vn{\@ifnextchar[{\@@vn}{\@vn}}

\def\@@vn[#1]#2{{\vnstyle{#1}\@vn{#2}}}

\vnstyle{it}


%% 23.3. Vertical bar in conditional expectation, probability

% \mathbin
\mathchardef\cond="226A



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 25. graphicx

% Is it a good idea to include graphicx? What if incompatable?

\RequirePackage{graphicx}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 26. url.sty

% Is it a good idea to include url? What if incompatable?

\RequirePackage{url}
\urlstyle{same}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 27. READY TO GO

\ifarticlecomp
	\pagestyle{plain}
\else
	\pagestyle{jeea}
\fi
\pagenumbering{arabic}
\if@twoside
	\flushbottom
\else
	\raggedbottom
\fi
\onecolumn

\frenchspacing  % Suppresses the extra space after period, colon.
\normalsize

\endinput

%%
%% End of file `jeea.cls'.
