  %*************************************************************%
  %*                                                           *%
  %*     Prepared by Gerald Banon                              *%
  %*     Instituto Nacional de Pesquisas Espaciais (INPE)      *% 
  %*     Copyright 2007 © MCT/INPE                             *%
  %*     All rights reserved.                                  *%
  %*                                                           *%
  %*************************************************************%
  
\NeedsTeXFormat{LaTeX2e} 
%\ProvidesClass{ISMM2007proceedings}[2007/07/01 ISMM2007 proceedings class]
\LoadClassWithOptions{book}

\RequirePackage[T1]{fontenc}
%\RequirePackage[latin1]{inputenc}
\RequirePackage[pagestyles]{titlesec}% needed for \titleformat and \newpagestyle
\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,
		aboveskip=10pt,
		belowskip=0pt,
		%margin=10pt
	}%
	\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
	\newcommand*{\serieinpe}[1]{\gdef\@serieinpe{#1}}
	\newcommand*{\institutionachronym}[1]{\gdef\@institutionachronym{#1}}
	\newcommand*{\institutioncity}[1]{\gdef\@institutioncity{#1}}
	\newcommand*{\publicationyear}[1]{\gdef\@publicationyear{#1}}
	
	\newcommand*{\Booktitle}[1]{\gdef\@Booktitle{#1}}
	\newcommand*{\cardnumber}[1]{\gdef\@cardnumber{#1}}
	\newcommand*{\firstAuthorLastName}[1]{\gdef\@firstAuthorLastName{#1}}
	\newcommand*{\firstAuthorFirstName}[1]{\gdef\@firstAuthorFirstName{#1}}
	\newcommand*{\authorNames}[1]{\gdef\@authorNames{#1}}
	\newcommand*{\numberOfPages}[1]{\gdef\@numberOfPages{#1}}
	\newcommand*{\keywords}[1]{\gdef\@keywords{#1}}
\fi

\if@editoroption
% catalogingdata
\newcommand{\catalogingdata}{
	{
%		\vspace*{\stretch{1}}
		{
			{
				\centering{%
					{
%						\protect\fbox{\parbox{11.5cm}{
						\protect\parbox{11.5cm}{
							\small\ttfamily%
							{\@cardnumber \\ \par}%
							{\hspace{2em}{\MakeUppercase\@firstAuthorLastName}, \@firstAuthorFirstName.\par}
							{\vspace{0.1cm}\hspace{6em}\parbox{9.5cm}{\hspace{-2em}\@Booktitle \space /\space \@authorNames.\ - \@institutioncity:\ \@institutionachronym, \@publicationyear.}\par}
							{\vspace{0.1cm}\hspace{2em}\parbox{10.5cm}{\hspace{4em}\@numberOfPages\ p.\ - (\@serieinpe).}\par}
							{\vspace{0.1cm}\hspace{2em}\parbox{10.5cm}{\hspace{2em}Includes bibliographical references and index.}\par}
							{\vspace{0.0cm}\hspace{2em}\parbox{10.5cm}{\hspace{2em}ISBN 0-000-00000-0}\par}
							{\vspace{0.2cm}\hspace{6em}\parbox{9.5cm}{\hspace{-2em}\@keywords}\par}
						}
%						}
					}
				}
				\par
			}
%			\vspace*{\stretch{1}}
		}
	}
}
\fi

\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\LARGE\bfseries\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{2em}%
			\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}\renewcommand{\baselinestretch}{0.9}\small}
		{}
		{}
		{\hfill\contentspage}
	
	\newcommand{\l@author}[2]{%
		\begingroup
			\vspace{-3.5mm}%
			\setlength{\parindent}{0mm}
			\parbox{10.5cm}{%
				\small\begin{flushleft}\textit{#1}\end{flushleft}
			}%
			\vspace{-3.5mm}
		\endgroup
	}
	\newcommand{\toclevel@author}{0}

	\newcommand{\l@index}[2]{%
		\begingroup
%			\vspace{-3.5mm}%
%			\setlength{\parindent}{0mm}
%			\parbox{10.5cm}{%
				\small\begin{flushleft}\textit{#1}\hfill#2\end{flushleft}
%			}
		\endgroup
	}
	\newcommand{\toclevel@index}{-1}
% 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}%
	\@mainmatterfalse
}
\if@editoroption
	\renewcommand\mainmatter{%
		\cleardoublepage
		\pagestyle{fullpaper}%
		\pagenumbering{arabic}%
		\@mainmattertrue
	}
\fi
% Front and main matter - end

\newcommand{\ShortBookTitle}[1]{\gdef\Short@BookTitle{#1}}
\newcommand{\EditorsTitle}[1]{\gdef\Editors@Title{#1}}
\newcommand{\Copyright}[1]{\gdef\@Copyright{#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}}
	\sethead[\textup{\thepage}][][\Short@BookTitle]{\shorttitle}{}{\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
				\\*%
				\@Copyright%
			}%
		}
		{}%
}%
\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}
	\newtheorem{lemma}{Lemma}
	\newtheorem{proposition}{Proposition}
	\newtheorem{corollary}{Corollary}
	\newtheorem{property}{Property}

	\theoremstyle{definition}
	\newtheorem{definition}{Definition}
	\newtheorem{example}{Example}

	\theoremstyle{remark}
	\newtheorem{remark}{Remark}
	\newtheorem{note}{Note}
\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
\newcommand{\shorttitle}{}% for short chapter title
\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\titleformat%
	{\chapter}%
	{\sloppy\raggedright\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
			\if@mainmatter
				\thispagestyle{fullpapertitlepage}%
			\else
				\thispagestyle{empty}%
			\fi
			\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}%
		\vspace{5dd 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{\hspace{-0.4pt}\textsuperscript{,}\hspace{0.8pt}}%
	}%
	\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}}%
		\gdef\superscript@separator{\hspace{-0.4pt}\textsuperscript{,}\hspace{0.8pt}}%
	}
	\g@addto@macro{\Institution@List}{%
		\stepcounter{institution@number}%
		\vspace{3pt}%
		\textsuperscript{\arabic{institution@number}}\,#2\\% Institution
	}%
	\g@addto@macro{\Institution@ListForOneInstitutionOnly}{%
		\vspace{3pt}%
		#2\\% Institution
	}%
}

\newcommand{\Affilref}[1][]{%
	\g@addto@macro{\Author@List}{%
		\superscript@separator
		\textsuperscript{\expandafter\csname key@#1\endcsname}%
		\gdef\superscript@separator{\hspace{-0.4pt}\textsuperscript{,}\hspace{0.8pt}}%
	}
}
% 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}%
				\addtocontents{toc}{\protect\vspace{2ex}}
				\addcontentsline{toc}{index}{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}%
				\addcontentsline{toc}{index}{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
		\phantomsection% to fixe a bug in hyperref
		\printauthorindex
		\immediate\closeout\@authorindexfile
	}
\fi