%%----------------------------------------------------------------------
%% ieeepes.sty
%
% Sets up the document layout for IEEE PES (Power Engineering Society)
% publications.
% Usage: Load as a package together with the article document class.
% Example:
%	\documentclass{article}
%	\usepackage{ieeepes}
% Note: This package requires package vmargin by Volker Kuhlmann.
%
% Copyright (C) Volker Kuhlmann 1993, 1995, 1996, 1999
%
% Volker Kuhlmann
% c/o University of Canterbury
% ELEC Dept
% Creyke Road
% Christchurch, New Zealand
% E-Mail: v.kuhlmann@elec.canterbury.ac.nz
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License, distributed from CTAN
% archives as macros/latex/base/lppl.txt; either
% version 1 of the License, or (at your option) any later version.
%
%
% HISTORY:
% 4.0.1 01Jun99	Changed license to LPPL.
% 4.0  13Apr99	Fixed for use with LaTeX 1998/06/01.
% 3.25 19Jul96	\colbe removed. \authorcolumn, \linefield, \authors.
% 3.23 17Jul96	\colbe.
% 3.22 04Jul96	Environment Table.
% 3.2  30Jun96	Option draft prints "draft". Option puttoc.
%		Corrected section numbers, and section referencing.
% 3.1  03Apr96	Added some comments.
% 3.1  06Mar96	Added option noieeebox.
% 3.0  16Nov95	Changed summary.
% 2.9  16Nov95	Added summary.
% 2.8  14Nov95	Fixed caption justification.
% 2.7  12Nov95	\maketitle illegal, \Rhighlight, \Lhighlight.
%		Fixed abstract. Use graphicx instead of epsfig.
%		PStimes loads times and mathptm.
% 2.6  09Nov95	Option PStimes.
% 2.5  07Nov95	\discussion, \closure.
% 2.4  06Nov95	\figref, \tabref, equations, biography photos.
% 2.3  27Oct95	Added \author, \and.
% 2.2  10Oct95	Improved.
% 2.1  24Sep95	Improved.
% 2.0  15Sep95	Created out of IEEEpaper.sty, V2.22, 21 Feb 1993.
%
%%----------------------------------------------------------------------

\def\filename{ieeepes}
\def\fileversion{V4.0.1}
\def\filedate{1999/06/01}
\edef\ieeepesname{\filename}


