  %*************************************************************%
  %*                                                           *%
  %*     Prepared by Gerald Banon                              *%
  %*     Instituto Nacional de Pesquisas Espaciais (INPE)      *% 
  %*     Copyright 2007 © INPE                                 *%
  %*     All rights reserved.                                  *%
  %*                                                           *%
  %*************************************************************%
  
\NeedsTeXFormat{LaTeX2e} 
\ProvidesClass{ISMM2007proceedings}[2007/03/18 ISMM2007 proceedings class]
\LoadClassWithOptions{book}

\RequirePackage[T1]{fontenc}
%\RequirePackage[latin1]{inputenc}
\RequirePackage[pagestyles]{titlesec}	% needed for \titleformat
\RequirePackage{titletoc}	% needed for \titlecontents

\RequirePackage{calc}
\RequirePackage{caption}

%\RequirePackage{multicol}

% Declare option
\newif\if@amsoption\@amsoptionfalse
\DeclareOption{ams}{\@amsoptiontrue}

\newif\if@fullpaper\@fullpapertrue	% full paper
\DeclareOption{extendedabstract}{\@fullpaperfalse}

\newif\if@editoroption\@editoroptionfalse
\DeclareOption{editor}{\@editoroptiontrue}

\DeclareOption{oneside}{\@twosidefalse \@mparswitchfalse}

% Declare caption
\DeclareOption{capstya}{%
	\renewcommand{\arraystretch}{1.1}
	\captionsetup{%
		%format=hang,
		font={small},
		labelfont={it},
		labelsep=period,
		position=top,
		aboveskip=12pt,
		belowskip=0pt
	}%
	\captionsetup[table]{%
		position=above
	}%
	\captionsetup[longtable]{%
		position=above
	}%
}
% Declare caption - end
% Declare option - end

\renewcommand\thefigure{\@arabic\c@figure}
\renewcommand\thetable{\@arabic\c@table}

\renewcommand\footnoterule{}	% draw no rule

\ExecuteOptions{capstya}	% default options

\ProcessOptions

