%& -no-cctspace
%
% $Id: jcmlatex.cls,v 1.22 2009/06/24 03:20:20 zlb Exp $
%
% Changelog:
%
% - 2009/06/19: add DOI (Ada)
% - 2009/02/13: don't show the 'Received' line if \JCMreceived is empty
%	(for special issues, Li Jing)
% - 2008/02/21: add `Accepted' (Li Jing)
% - 2008/02/02: add the `cite' package
% - 2008/02/01: fix a pages range issue
% - 2008/01/30: fix a bug in jcmlatex.bst
% - 2007/08/29: reformat 'Received ...' line (Li Jing)
% - 2007/08/21: new title page
% - 2007/06/18: set default class option to 'final'
% - 2007/05/05: change \and to produce `and' in \author{...}
% - 2007/05/04: call \ps@firstpage also for draft mode, use \affiliation
%       instead of \thanks in \author{}, add jcmlatex.bst
% - 2007/01/19: prevent linebreak between title and fnmarks
% - 2006/09/07: created the file
%

\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesClass{jcmlatex}[2009/06/19, Journal of Computational Mathematics]

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass[a4paper,twoside]{article}[1996/10/31]
\pagestyle{myheadings}

% Class options
% Options 'draft' and 'final'
\newif\ifdraft \draftfalse
\DeclareOption{draft}{\drafttrue}
\DeclareOption{final}{\draftfalse}
\ProcessOptions

\RequirePackage{cite}
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{amssymb}

%--------------------------- Page Format --------------------------
\headsep=5mm
\headheight=5mm
\topmargin=0pt
\oddsidemargin=0pt
\evensidemargin=0pt
\textheight=215truemm
\textwidth=145truemm
\footskip=2truemm
\renewcommand{\baselinestretch}{1.10}
\renewcommand{\arraystretch}{1.0}

\abovedisplayskip=6pt plus 2pt minus 2.5pt 
\belowdisplayskip=6pt plus 2pt minus 2.5pt

%========================= Floats, tables, figures =================
\renewcommand{\floatpagefraction}{1}
\floatsep=10pt plus 2.5pt minus 1pt
\textfloatsep=10pt plus 2.5pt minus 1pt
\intextsep=10pt plus 2.5pt minus 1pt
\doublerulesep=0pt

\abovecaptionskip=3pt
\belowcaptionskip=5pt

%
% Insert \small and remove colon after table/figure number
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \small
  \sbox\@tempboxa{#1 #2}%
  \ifdim \wd\@tempboxa >\hsize
    #1 #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

\@addtoreset{table}{section}
\renewcommand\thetable{\thesection.\arabic{table}}
\def\fnum@table{\tablename\nobreakspace\thetable:}

\@addtoreset{figure}{section}
\renewcommand\thefigure{\thesection.\arabic{figure}}
\renewcommand\figurename{Fig.}
\def\fnum@figure{\figurename\nobreakspace\thefigure.}

%======================== Section ===============================
\def\@seccntformat#1{\csname the#1\endcsname. }
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                     %%%{-3.5ex \@plus -1ex \@minus -.2ex}%
                                     {3.5ex \@plus 1ex \@minus .2ex}%
                                     {2.3ex \@plus.2ex}%
                                     {\normalfont\large\bfseries\centering}}
\renewcommand\subsection{\@startsection {subsection}{2}{\z@}%
                                        %%%{-3.25ex\@plus -1ex \@minus -.2ex}%
                                        {3.25ex\@plus 1ex \@minus .2ex}%
                                        {1.5ex \@plus .2ex}%
                                        {\normalfont\normalsize\bfseries}}

%======================== Bibliography ===============================
\renewcommand\@openbib@code{\parsep \z@ \itemsep \z@ \parskip \z@ \small}
\bibliographystyle{jcmlatex}

%======================== Equation ===================================
\@addtoreset{equation}{section}
\renewcommand\theequation{\thesection.\arabic{equation}}

%======================== Theorem, Lemma, etc., and proof ============
\def\@begintheorem#1#2{\trivlist
   \item[\hskip \labelsep{\bfseries #1\ #2.}]\itshape}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{proposition}{Proposition}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{remark}{Remark}[section]
\newtheorem{definition}{Definition}[section]
\newtheorem{condition}{Condition}[section]
\newtheorem{example}{Example}[section]
\newtheorem{conclusion}{Conclusion}[section]
\newtheorem{algorithm}{Algorithm}[section]
\newtheorem{assumption}{Assumption}[section]
\newenvironment{proof} {\par{\it Proof.} \ignorespaces} {\par\medskip}

%===========================================================================

\AtBeginDocument{\label{firstpage}}
%
% The following trick, borrowed from TUGBoat Vol. 19 (1998) No. 1, is
% to prevent \label{lastpage} from disappearing when last page is full.
% (http://www.tug.org/TUGboat/Articles/tb19-1/tb58works.pdf)
\AtEndDocument{\clearpage
  \addtocounter{page}{-1}%
  \immediate\write\@auxout{\string\newlabel{lastpage}{{}{\thepage}}}%
  \addtocounter{page}{1}}

\newenvironment{keywords}
  {\leftskip\leftmargin \rightskip\leftskip
   \noindent\small
   \textit{Key words:} %
   \ignorespaces}
  {\par}

\newenvironment{classification}
  {\leftskip\leftmargin \rightskip\leftskip
   \noindent\small
   \textit{Mathematics subject classification:} %
   \ignorespaces}
  {\par}

% FIXME: why need to insert a space (but not within \maketitle)?
\@addtoreset{footnote}{page}
\renewcommand\thefootnote{\arabic{footnote}) }%
\renewcommand\maketitle{\par
  \begingroup
    \ifdraft
      \renewcommand\thefootnote{\arabic{footnote})}%
    \else
      \c@footnote\m@ne
      \renewcommand\thefootnote{\ifnum\c@footnote=0\relax*\else
         \@arabic\c@footnote)\fi}%
    \fi
    \def\@makefnmark{\hbox{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark} }##1}%
    \newpage
    \global\@topnum\z@   % Prevents figures from going at top of page.
    \@maketitle 
    \thispagestyle{firstpage}%
    \@thanks
  \endgroup
  %%%\setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}

\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  {\centering
    {% Insert 'Received ...'
     \let\thanks@bak\thanks
     \def\thanks{\protect\thanks@bak}%
     \def\thanks@tmp{%
        \ifx\thanks@bak\thanks@old\else
	  % Note: don't show the 'Received' line if \JCMreceived is empty
	  \edef\@tempb{\JCMreceived}%
	  \ifx\@tempb\@empty\else
            \edef\@tempa{\JCMrevised}%
            % prevent line break between title and \thanks
            {\skip0=\lastskip\unskip\nobreak\hskip\skip0}%
            \ifx\@tempa\@empty
              \thanks@old{Received \JCMreceived \;/ Accepted \JCMaccepted \;/}%
            \else
              \thanks@old{Received \JCMreceived \;/ Revised version received
              \JCMrevised \;/ Accepted \JCMaccepted \;/}%
            \fi
            \global\@datestrue\let\thanks@bak\thanks@old
	  \fi
        \fi
        \thanks@bak}
     \newif\if@dates \@datesfalse
     \ifdraft\else
        \let\thanks@old\thanks@bak
        \def\thanks@bak{\thanks@tmp}%
     \fi
     \let \footnote \thanks
     %%%{\large\textbf{\MakeUppercase{\@title}}}%
     {\large\textbf{\@title}}%
     \ifdraft\else
       \if@dates\else
	 % Note: don't show the 'Received' line if \JCMreceived is empty
	 \edef\@tempb{\JCMreceived}%
	 \ifx\@tempb\@empty\else
           \edef\@tempa{\JCMrevised}%
	   \ifx\@tempa\@empty
             \thanks@old{Received \JCMreceived \;/ Accepted \JCMaccepted \;/}%
           \else
             \thanks@old{Received \JCMreceived \;/ Revised version received
                \JCMrevised \;/ Accepted \JCMaccepted \;/}%
           \fi
         \fi
       \fi
     \fi
     \par}%
    \vskip 1.5em%
    \let \footnote \thanks
    {\small
     \def\affiliation##1{\\{\it ##1}\/\par}%
     \def\and{\ifvmode \else {and }\fi}%
     \let \thanks \affiliation
     \@author
    }%
  \par}}

\ifx\DOI\@undefined\def\DOI{??}\fi
\ifx\JCMvol\@undefined\def\JCMvol{??}\fi
\ifx\JCMno\@undefined\def\JCMno{?}\fi
\ifx\JCMyear\@undefined\def\JCMyear{200?}\fi
\ifx\JCMreceived\@undefined\def\JCMreceived{???? ??, 200?}\fi
\ifx\JCMrevised\@undefined\def\JCMrevised{???? ??, 200?}\fi
\ifx\JCMaccepted\@undefined\def\JCMaccepted{???? ??, 200?}\fi

\newcommand\ps@firstpage{%
  \def\@oddhead{\parbox{7cm}{\small
    Journal of Computational Mathematics\\
    Vol.\JCMvol, No.\JCMno, \JCMyear,
    \pageref{firstpage}--\pageref{lastpage}.\hfill}\hfil
    \parbox{4.8cm}{\small http://www.global-sci.org/jcm\\doi:\DOI}}%
  \let\@evenhead\@oddhead}

\renewcommand\markboth[2]{%
  \def\@evenhead{\thepage\hfill {\footnotesize\rm #1}}%
  \def\@oddhead{{\footnotesize\rm #2}\hfill \thepage}%
}

\markboth{Journal of Computational Mathematics}
     {Journal of Computational Mathematics}

\endinput