\NeedsTeXFormat{LaTeX2e}[1998/06/01]
\ProvidesPackage{\filename}[\filedate]
\typeout{Package `\filename', \fileversion, <\filedate>}


%
%% LOAD REQUIRED PACKAGES
%
% Margin macros, by Volker Kuhlmann. Can be obtained from CTAN.
% A copy should be included with ieeepes for convenience.
\RequirePackage{vmargin}


%
%% DECLARE PACKAGE OPTIONS
%
\DeclareOption{draft}{%
	\PackageWarning{\ieeepesname}{DRAFT selected}%
	\AtEndOfPackage{%
		\pagestyle{plain}%
		\def\@Lhlmark{\LARGE$\rightarrow$}%
		\def\@Rhlmark{\LARGE$\leftarrow$}%
		\def\@oddfoot{\reset@font
			\hbox to\z@{\sffamily\bfseries DRAFT%
				\hskip 2em{\footnotesize\@date}\hss}%
			\hfil\thepage\hfil
			\hbox to\z@{\hss\sffamily\bfseries 
				{\footnotesize\@date}\hskip 2em DRAFT}}%
		\let\@evenfoot\@oddfoot
		}
	\newcommand\@puttoc{\old@tableofcontents\par\bigskip\bigskip}%
	%% with option puttoc
	}

\DeclareOption{psphotos}{%
	\psphototrue
	\AtEndOfPackage{\RequirePackage{graphicx}}
	}
\newif\ifpsphoto

\DeclareOption{photofit}{%
	\photofittrue
	}
\newif\ifphotofit

\DeclareOption{PStimes}{%
	\AtEndOfPackage{\RequirePackage{times,mathptm}}
	}

\DeclareOption{noieeebox}{%
	\AtBeginDocument{\let\@putbox\relax}
	}

\DeclareOption{puttoc}{%
	\newcommand\@@puttoc{\csname @puttoc\endcsname}%
	%% put toc, but only if option draft is active as well
	}


\ProcessOptions


%
%% PAGE AND PARAGRAPH LAYOUT
%
\setpapersize{USletter}
\setmarginsrb{18mm}{25mm}{18mm}{14mm}{0pt}{0mm}{}{11mm}
\parskip	0pt plus 1.5pt	% default by LaTeX: 0pt plus 1pt
\parindent	3.5mm		% default by LaTeX: 15pt
\columnsep	5mm		% default by LaTeX: 10pt = 3.5mm
\pagestyle	{empty}


%
%% WARNINGS, ERRORS
%
\newcommand\err@@text[1]%
	{Illegal command: \string#1}
\newcommand\hlp@@text
	{You can't use this command in IEEE PES documents.}
\newcommand\err@@illcmd[1]{%
	\PackageError{\ieeepesname}{\err@@text{#1}}{\hlp@@text}%
}


%
%% HEADER, EMPTY BOX
%
% \author, \and
% \authorcolumn
% \linefield
% \authors, &, \\
%
\renewcommand\author[1]{%
	\gdef\@author{%
		\author@beg #1\author@end
	}%
}
\renewcommand\and{%
	\author@end\author@beg
}
\newcommand\author@beg{%
	\mbox{}\hfill
	\hspace*{-.5\textwidth}%
	\begin{minipage}{\textwidth}%
	\centering
}
\newcommand\author@end{%
	\end{minipage}%
	\hspace*{-.5\textwidth}%
	\hfill\mbox{}%
}
%
\newcommand\authorcolumn[1]{\mbox{}\hfill\hspace{-.5\textwidth}%
	\parbox[t]{\textwidth}{\centering\strut #1\strut}\strut
		\hspace{-.5\textwidth}\hfill\mbox{}\ignorespaces}
	% works, but are the \strut s correct?
%
\newcommand\linefield[1]{\mbox{}\hfill\hbox to \z@{\hss #1\hss}\hfill\null
	\ignorespaces}% works!
%
\newbox\author@box
\newcommand\authors{%
	%\gdef\@author{\author@begii #1\author@endii}%
	\begingroup
	\catcode`\&\active
	\authorii@
}
\newcommand\authorii@{}
\begingroup
\catcode`\&\active
\gdef\authorii@#1{%
	\global\setbox\author@box=\hbox{\parbox{\textwidth}{%
		\large\rmfamily
		\centering% before redefining \\ !!!
		\def\\{\author@endii\linebreak\author@begii}%
		\def&{\author@endii\hfil\hfil\author@begii}%
		\leavevmode\author@begii #1\author@endii\par}}%
	\gdef\@author{\box\author@box}%
	\endgroup
}
\endgroup
\newcommand\author@begii{\hbox to \z@\bgroup\hss\ignorespaces}
\newcommand\author@endii{\hss\egroup}
%
\newcommand\@putheader{%
	\twocolumn[%
		\begin{center}
		{\Large\textbf{\@title}\par}% this needs to be 14pt bold
		\vspace{1cm}
		\tabcolsep	1cm
		{\large\textrm{\@author}\par}% needs to be 12pt
		\vspace{1cm}
		\end{center}
		]
	}
%
\newcommand\@putbox{%
	% put empty space on bottom of page
	% the figure-counter is not incremented because we don't
	% have a caption
	\begin{figure}[b]
	%\framebox(200,142.3){50mm of nothing}
	%\fbox{\makebox(200,142.3){}}
	\makebox(200,142.3){}
	\end{figure}
	}
%
\newcommand\ieeepes@maketitle{\@putheader\@putbox\csname @@puttoc\endcsname}
%\AtBeginDocument{\ieeepes@maketitle}
%This hook is now part of the preamble -> can no longer use it here.
%
%% make \maketitle illegal
%\renewcommand\maketitle{\PackageError{ieeepes}%
%	{\err@@section\maketitle}\hlp@@section}
% Adjust \maketitle, show error if not used
\renewcommand\maketitle{%
	\ieeepes@maketitle
	\capwidth=0.8\columnwidth
	\def\had@pesmt{y}%
}
\def\had@pesmt{}
\AtEndDocument{%
	\if y\had@pesmt\else
	  \PackageError{\ieeepesname}%
		{Must use \string\maketitle\space after
		 \string\begin{document}}%
		\hlp@@section
	\fi
}


%
%% TABLE OF CONTENTS
%
% save original definition and make illegal
\let\old@tableofcontents=\tableofcontents
\renewcommand\tableofcontents{\err@@illcmd\tableofcontents}


%
%% ABSTRACT
%
\renewenvironment{abstract}{%
	\footnotesize\bfseries
	\textit{Abstract---}\ignorespaces
}{%
	\par
}


%
%% SECTIONING
%
% Section numbering for \section, \subsection, \subsubsection.
\setcounter{secnumdepth}{3}
%
% Save original definition of \@xsect
\let\sv@xsect=\@xsect
%
%\renewcommand\@seccntformat[1]{\csname the#1\endcsname \hskip.4em\relax}
%% this is used for typesetting the sectioning number
%
%\renewcommand\thesection{\Roman{section}.}
\renewcommand\thesection{\Roman{section}}
% copied from classes.dtx, and modified:
\renewcommand\section{%
	\def\@seccntformat##1{\Roman{section}.\hskip.4em\relax}%
	\let\@xsect=\sv@xsect
	\@startsection {section}{1}{\z@}%
		{1\baselineskip \@plus1\baselineskip \@minus.1\baselineskip}%
		{.8\baselineskip \@plus.2\baselineskip}%
		{\reset@font\normalsize\scshape\noindent\hfil}%
	}
%
%\renewcommand\thesubsection{\Alph{subsection}.}
\renewcommand\thesubsection{\thesection.\Alph{subsection}}
% copied from classes.dtx, and modified:
\renewcommand{\subsection}{%
	\def\@seccntformat##1{\Alph{subsection}.\hskip.4em\relax}%
	\let\@xsect=\sv@xsect
	\@startsection{subsection}{2}{\z@}%
		{1\baselineskip \@plus1\baselineskip \@minus.1\baselineskip}%
		{.8\baselineskip \@plus.2\baselineskip \@minus.1\baselineskip}%
		{\reset@font\normalsize\itshape}%
	}
%
%\renewcommand\thesubsubsection{\arabic{subsubsection})}
\renewcommand\thesubsubsection{\thesubsection.\arabic{subsubsection})}
% copied from classes.dtx, subparagraph, and modified:
\renewcommand{\subsubsection}{%
	\def\@seccntformat##1{\arabic{subsubsection})\hskip.4em\relax}%
	% Intercept \@xsect call by \@sect, and add a colon
	\def\@xsect{%
		\let\old@svsechd=\@svsechd
		\def\@svsechd{\old@svsechd:}%
		\sv@xsect}%
	\@startsection{subsubsection}{3}{\parindent}%
		{-1\parskip}%
		{-.5em}%
		{\reset@font\normalsize\itshape}%
	}
%
% Disallow sectioning below \subsubsection.
\renewcommand\paragraph{\err@@illcmd\paragraph}
\renewcommand\subparagraph{\err@@illcmd\subparagraph}


%
%% FLOATS (FIGURES AND TABLES)
%

% Define numbering
%
\renewcommand\thefigure{\arabic{figure}}
\renewcommand\figurename{Fig.}
\renewcommand\thetable{\Roman{table}}
\renewcommand\tablename{Table}
\renewcommand\thempfootnote{\alph{mpfootnote}}

% References
%
\newcommand\figref{\figurename~\ref}
\newcommand\tabref{\tablename~\ref}
\newcommand\fref{\figref}
\newcommand\tref{\tabref}

% Caption spacing
%
% (the following skips are set here to avoid trouble with other
%  packages also working with captions.)
\abovecaptionskip	.9\baselineskip
\belowcaptionskip	0mm
%
\newdimen\capwidth
%\AtBeginDocument{\capwidth=.8\columnwidth}
% setting \capwidth is useless before \twocolumn is active
% now done by \maketitle

% Float placement parameters
%
\floatsep			1\baselineskip 
				  \@plus.1\baselineskip \@minus.1\baselineskip
\textfloatsep			1.1\baselineskip 
				  \@plus1\baselineskip \@minus\z@

% Make the contents of a figure/table environment centered by default.
% (Note: this makes use of internal LaTeX control sequences and might
% not work any more with future releases.)
%
\let\old@floatboxreset=\@floatboxreset
\def\@floatboxreset{\old@floatboxreset\centering}

% Handle caption formatting
%
% Intercept at beginning of figure, and setup
\let\old@figure=\figure
\def\figure{%
%\showthe\abovecaptionskip
	\let\@makecaption=\fig@caption
	\abovecaptionskip=.9\baselineskip
	\belowcaptionskip=0mm
	\old@figure
	}
\newcommand\fig@caption[2]{%
	\par
	\vskip\abovecaptionskip
	\centering\footnotesize
	\sbox\@tempboxa{#1. #2}\ifdim\wd\@tempboxa > \capwidth
	  \parbox\capwidth{#1. #2}%
	\else
	  \parbox\capwidth{\centering #1. #2}%
	\fi
	\vskip\belowcaptionskip
	}
%
% Intercept at beginning of table, and setup
\let\old@table=\table
\def\table{%
	\let\@makecaption=\tbl@caption
	\abovecaptionskip=0mm
	\belowcaptionskip=.9\baselineskip
	\old@table
	}
\newcommand\tbl@caption[2]{%
	\par
	\vskip\abovecaptionskip
	\centering\footnotesize\scshape
	%\sbox\@tempboxa{#1. #2}%
	\sbox\@tempboxa{#2}%
	\ifdim\wd\@tempboxa > \capwidth
	  \parbox\capwidth{\hfil #1\\#2}%
	\else
	  \parbox\capwidth{\centering #1\\#2}%
	\fi
	\vskip\belowcaptionskip
	}

% New environments for figure and table which take a label and the
% caption as argument and place the caption correctly.
% Arguments in square brackets are optional.
% The LABEL argument is required but may be empty.
%
% \begin{Figure}[FLOATPLACEMENT]{LABEL}[TOC CAPTION]{CAPTION}
% \begin{Table}[FLOATPLACEMENT]{LABEL}[TOC CAPTION]{CAPTION}
%
% Note: \figure does not take control sequences for LOC. Must be expanded
% recursively, hence the \edef\@FLPLACE and \expandafter before \figure.
%
\newenvironment{Figure}[2][\fps@figure]{%
	\edef\@FLPLACE{#1}\def\@TFLABEL{#2}\Figure@@
	}{%
	\caption[\@tocCAPTION]{\@CAPTION}%
	\ifx\@TFLABEL\empty\else\label\@TFLABEL\fi
	\endfigure
	}
\newcommand\Figure@@[2][]{%
	\def\@tocCAPTION{#1}\def\@CAPTION{#2}%
	\expandafter\figure\expandafter[\@FLPLACE]%
	}
%
\newenvironment{Table}[2][\fps@table]{%
	\edef\@FLPLACE{#1}\def\@TFLABEL{#2}\Table@@
	}{%
	\ifx\@TFLABEL\empty\else\label\@TFLABEL\fi
	\endtable
	}
\newcommand\Table@@[2][]{%
	\def\@tocCAPTION{#1}\def\@CAPTION{#2}%
	\expandafter\table\expandafter[\@FLPLACE]%
	\caption[\@tocCAPTION]{\@CAPTION}%
	}

% left and right highlighters
%
\newcommand\Lhighlight{\leavevmode\llap\@Lhlmark}
\newcommand\Rhighlight{\leavevmode\rlap\@Rhlmark}
\newcommand\@Lhlmark{}
\newcommand\@Rhlmark{}


%
%% EQUATIONS AND EQUATION REFERENCES
%

% Reference equations with (n), and remove the second set of
% parantheses from the equation number printed next to the equation,
% which would otherwise show up as ((n)).
%
\renewcommand\theequation{(\arabic{equation})}
\renewcommand\@eqnnum{\normalfont \normalcolor \theequation}

% Equation references
%
\newcommand\equref{\ref}		% within sentence
\newcommand\Equref{Equation~\ref}	% at beginning of sentence


%
%% CITATIONS AND BIBLIOGRAPHIES
%
\bibliographystyle{ieeepes}

% Turn the \section*{} which is called by \thebibliography into a
% \section{}, i.e. get the section numbered.
%
\let\old@thebibliography=\thebibliography
\def\thebibliography{%
	\let\old@section@=\section
	\def\section{\@ifstar\old@section@\old@section@}%
	\old@thebibliography
	}


%
%% BIOGRAPHY
%
% \begin{biography}{NAME}[RAISE EPS IMAGE]{FILENAME OF EPS FILE}
%
% The photograph to submit should be 30mm x 45mm, but this would not
% fit in the space provided in the example, which is about 28mm x 37mm
% (measured). The height has been decreased appropriately with this
% package.
%
\newdimen\@photoho
%
\newenvironment{biography}[1]{%
	\par
	\vspace{8mm \@plus2mm \@minus1mm}
	\footnotesize		% should be 8pt, roman
	\noindent
	\newcommand\@authorname{#1}%
	\@placephoto
}{%
	\par
}
\newcommand\@placephoto[2][\z@]{%
	\def\@photo{#2}\def\no@photo{nophoto}%
	\ifx\@photo\no@photo\else
	  \hangindent	30mm
	  \hangafter	-12
	  \ifpsphoto\ifx\@photo\@empty\else
	    \@photoho=-36.73mm
	    \advance\@photoho by #1
	    \llap{\raisebox{\@photoho}[\z@][\z@]{\parbox[t][38.5mm][t]{30mm}{%
	      \ifphotofit
	       \includegraphics[width=28mm,height=38.73mm]{#2}%
	      \else
	       \includegraphics[width=28mm]{#2}%
	      \fi
	      % area available with cm fonts: 28mm x 38.73mm
	      }}}%
	  \fi\fi
	\fi
	\textbf{\@authorname}\ \ignorespaces
	}


%
%% BALANCE COLUMNS ON LAST PAGE (MANUALLY)
%
\newcommand\columnbreak{%
	\ifvmode\newpage\else\vadjust{\newpage}\fi
	}


%
%% RE-DEFINE DATE FORMAT
%
\newcommand\@today{\number\year/\number\month/\number\day}
\let\today=\@today
\AtBeginDocument{\let\today=\@today}


%
%% SUMMARY, DISCUSSION AND CLOSURE
%
% \summary
% \discussion{PAPER NUMBER}{PAPER TITLE}{AUTHOR NAMES}%
%	{DISCUSSER NAME}{AFFILIATION INCL ADDRESS}{SHORT AFFILIATION}
% \closure{AUTHOR NAME}
%
\newcommand\reset@counters{%
	\setcounter{figure}{0}\setcounter{table}{0}%
	\setcounter{section}{0}%
	\setcounter{equation}{0}%
	\setcounter{footnote}{0}\setcounter{mpfootnote}{0}%
	}
%
\newcommand\summary{%
	\clearpage
	\reset@counters
	\setcounter{page}{1}%
	\thispagestyle{plain}\pagestyle{plain}%
	\onecolumn
	\columnwidth	88mm	% warning: brutal trick!
	\hsize\columnwidth	% "
}
\newcommand\discussion[6]{%
	\cleardoublepage
	\reset@counters
	\setcounter{page}{1}%
	\thispagestyle{plain}\pagestyle{plain}%
	\onecolumn
	\noindent Discussion of #1, ``#2'', by #3.\par
	\vspace{\baselineskip}%
	\noindent Discussion by #4, #5.\par
	\columnwidth	88mm	% warning: brutal trick!
	\hsize\columnwidth	% "
	\clearpage
	\begin{center}
	\Large
	\textbf{Discussion}
	\end{center}
	\textbf{#4}\ (#6)\ \ignorespaces
}
\newcommand\closure[1]{%
	\cleardoublepage
	\reset@counters
	\setcounter{page}{1}%
	\thispagestyle{plain}\pagestyle{plain}%
	\onecolumn
	\columnwidth	88mm	% warning: brutal trick!
	\hsize\columnwidth	% "
	\clearpage
	\begin{center}
	\Large
	\textbf{Closure}
	\end{center}
	\textbf{#1}\ \ignorespaces
}


%
%% TABLE STRUTS
%
% \setTBstruts, defining \T, \B
%
% to control vertical spacing in tabular and array
% (taken from "TeX and TUG NEWS", Vol. 2, No. 3, 1993, p. 10)
%
\providecommand\setTBstruts{\def\T{\rule{0pt}{2.6ex}}%
				\def\B{\rule[-1.2ex]{0pt}{0pt}}}


%% EOF ieeepes.sty
%%----------------------------------------------------------------------