\if@editoroption
% part
	\renewcommand{\part}{
		\cleardoublepage
		\thispagestyle{empty}
		\renewcommand{\thepart}{\Roman{part}}
		\secdef\cmda@part\cmdb@part
	}
	\newcommand{\cmda@part}[2][?]{%
		\refstepcounter{part}%
		\addcontentsline{toc}{part}{\protect\numberline{\thepart} #1}
		\begin{flushleft}\Large\thepart\vspace{6mm}\par\huge\uppercase{#2}\end{flushleft}
	}
	\newcommand{\cmdb@part}[1]{#1}	% not used
\fi

\if@editoroption
% Table of Contents
	\newskip\tocpartskip
	\tocpartskip=8pt plus1pt

	\renewcommand{\l@part}[2]{%
		\vskip\tocpartskip
%		\begingroup
			\setlength\@tempdima{1em}%
			\parindent \z@ \rightskip \@pnumwidth
			\parfillskip -\@pnumwidth
			{\leavevmode\vskip1pt Part #1\hfil \hbox to\@pnumwidth{\hss}}
			\par
			\nobreak
			\global\@nobreaktrue
			\everypar{\global\@nobreakfalse\everypar{}}
%		\endgroup
	}

	\titlecontents{chapter}[0cm]
		{\vspace{0.3cm}}
		{}
		{}
		{\hfill\contentspage}
	
	\newcommand{\l@author}[2]{\vspace{-3.5mm}\small\begin{flushleft}\textit{#1}\end{flushleft}}
% Table of Contents - end
\fi

% Front and main matter
\let\Old@cleardoublepage\cleardoublepage
\renewcommand{\cleardoublepage}{%
	\clearpage
	\thispagestyle{empty}%
	\Old@cleardoublepage
}
\renewcommand\frontmatter{%
	\cleardoublepage
	\pagestyle{frontmatter}%
	\pagenumbering{roman}%
}
\if@editoroption
	\renewcommand\mainmatter{%
		\cleardoublepage
		\pagestyle{fullpaper}%
		\pagenumbering{arabic}%
	}
\fi
% Front and main matter - end

\newcommand{\ShortBookTitle}[1]{\gdef\Short@BookTitle{#1}}
\newcommand{\EditorsTitle}[1]{\gdef\Editors@Title{#1}}

% Page styles
% \newpagestyle command is defined in the titlesec package
% \newpagestyle{ name }[ global-style ]{ commands }
% \sethead[ even-left ][ even-center ][ even-right ]{ odd-left }{ odd-center }{ odd-right }
\newpagestyle{fullpaper}[\small\itshape]{
	\sethead[\textup{\thepage}][][\Short@BookTitle]{\chaptertitle}{}{\textup{\thepage}}
}%
\newpagestyle{fullpapertitlepage}[\scriptsize\sffamily]{
	\setfoot
		{}
		{%
			\parbox{\hsize}{%
				\begin{center}\small\textup{\thepage}\end{center}
				\textit{\Editors@Title},
				\expandafter\ifx\csname runTWO@\roman{FullPaperNumber}\endcsname\relax
					\,\csname runONE@\roman{FullPaperNumber}\endcsname
				\else
					\,\csname runTWO@\roman{FullPaperNumber}\endcsname
				\fi
				\\*%
				\copyright2007 INPE. Printed in Brazil.%
			}%
		}
		{}%
}%
\newpagestyle{frontmatter}[\small\itshape]{%
	\sethead%
		[\textup{\thepage}]%
		[]%
		[]%
		{}%
		{}%
		{\textup{\thepage}}%
	\setfoot{}{}{}%
}%
% Page styles - end

\if@amsoption
	\RequirePackage{amsmath}
	\RequirePackage{amssymb}
	\RequirePackage{amsthm}
	\theoremstyle{plain}
	\newtheorem{theorem}{Theorem}[section]
	\newtheorem{lemma}{Lemma}[section]
	\newtheorem{proposition}{Proposition}[section]
	\newtheorem{corollary}{Corollary}[section]
	\theoremstyle{definition}
	\newtheorem{definition}{Definition}[section]
	\newtheorem{example}{Example}[section]
	\theoremstyle{remark}
	\newtheorem{remark}{Remark}[section]
	\newtheorem{note}{Note}[section]
\fi

\def\Natural{{\ensuremath \mathbb{N}}}
\def\Integer{{\ensuremath \mathbb{Z}}}
\def\Rational{{\ensuremath \mathbb{Q}}}
\def\Real{{\ensuremath \mathbb{R}}}
\def\Complex{{\ensuremath \mathbb{C}}}

% mathenum
\newenvironment{mathenum}{%
	\begingroup
		\renewcommand{\theenumi}{\roman{enumi}}%
		\renewcommand{\labelenumi}{{\normalfont\upshape(\theenumi)}}%
		\renewcommand{\theenumii}{\alph{enumii}}%
		\renewcommand{\labelenumii}{{\normalfont\upshape(\theenumii)}}%
		\begin{enumerate}
			\vskip-\topsep\vskip-\parskip
			\topsep5pt\itemsep2pt%
			\parsep1pt\parskip0pt%
			\vskip\topsep\vskip\parskip
}{%
		\end{enumerate}
	\endgroup
}

%\normalsize
\voffset=-1in
\hoffset=-1in

% Page style parameters
\if@fullpaper\else
	\setlength{\columnsep}{16pt}	% for two columns
\fi

% textwidth
\if@fullpaper
	\setlength{\textwidth}{115mm}
\else
	\setlength{\textwidth}{165mm}
\fi

% oddsidemargin
% evensidemargin
\newlength{\both@margins}
\setlength{\both@margins}{-\textwidth}
\advance\both@margins\paperwidth

\if@editoroption
% twoside
	\setlength{\oddsidemargin}{.34\both@margins}
	\setlength{\evensidemargin}{.66\both@margins}
\else
% oneside
	\setlength{\oddsidemargin}{.5\both@margins}
	\setlength{\evensidemargin}{.5\both@margins}
\fi

% textheight
\if@fullpaper
	\setlength{\textheight}{190mm}
\else
	\setlength{\textheight}{230mm}
\fi

% topmargin
\setlength{\topmargin}{-\textheight}
\advance\topmargin\paperheight

% headheight
\setlength{\headheight}{12pt}
\advance\topmargin-\headheight

% headsep
\setlength{\headsep}{16pt}
\advance\topmargin-\headsep

% footskip
\setlength{\footskip}{28pt}
\addtolength{\skip\footins}{16pt}
\advance\topmargin-\footskip

\setlength{\topmargin}{.4\topmargin}
% Page style parameters - end

\newcommand{\email}[1]{{\ttfamily#1}}

% Page List
\if@editoroption
	\newcounter{FullPaperNumber}
	\setcounter{FullPaperNumber}{0}
	\input{pagelist}
\fi
% Page List - end

% Title
\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\titleformat%
	{\chapter}%
	{\normalfont\fontseries{b}\LARGE}% the declarations that are applied to the whole title
	{}% the heading number
	{0pt}% the distance between the label and title text
	{}% code executed immediately preceding the heading text
	[%
		\if@editoroption
			\thispagestyle{fullpapertitlepage}%
			\xdef\FullPaperFirstPage{\thepage}%
		\else
			\thispagestyle{empty}%
		\fi
		\vspace{12dd plus 4dd minus 4dd}%
	]
% Title - end


% Authors and institutions
\newcounter{author@number}
\newcounter{nextauthor@number}
\newcounter{numberOf@authors}

\newcounter{institution@number}
\newcounter{numberOf@institutions}

\newcounter{foot@note}

\newcommand{\afootnote}[1]{
	\stepcounter{foot@note}%
	\protect\ftnote{\fnsymbol{foot@note}}{#1}%
}

\newcommand*{\ftnote}[1]{\ftnotemark{#1}\@footnotetext}
\newcommand*{\ftnotemark}[1]{\foot@makemark{#1}\@footnotemark}

\def\foot@makemark#1{\def\@tempa{#1}%
	\ifx\@tempa\@empty\else
		\begingroup
			\unrestored@protected@xdef\@thefnmark{#1}%
		\endgroup
	\fi
}

\def\Author@List{}
\def\Author@ListForOneInstitutionOnly{}

\newenvironment{Authors}{%
%	\begingroup
	\normalfont\normalsize\raggedright
	\parindent0pt
	\setcounter{numberOf@authors}{0}%
	\setcounter{numberOf@institutions}{0}% needed when running \Affilref
	\if@editoroption
		\csname authorR\roman{FullPaperNumber}\endcsname% indexing author name
	\fi
}{%
	{%
		\setcounter{author@number}{0}%
		\ifnum\value{numberOf@institutions}=1%
% one institution only
			\setcounter{institution@number}{0}%
			\Author@ListForOneInstitutionOnly
		\else
% more than one institution
			\setcounter{institution@number}{0}%
			\Author@List
		\fi
		\par
		\vspace{8dd plus 2dd minus 2dd}%
		\if@editoroption
			\setcounter{author@number}{0}%
			\addcontentsline{toc}{author}{\csname authorListR\roman{FullPaperNumber}\endcsname}
		\fi
	}%
	{%
		\slshape\footnotesize
		\ifnum\value{numberOf@institutions}=1%
			\Institution@ListForOneInstitutionOnly
		\else
			\setcounter{institution@number}{0}%
			\Institution@List
		\fi
		\par
		\vspace{6dd plus 2dd minus 2dd}%
	}%
%	\endgroup
	\gdef\Author@List{}% empty out Author@List for next use
	\gdef\Author@ListForOneInstitutionOnly{}% empty out Author@ListForOneInstitutionOnly for next use
	\gdef\Institution@List{}% empty out Institution@List for next use
	\gdef\Institution@ListForOneInstitutionOnly{}% empty out Institution@ListForOneInstitutionOnly for next use
}

% Author list
\def\computeSeparator@forAuthorList{%
	\addtocounter{author@number}{1}%
	\ifnum\value{author@number}=1%
% first author - nothing to do
	\else
% not the first author
		\ifnum\value{author@number}=\value{numberOf@authors}%
% last author
			\ and\ %
		\else
% not the last author
			,\ %
		\fi
	\fi
}

\newcommand{\Author}{%
	\@ifnextchar[%
		{\Author@withfootnote}%
		{\Author@withoutfootnote}%
}

\def\Author@withfootnote[#1]#2{%
	\stepcounter{numberOf@authors}%
	\g@addto@macro{\Author@List}{%
		\computeSeparator@forAuthorList
		\mbox{\textsc{#2}}% author name
		\afootnote{#1}% footnote
		\gdef\superscript@separator{\textsuperscript{,}\hspace{1pt}}%
	}%
	\g@addto@macro{\Author@ListForOneInstitutionOnly}{%
		\computeSeparator@forAuthorList
		\mbox{\textsc{#2}}% author name
		\afootnote{#1}% footnote
	}%
}

\def\Author@withoutfootnote#1{%
	\stepcounter{numberOf@authors}%
	\g@addto@macro{\Author@List}{%
		\computeSeparator@forAuthorList
		\mbox{\textsc{#1}}% author name
		\gdef\superscript@separator{}%
	}%
	\g@addto@macro{\Author@ListForOneInstitutionOnly}{%
		\computeSeparator@forAuthorList
		\mbox{\textsc{#1}}% author name
	}%
}
% Author list - end

% Institution list
\def\Institution@List{}
\def\Institution@ListForOneInstitutionOnly{}

\newcommand{\Affil}[2][\@empty]{%
	\stepcounter{numberOf@institutions}%
	\def\optional@argument{#1}
	\ifx\optional@argument\@empty\else
		\expandafter\edef\csname key@#1\endcsname{\arabic{numberOf@institutions}}%
	\fi
	\g@addto@macro{\Author@List}{%
		\stepcounter{institution@number}%
		\superscript@separator%
		\textsuperscript{\arabic{institution@number}}%
	}
	\g@addto@macro{\Institution@List}{%
		\stepcounter{institution@number}%
		\textsuperscript{\arabic{institution@number}}\,#2\\% Institution
	}%
	\g@addto@macro{\Institution@ListForOneInstitutionOnly}{%
		#2\\% Institution
	}%
}

\newcommand{\Affilref}[1][]{%
	\g@addto@macro{\Author@List}{%
		\superscript@separator
		\textsuperscript{\expandafter\csname key@#1\endcsname}%
	}
}
% Institution list - end
% Authors and institutions - end

% Abstract
\newenvironment{Abstract}{%
	\small%
	\begin{list}{}{%
		\setlength{\labelsep}{10pt}%
		\renewcommand{\makelabel}[1]{{\textbf{##1}}\hfill}%
		\settowidth{\labelwidth}{\textbf{Keywords:}}%
		\setlength{\leftmargin}{\labelwidth}%
		\addtolength{\leftmargin}{\labelsep}%
	}%
	\item[Abstract]%
}{%
	\end{list}
}
% Abstract - end

% Keywords
\newenvironment{Keywords}{%
	\small%
	\begin{list}{}{%
		\setlength{\labelsep}{10pt}%
		\renewcommand{\makelabel}[1]{{\textbf{##1}}\hfill}%
		\settowidth{\labelwidth}{\textbf{Keywords:}}%
		\setlength{\leftmargin}{\labelwidth}%
		\addtolength{\leftmargin}{\labelsep}%
	}%
	\item[Keywords:]%
}{%
	\end{list}
}
% Keywords - end

% Equation
\renewcommand{\theequation}{\arabic{equation}}
% Equation - end

% Section
\renewcommand{\thesection}{\arabic{section}}
\titleformat%
	{\section}%
	{\raggedright\large\bfseries}% the declarations that are applied to the whole title
	{\thesection.\enspace\thinspace\thinspace}% the heading number
	{0pt}% the distance between the label and title text
	{}% code executed immediately preceding the heading text
% Section - end

% Index
%\newcommand{\Index}[1]{#1\index{#1}}
\def\cap@this#1{\uppercase{#1}}
\def\CapitalizeFirstLetter#1{{\expandafter\cap@this #1}}
\newcommand{\Index}[1]{#1\index{#1@\CapitalizeFirstLetter{#1}}}
% Index - end

\AtBeginDocument{%
	\global\let\title\chapter%
	
% Editor option
	\if@editoroption
% \printindex
		\providecommand\printindex{%
			\IfFileExists{\jobname.ind}{%
				\cleardoublepage
				\renewcommand{\indexname}{Index}%
				\footnotesize
				\@input@{\jobname.ind}%
			}{\typeout{Index file not found!}}
		}

% \makeauthorindex
		\def\makeauthorindex{%
			\newwrite\@authorindexfile
			\immediate\openout\@authorindexfile=\jobname.adx
% \@wrauthorindex
			\def\authorindex{%
				\@bsphack\begingroup
				\@sanitize\@wrauthorindex%
			}
			\let\makeauthorindex\@empty
		}%
% \@wrauthorindex
		\def\@wrauthorindex#1{%
			\protected@write\@authorindexfile{}%
			{\string\indexentry{#1}{\thepage}}%
			\endgroup\@esphack
		}
		% \printauthorindex
		\newcommand\printauthorindex{%
			\IfFileExists{\jobname.and}{%
				\cleardoublepage
				\renewcommand{\indexname}{Author Index}%
				\@input@{\jobname.and}%
			}{\typeout{Author Index file not found!}}
		}

		\@ifpackageloaded{hyperref}{%
			\ifHy@hyperindex
				\def\HyInd@ParenLeft{(}%
				\def\HyInd@ParenRight{)}%
				\Hy@nextfalse
				\@ifpackageloaded{multind}{\Hy@nexttrue}{}%
				\@ifpackageloaded{index}{\Hy@nexttrue}{}%
				\begingroup
				\lccode`\|=\expandafter`\HyInd@EncapChar\relax
				\lowercase{%
					\endgroup
					\ifHy@next
						\let\HyInd@org@wrindex\@wrauthorindex
						\def\@wrauthorindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
						\def\HyInd@@wrindex#1#2|#3|#4\\{%
							\ifx\\#3\\%
								\HyInd@org@wrindex{#1}{#2|hyperpage}%
							\else
								\def\Hy@temp@A{#3}%
								\ifcase0%
									\ifx\Hy@temp@A\HyInd@ParenLeft 1\fi
									\ifx\Hy@temp@A\HyInd@ParenRight 1\fi
									\relax
									\HyInd@org@wrindex{#1}{#2|#3}%
								\else
									\HyInd@org@wrindex{#1}{#2|#3hyperpage}%
								\fi
							\fi
						}%
					\else
						\def\@wrauthorindex#1{\@@wrauthorindex#1||\\}
						\def\@@wrauthorindex#1|#2|#3\\{%
							\if@filesw
								\ifx\\#2\\%
									\protected@write\@authorindexfile{}{%
										\string\indexentry{#1|hyperpage}{\thepage}%
									}%
								\else
									\def\Hy@temp@A{#2}%
									\ifcase0%
										\ifx\Hy@temp@A\HyInd@ParenLeft 1\fi
										\ifx\Hy@temp@A\HyInd@ParenRight 1\fi
										\relax
										\protected@write\@authorindexfile{}{%
											\string\indexentry{#1|#2}{\thepage}%
										}%
									\else
										\protected@write\@authorindexfile{}{%
											\string\indexentry{#1|#2hyperpage}{\thepage}%
										}%
									\fi
								\fi
							\fi
							\endgroup
							\@esphack
						}%
					\fi
				}%
			\fi
		}{}%

		\makeindex
		\makeauthorindex
	\else
		\let\authorindex\@gobble
	\fi
% Editor option - end

	\newif\ifpdf
	\@ifpackageloaded{hyperref}{%
		\ifpdf
			\PassOptionsToPackage{pdftex}{hyperref}%
		\else
			\PassOptionsToPackage{dvips}{hyperref}%
		\fi
		\hypersetup{%
			plainpages=false,
			bookmarksopen=true,
			bookmarksopenlevel=1,
			pdfstartview=FitV,
			bookmarksnumbered=false,
			linktocpage=true,
			colorlinks=true,
			urlcolor=blue
		}
	}{}%

	\@ifpackageloaded{graphics}{%
		\ifpdf
			\PassOptionsToPackage{pdftex}{graphics}%
        	\else
			\PassOptionsToPackage{dvips}{graphics}%
        	\fi
	}{}%
	\ifpdf
		\IfFileExists{fontenc.sty}{%
			\RequirePackage[T1]{fontenc}%
		}{}%
		\IfFileExists{textcomp.sty}{%
			\RequirePackage{textcomp}%
		}{}%
	\fi
	\pagestyle{empty}
}

\if@editoroption
	\AtEndDocument{%
		\printindex
		\printauthorindex
		\immediate\closeout\@authorindexfile
	}
\fi