% \iffalse meta-comment
%
% Copyright 2000 by Hanspeter Schmid
%
% This file may be distributed under the terms of the
% GNU General Public License.  The latest version of this license
% can be found at http://www.gnu.org/copyleft/gpl.html
% 
% \fi
% \iffalse
%
%<*driver>
% \fi
\ProvidesFile{hpsdiss.dtx}[2000/10/26 v1.0 Hanspeter's dissertation style]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{hpsdiss.dtx}
\title{hpsdiss: Dissertation class for ETH Z\"urich}
\date{\filedate}
\author{%
  Hanspeter Schmid, hanspi@computer.org}
\begin{document}
\maketitle
\DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \CheckSum{1517}
%
% \section{Please \ldots}
%
%  rename this class when you make \emph{any} changes.  I absolutely
%  don't want different versions floating around.  I will not give
%  any support to anybody who breaks this rule.
%  Questions?  Use e-mail, my address is |hanspi@computer.org|.
%
% \section{Introduction}
%  
%  I developed this \LaTeX\ class to typeset my own dissertation at the
%  ETH Z\"urich.  I was never satisfied with the conventional layout,
%  which was to fill an A5 page with a font size of 10pt.  Then the lines
%  become too long, in my opinion.
%  
%  The class |hpsdiss.cls| produces shorter lines, has wide outer
%  margins, and prints section numbers, figure and table numbers, and of
%  course margin notes into these wide margins.  In my dissertation,
%  I used the command |\Abstract| (see
%  below) to give every single paragraph its little abstract in the
%  margin, as an aid for the reader who browses through the book and also
%  to communicate what the main idea behind every paragraph is.
%  
%  Other features of this class are:
%  \begin{itemize}
%  \item It can typeset everything with a ragged right margin (that's how I
%    prefer it).
%  \item It redefines the environments |sidewaysfigure| and
%    |sidewaystable| such that they produce sensible captions.
%  \item It provides several commands to let material extend into the
%    margins (figures, tables \ldots).
%  \item It provides a special chapter title page that contains the
%    title, a quote, and a chapter abstract.
%  \item It provides a special environment |bkgnd| for historical and
%    personal information, which uses a different font to differ it
%    optically from the purely scientific part of the dissertation.
%  \item It has an option |specialfonts| that switches to a nice font
%    combination: Times for main text, Gill Sans for headings, and Codex
%    for the background information.  Unfortunately, this option is
%    useless for most users, since it relies on fonts that are not in the
%    public domain.
%  \item It generates the official title page of the dissertation
%    ``Series in Signal and Information Processing,'' and also the back
%    of the book.
%  \end{itemize}
%  
%  Many things in this class are configurable by class options, and it
%  also provides several commands.  The commands and environments that
%  are interesting for the users of this class are marked in the margin
%  and are described there.
%
% \StopEventually{}
%
% \changes{v1.0}{2000/10/26}{Generated from my old hpsdiss.cls}
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{hpsdiss}[2000/10/26 PhD thesis class by Hanspeter Schmid]
%    \end{macrocode}
%
% \section{Class Options}
%
%  This class bases on book.cls, and almost all options that it does not
%  understand itself are passed on to |book.cls|.  Only the option
%  |twocolumn| is rejected, because it does not make sense.  Font size
%  options like |11pt| \ldots should not be used, since the font sizes
%  are hard-wired.
%  
%  |hpsdiss| has quite a few options of its own.  |raggedright| lets all
%  text appear with a ragged right margin, using the macro |\RaggedRight|
%  from the package |ragged2e|.  |specialfonts| is described above.
%  
%  Most options are there to determine what the title page looks like.
%  The options belong to three sets: language, gender, and degree.  The
%  default language is English, other languages can be used with the
%  options |deutsch|, |italiano|, and |francais|.  The default gender of
%  the author is male, use the option |female| if you're a woman.  This
%  plays a role in conjunction with the options |deutsch| and |francais|.
%  The default doctoral degree is ``Doctor of Technical Sciences,'' use
%  the option |scnat| for ``Natural Sciences'' and |scmath| for
%  ``Mathematics.''
%
%    \begin{macrocode}
\DeclareOption{twocolumn}{%
  \@latex@warning{hpsdiss.cls does not accept the option `twocolumn'.}%
  \OptionNotUsed}
\DeclareOption{raggedright}{\newcommand{\TextAlignment}{\RaggedRight}}
\DeclareOption{specialfonts}{\newcommand{\SpecialFonts}{\relax}}
\DeclareOption{deutsch}{\newcommand{\DT@deutsch}{\relax}}
\DeclareOption{francais}{\newcommand{\DT@francais}{\relax}}
\DeclareOption{italiano}{\newcommand{\DT@italiano}{\relax}}
\DeclareOption{scnat}{\newcommand{\DT@scnat}{\relax}}
\DeclareOption{scmath}{\newcommand{\DT@scmath}{\relax}}
\DeclareOption{female}{\newcommand{\DT@female}{\relax}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\PassOptionsToClass{twoside}{book}
\ProcessOptions
\LoadClass{book}
%    \end{macrocode}
%
%  This packages requires several other packages that we now
%  load: |geometry| to set the page
%  layout, |calc| for arithemtics within arguments, |ragged2e| for
%  producing ragged-right text, |rotating| for tables and figures
%  that are turned sideways, and |mparhack| such that the margin
%  paragraphs work (more) properly.  Finally, |graphicx| and 
%  |colordvi| are required for the title page.
%
%    \begin{macrocode}
\RequirePackage{geometry}
\RequirePackage{calc}
\RequirePackage{ragged2e}
\RequirePackage{rotating}
\RequirePackage{mparhack}
\RequirePackage{graphicx}
\RequirePackage{colordvi}
%    \end{macrocode}
%
% \section{Page Layout}
%  
% \begin{macro}{\MarginParWidth}
% \begin{macro}{\MarginParSep}
% \begin{macro}{\TotalWidth}
%
%  The page is laid out as a main text block with a 26-mm outer margin
%  to be printed on A5 paper.  These dimensions can be changed by modifying
%  |\MarginParWidth|, |\MarginParSep|, and |\TotalWidth|, but please don't
%  change this unless you are prepared to find out what else you need to
%  change as well.
%
%    \begin{macrocode}
\newcommand{\MarginParWidth}{26mm}
\newcommand{\MarginParSep}{4mm}
\newcommand{\TotalWidth}{118.5mm}
\geometry{paper=a5paper,dvips=true,twoside=true}
\geometry{width=\TotalWidth,height=192mm,top=7mm,twosideshift=7mm}
\geometry{headheight=4mm,headsep=9mm}
\geometry{nofoot}
\geometry{marginparsep=\MarginParSep,marginparwidth=\MarginParWidth}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%  
% \begin{macro}{\CapFont}
% \begin{macro}{\CapNumFont}
% \begin{macro}{\SecFont}
% \begin{macro}{\SecNumFont}
% \begin{macro}{\ChapFont}
% \begin{macro}{\TitleFont}
% \begin{macro}{\HeaderFont}
% \begin{macro}{\BackgroundFont}
%
%  The following macros define, in this order, the fonts used for
%  captions, caption lables, section titles, section numbers, chapter
%  titles, the document title, the page headings, and the |background|
%  environment, and the fonts used on the official title page.
%  There is a conventional version and a version called by
%  the option |specialfonts|.
%  
%    \begin{macrocode}
\ifx\SpecialFonts\undefined
  \newcommand{\CapFont}{\em}
  \newcommand{\CapNumFont}{\sf\bfseries}
  \newcommand{\SecFont}{\sf\bfseries}
  \newcommand{\SecNumFont}{\sf\bfseries}
  \newcommand{\ChapFont}{\sf\bfseries}
  \newcommand{\TitleFont}{\sf\bfseries}
  \newcommand{\HeaderFont}{\sf\small}
  \newcommand{\BackgroundFont}{\em}
  \newcommand{\DTfont@author}{\sf\bfseries}
  \newcommand{\DTfont@normal}{\sf}
  \newcommand{\DTfont@series}{\sf\bfseries}
  \newcommand{\DTfont@title}{\sf\bfseries}
\else
  \newcommand{\CapFont}{\em}
  \newcommand{\CapNumFont}{\usefont{T1}{bgs}{b}{r}\selectfont}
  \newcommand{\SecFont}{\usefont{T1}{bgs}{b}{r}\selectfont}
  \newcommand{\SecNumFont}{\usefont{T1}{bgs}{b}{r}\selectfont}
  \newcommand{\ChapFont}{\usefont{T1}{bgs}{b}{r}\selectfont}
  \newcommand{\TitleFont}{\usefont{T1}{bgs}{b}{r}\selectfont}
  \newcommand{\HeaderFont}{\usefont{T1}{bgs}{r}{r}\selectfont}
  \newcommand{\BackgroundFont}{%
    \usefont{T1}{bc9}{r}{r}\selectfont%
    \renewcommand{\emph}[1]{{##1}}}
  \newcommand{\DTfont@author}{\usefont{T1}{bgs}{b}{r}\selectfont}
  \newcommand{\DTfont@normal}{\usefont{T1}{bgs}{r}{r}\selectfont}
  \newcommand{\DTfont@series}{\usefont{T1}{bgs}{b}{r}\selectfont}
  \newcommand{\DTfont@title}{\usefont{T1}{bgs}{b}{r}\selectfont}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\noparskip}
%
%  This class uses the European book layout, i.e., a layout that has
%  no paragraph identations, but some paragraph skip.  This is sometimes
%  not wanted in tables of contents, so we provide a macro that makes
%  it possible to produce tables of contents with tight vertical spacing
%  by writing something like |{\noparskip \tableofcontents}|.
%
%    \begin{macrocode}
\newcommand{\noparskip}{\parskip=\z@ \@plus\z@ \@minus\z@}
%    \end{macrocode}
%
% \end{macro}
%
%  Now come the details of the paragraph layout.  If |raggedright| is not
%  used, |\TextAlignment| must be set anyway, and |\parindent| must be
%  set to zero.  (The command |\RaggedRight| does that too).  The text
%  alignement command is issued at the begin of the document, and the
%  parskip is also set to a reasonable, non-zero value.  Finally, clubs
%  and widows are punished hard.
%    \begin{macrocode}
\ifx\TextAlignment\undefined
  \newcommand{\TextAlignment}{\relax}
  \parindent=0pt
\else\fi
\AtBeginDocument{\TextAlignment}
\parskip=2ex \@plus 0.5ex \@minus 0.5ex
\widowpenalty 10000
\clubpenalty 10000
\@clubpenalty 10000
%    \end{macrocode}
%  Lists are generally defined with tighter vertical spacing, the
%  following was adapted from |book.cls|.
%    \begin{macrocode}
\def\@listi{\leftmargin\leftmargini
  \parsep \z@ \@plus2\p@ \@minus\z@
  \topsep \z@ \@plus2\p@ \@minus\z@
  \itemsep\z@ \@plus2\p@ \@minus\z@}
\let\@listI\@listi
\@listi
\def\@listii{\leftmargin\leftmarginii
  \labelwidth\leftmarginii
  \advance\labelwidth-\labelsep
  \topsep \z@ \@plus2\p@  \@minus\z@
  \parsep \z@ \@plus\p@ \@minus\z@
  \itemsep \parsep}
\def\@listiii{\leftmargin\leftmarginiii
  \labelwidth\leftmarginiii
  \advance\labelwidth-\labelsep
  \topsep \z@ \@plus\p@ \@minus\z@
  \parsep \z@ \@minus\z@
  \partopsep \z@ \plus\z@ \@minus\z@
  \itemsep \topsep}
\def\@listiv {\leftmargin\leftmarginiv
  \labelwidth\leftmarginiv
  \advance\labelwidth-\labelsep}
\def\@listv  {\leftmargin\leftmarginv
  \labelwidth\leftmarginv
  \advance\labelwidth-\labelsep}
\def\@listvi {\leftmargin\leftmarginvi
  \labelwidth\leftmarginvi
  \advance\labelwidth-\labelsep}
%    \end{macrocode}
%  I use font size 10pt, and noything else, thus it is hard-wired.
%  The following is adapted from |bk10.clo|.
%    \begin{macrocode}
\renewcommand\normalsize{%
   \@setfontsize\normalsize\@xpt\@xiipt
   \abovedisplayskip 10\p@ \@plus2\p@ \@minus\z@
   \abovedisplayshortskip \z@ \@plus3\p@ \@minus\z@
   \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
   \belowdisplayskip \abovedisplayskip
   \let\@listi\@listI}
\normalsize
\renewcommand\small{%
   \@setfontsize\small\@ixpt{11}%
   \abovedisplayskip 8.5\p@ \@plus3\p@ \@minus\z@
   \abovedisplayshortskip \z@ \@plus2\p@
   \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
   \def\@listi{\leftmargin\leftmargini
               \topsep \z@ \@plus2\p@ \@minus\z@
               \parsep \z@ \@plus\p@ \@minus\z@
               \itemsep \parsep}%
   \belowdisplayskip \abovedisplayskip
   }
\renewcommand\footnotesize{%
   \@setfontsize\footnotesize\@viiipt{9.5}%
   \abovedisplayskip 6\p@ \@plus2\p@ \@minus\z@
   \abovedisplayshortskip \z@ \@plus\p@
   \belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@
   \def\@listi{\leftmargin\leftmargini
               \topsep \z@ \@plus\p@ \@minus\z@
               \parsep \z@ \@plus\p@ \@minus\z@
               \itemsep \parsep}%
   \belowdisplayskip \abovedisplayskip
}
%    \end{macrocode}
%
% \section{Page Headings}
%
%  The running feet are empty in this page style.
%    \begin{macrocode}
\def\ps@headings{%
  \let\@oddfoot\@empty\let\@evenfoot\@empty
%    \end{macrocode}
%  On left pages: skip to the left of the margin, typeset the page
%  number, and then typeset the heading text above the normal text.
%    \begin{macrocode}
  \def\@evenhead{%
    \hskip-\marginparsep\hskip-\marginparwidth%
    \makebox[\marginparsep+\marginparwidth][l]{\HeaderFont\thepage}%
    {\makebox[\textwidth][l]{\HeaderFont\vphantom{g}\leftmark}}}
%    \end{macrocode}
%  Right pages: Typeset the heading text above the normal text,
%  and then typeset the page number at the right edge of the
%  margin.  The trailing |\hskip|s prevent overfull hboxes.
%    \begin{macrocode}
  \def\@oddhead{% 
    {\makebox[\textwidth][r]{\HeaderFont\vphantom{g}\rightmark}}%
    \makebox[\marginparsep+\marginparwidth][r]{\HeaderFont\thepage}%
    \hskip-\marginparsep\hskip-\marginparwidth}
%    \end{macrocode}
%  When using this page style, the content of the running heading is
%  determined by the chapter and section titles.
%    \begin{macrocode}
  \let\@mkboth\markboth
%    \end{macrocode}
%  |book.cls| uses the |\chaptermark| and |\sectionmark| macros to fill 
%  the running heads.  In contrast to the standard |book.cls|,
%  I don't want headings to appear in capital letters, so I had
%  to remove all the |\makeuppercase| commands.
%    \begin{macrocode}
  \def\chaptermark##1{%
    \markboth {%
      \ifnum \c@secnumdepth >\m@ne %
        \if@mainmatter \@chapapp\ \thechapter. \ \fi %
      \fi %
      ##1}{}}%
  \def\sectionmark##1{%
    \markright {%
      \ifnum \c@secnumdepth >\z@ %
      \thesection. \ %
      \fi %
      ##1}}}
%    \end{macrocode}
%  And now execute |\ps@headings|.
%    \begin{macrocode}
\pagestyle{headings}
%    \end{macrocode}
%  Unfortunatley, the original |book.cls| makes all headings in
%  Tables of Contents, Lists of Figures, Lists of Tables, and
%  in the Bibliography section appear in capital letters too.
%  I don't want this, and remove all the |\makeuppercase| commands
%  from the definitions made in |book.cls|.
%    \begin{macrocode}
\renewcommand\tableofcontents{%
  \chapter*{\contentsname\@mkboth{\contentsname}{\contentsname}}%
  \@starttoc{toc}}
\renewcommand\listoffigures{% 
  \chapter*{\listfigurename\@mkboth{\listfigurename}{\listfigurename}}%
  \@starttoc{lof}}
\renewcommand\listoftables{%
  \chapter*{\listtablename\@mkboth{\listtablename}{\listtablename}}%
  \@starttoc{lot}}
%    \end{macrocode}
%
% \section{Bibliography}
%
%  In addition to the headings problem, I want the bibliography
%  to show the reference fields in the margin.
%  I use a global variable |\ThePage| that will contain the
%  page number of the page on which a particular bibliography
%  entry is printed.  Unfortunatley, this can only be determined
%  when the box containing the entry is shipped out.  So I have
%  to use the |.aux| file to store and retrieve this information.
%  First, define a counter that is used to generate the
%  internally used labels.
%    \begin{macrocode}
\newcounter{autolabels}%
\renewenvironment{thebibliography}[1]
{\chapter*{\bibname\@mkboth{\bibname}{\bibname}}%
  \small %
  \addcontentsline{toc}{chapter}{\bibname}
%    \end{macrocode}
%  Now re-define the command that makes the bibliography labels.
%  I'll comment that in detail, the same trick is used below with
%  fewer comments for all sorts of other things.
%    \begin{macrocode}
  \renewcommand{\@mklab}[1]{%
%    \end{macrocode}
%  Increase the counter and automatically generate a label.
%    \begin{macrocode}
    \refstepcounter{autolabels}%
    \label{autolabel:\theautolabels}%
%    \end{macrocode}
%  In the first run of \LaTeX, the label does not exists yet
%  (it has to be read back from an |.aux| file).  To prevent
%  an error, assume that the page on which
%  this bibliography entry starts is page number 1.
%    \begin{macrocode}
    \expandafter\ifx\csname r@autolabel:\theautolabels \endcsname\relax %
      \edef\ThePage{1}%
    \else %
      \edef\ThePage{\pageref{autolabel:\theautolabels}}%
    \fi %
%    \end{macrocode}
%  Now typeset the lable into \emph{both} margins and align it to
%  the right if it is in the right margin.  Display it only on the
%  side where it is needed.  Doinf this is very important, if the
%  boxes are not precisely identical, \LaTeX might typeset it at
%  the bottom of page~130 in the first run, then flip the label to
%  the other side in the second run, but find out that the whole
%  thing should better be placed at the top of page~131.  Then it
%  would go back again in the run after, and oscillate for ever.
%  I really don't whant this!
%    \begin{macrocode}
    \makebox[0pt][l]{\hbox{}\hskip\textwidth \hskip\marginparsep %
      \ifodd\ThePage {##1}\else \phantom{##1}\fi}%
    \makebox[0pt][l]{\hbox{}\hskip-\marginparsep \makebox[0pt][r]{%
        \ifodd\ThePage \phantom{##1}\else{##1}\fi }}%
    \hfil\hbox{}}
  \list{\@biblabel{\@arabic\c@enumiv}}%
%    \end{macrocode}
%  Since the labels are now in the margin, I have to remove the
%  space that is normally assigned to the labels.
%    \begin{macrocode}
  {\labelwidth=0pt%
    \leftmargin=0pt%
    \labelsep=0pt%
    \itemsep=1ex%
    \@openbib@code
    \usecounter{enumiv}%
    \let\p@enumiv\@empty
    \renewcommand\theenumiv{\@arabic\c@enumiv}}%
  \sloppy
  \clubpenalty4000
  \@clubpenalty \clubpenalty
  \widowpenalty4000%
  \sfcode`\.\@m}
{%
  \normalsize %
  \def\@noitemerr
  {\@latex@warning{Empty `thebibliography' environment}}%
  \endlist}
%    \end{macrocode}
%
% \section{Captions}
%
%  Rotated figures need a conventional caption style, so I generate
%  a flag saying whether we are inside a rotated float
%  (adapted from |rotating.sty|).
%    \begin{macrocode}
\renewcommand\sidewaysfigure{\let\inside@rotated@float=\relax %
  \@rotfloat{figure}}
\renewcommand\sidewaystable{\let\inside@rotated@float=\relax %
  \@rotfloat{table}}
%    \end{macrocode}
%  The command |\caption| generates the automatic label.
%    \begin{macrocode}
\def\caption{%
  \ifx\@captype\@undefined
    \@latex@error{\noexpand\caption outside float}\@ehd
    \expandafter\@gobble
  \else
    \stepcounter{autolabels}%
    \refstepcounter\@captype
    \label{autolabel:\theautolabels}%
    \expandafter\@firstofone
  \fi
  {\@dblarg{\@caption\@captype}}%
  }
%    \end{macrocode}
%  The definition of the following macro is |\long| in order to allow more
%  than one paragraph in the argument of |\caption|.
%    \begin{macrocode}
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \expandafter\ifx\csname r@autolabel:\theautolabels \endcsname\relax %
    \edef\ThePage{1}%
  \else %
    \edef\ThePage{\pageref{autolabel:\theautolabels}}%
  \fi
%    \end{macrocode}
%  Captions of normal floats:
%  Place a zero-width box that puts its contents
%  right-aligned.  The contents are a zero-width box that
%  places a left-aligned label, and two horizontal spaces.
%  Then typeset the caption text |\raggedright| (without
%  hyphenation) and |\raggedleft| into full-width parboxes.
%  Finally, append a zero-width
%  box.  Inside, move to the right edge of the margin, and
%  put another zero-width box that places a right-aligned
%  caption label.  (Note how the trick against oscillations
%  is used again.)
%    \begin{macrocode}
  \ifx\inside@rotated@float\undefined
      \makebox[0pt][r]{\makebox[0pt][l]{\CapNumFont %
          \ifodd\ThePage \phantom{#1}\else {#1}\fi}%
        \hskip\marginparsep \hskip\marginparwidth \hbox{}}%
      \makebox[0pt][l]{%
        \ifodd\ThePage %
        \parbox[t]{\TotalWidth-\MarginParWidth-\MarginParSep}%
        {\raggedleft \CapFont #2}%
        \else %
        \phantom{\parbox[t]{\TotalWidth-\MarginParWidth-\MarginParSep}%
          {\raggedleft \CapFont #2}}%
        \fi}%
      \makebox[0pt][l]{%
        \ifodd\ThePage %
        \phantom{\parbox[t]{\TotalWidth-\MarginParWidth-\MarginParSep}%
          {\raggedright \CapFont #2}}%
        \else %
        \parbox[t]{\TotalWidth-\MarginParWidth-\MarginParSep}%
        {\raggedright \CapFont #2}%
        \fi}%
      \hfill %
      \makebox[0pt][l]{\hbox{}\hskip\marginparsep \hskip\marginparwidth %
        \makebox[0pt][r]{\CapNumFont %
          \ifodd\ThePage {#1}\else \phantom{#1}\fi}}%
    \vskip\belowcaptionskip %
%    \end{macrocode}
%  Captions of rotated floats are treated as in |books.cls|.
%    \begin{macrocode}
  \else
    \sbox\@tempboxa{{\CapNumFont #1:} \CapFont #2}%
    \ifdim \wd\@tempboxa >\hsize
      {\CapNumFont #1:} \CapFont #2\par
    \else
      \global \@minipagefalse
      \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
    \fi %
  \fi}
%    \end{macrocode}
%  Finally, set the vertical spacing of captions.
%    \begin{macrocode}
\setlength\abovecaptionskip{6\p@}
\setlength\belowcaptionskip{10\p@}
%    \end{macrocode}
%
% \section{Parts, Chapters, Sections, \ldots}
%
%  No headings on the page where a part begins.
%    \begin{macrocode}
\renewcommand\part{%
  \if@openright \cleardoublepage \else \clearpage \fi
  \thispagestyle{empty}%
%    \end{macrocode}
%  Never ever swap to twocolumn-mode afterwards!
%    \begin{macrocode}
  \@tempswafalse
%    \end{macrocode}
%  I need an empty box to prevent the fil glue from disappearing.
%    \begin{macrocode}
  \null\vfil
%    \end{macrocode}
%  Use |\secdef| to indicate which commands to use to make
%  the actual heading.
%    \begin{macrocode}
  \secdef\@part\@spart}
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
%    \end{macrocode}
%  Clear the mark registers and center the title on the page.
%  Also prevent breaking between
%  lines, and reset the font.  Finally, use a box that spans the full
%  width of the page (defined below).
%    \begin{macrocode}
    \markboth{}{}%
    \fullwidthbox{%
      \centering
      \interlinepenalty \@M
      \normalfont
      \ifnum \c@secnumdepth >-2\relax
        \huge\ChapFont \partname~\thepart
        \par
        \vskip 20\p@
      \fi
      \Huge \ChapFont #2\par%
    }
    \@endpart}
%    \end{macrocode}
%  The following macro does the actual formatting of the title of
%  the part when the star form of the user command was used.
%  In this case never print a number. Otherwise the formatting
%  is the same.
%    \begin{macrocode}
\def\@spart#1{%
    \fullwidthbox{
      \centering
      \interlinepenalty \@M
      \normalfont
      \Huge \ChapFont #1\par%
    }
    \@endpart}
%    \end{macrocode}
%
%  The chapter start page gets a special layout:
%    \begin{macrocode}
\renewcommand\chapter{%
  \if@openright \cleardoublepage \else \clearpage \fi
  \thispagestyle{empty}%
  \@tempswafalse
%    \end{macrocode}
%  Prevent floats from appearing at the top of this page
%  because it looks weird to see a floating object above a chapter
%  title.
%    \begin{macrocode}
  \global\@topnum\z@
%    \end{macrocode}
%  Supress the indentation of the first paragraph by
%  setting the switch |\@afterindent| to false.  Use |\secdef|
%  to specify the macros to use for actually setting the chapter
%  title.
%    \begin{macrocode}
  \@afterindentfalse
  \secdef\@chapter\@schapter}
%    \end{macrocode}
%  The chapter always starts on an odd page, so playing with
%  spaces is not difficult here.  First normal chapters,
%  then the ones where the star form was used.
%  Note that the |\vskip| after the numbered version of the
%  chapter head is only |12\p@|, since a |\chapquote| is 
%  expected afterwards that gives the remaining |40\p@|. 
%    \begin{macrocode}
\def\@makechapterhead#1{%
  {\parindent \z@ \raggedleft \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge \ChapFont \@chapapp\space \thechapter
        \par\nobreak
        \vskip 12\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \ChapFont #1\par\nobreak
    \vskip 12\p@
  }}
\def\@makeschapterhead#1{%
  {\parindent \z@ \raggedleft
    \normalfont
    \interlinepenalty\@M
    \Huge \ChapFont  #1\par\nobreak
    \vskip 40\p@
  }}
%    \end{macrocode}
%
% \begin{macro}{\chapquote}
% \begin{macro}{\chapnoquote}
%  And here comes the macro for quotations, use as
%  |\chapquote{Quotation}{Author}|.  If you don't want
%  quotes after chapter titles, use |\chapnoquote| 
%  to correct the vertical spacing.
%    \begin{macrocode}
\newcommand{\chapquote}[2]{%
  {\ChapFont
    \RaggedLeft #1
    
    (#2)
    \vskip 40\p@
    }}
\newcommand{\chapnoquote}{\null\vskip 28\p@}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{environment}{chapabstract}
%  In my dissertation, I used raggedright, but this looks ugly on
%  the chapter title page.  So I wrote the following environment
%  that switches |\RaggedRight| off and used it for writing
%  the abstracts of the chapters.
%    \begin{macrocode}
\newenvironment{chapabstract}{%
  \setlength{\leftskip}   {\z@skip}%
  \setlength{\@rightskip} {\z@skip}%
  \setlength{\rightskip}  {\@rightskip}%
  \parfillskip=0pt plus 1fil %
  }{\par}
%    \end{macrocode}
% \end{environment}
%
%  Use a different font for sections:
%  The following  gives a normal heading with white space above
%  and below the section heading, the title set in |\SecFont\Large|,
%  and no indentation on the first paragraph.
%    \begin{macrocode}
\renewcommand{\section}{%
  \@startsection {section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\SecFont\Large}}
\renewcommand{\subsection}{%
  \@startsection{subsection}{2}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\SecFont\large}}
\renewcommand{\subsubsection}{%
  \@startsection{subsubsection}{3}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\SecFont\normalsize}}
%    \end{macrocode}
%  Paragraphs are never numbered; they just make their
%  Argument bold.
%    \begin{macrocode}
\renewcommand{\paragraph}[1]{\noindent\textbf{#1}}
%    \end{macrocode}
%  No trailing period in the section number
%    \begin{macrocode}
\def\@seccntformat#1{\csname the#1\endcsname}
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
%    \end{macrocode}
%  If the present section is not numbered, assume that
%  it is on an odd page.  This does not matter since
%  no section number will be typeset (see below).
%    \begin{macrocode}
    \edef\ThePage{1}
  \else
    \stepcounter{autolabels}
    \refstepcounter{#1}%
    \expandafter\ifx\csname r@autolabel:\theautolabels \endcsname\relax %
      \edef\ThePage{1}%
    \else %
      \edef\ThePage{\pageref{autolabel:\theautolabels}}%
    \fi
%    \end{macrocode}
%  Since |\@seccntformat| might end with an improper |\hskip| which
%  is scanning forward for plus or minus, we end the definition
%  of |\@svsec| with |\relax| as a precaution.
%    \begin{macrocode}
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \ifdim \@tempskipa>\z@
    \begingroup
%    \end{macrocode}
%  To prevent oscillation as well as possible, always typeset
%  the section number on both sides of the section heading, but
%  one will always be invisible.
%    \begin{macrocode}
      {%
%    \end{macrocode}
%  Label in the right margin: typeset a zero-width box whose
%  argument is left-aligned.  The argument contains spaces to move
%  the inner zero-width box to the right edge of the margin.  
%    \begin{macrocode}
        \makebox[0pt][l]{%
          \hbox{}\hskip\textwidth \hskip\marginparsep %
          \hskip\marginparwidth \makebox[0pt][r]{#6\SecNumFont %
            \ifodd \ThePage \@svsec \else \phantom{\@svsec}\fi %
            }}%
%    \end{macrocode}
%  Label in the left margin: analogous.
%    \begin{macrocode}
        \makebox[0pt][r]{%
          \makebox[0pt][l]{#6\SecNumFont %
            \ifodd \ThePage \phantom{\@svsec}\else \@svsec \fi }%
          \hskip\marginparwidth \hskip\marginparsep}%
%    \end{macrocode}
%  And now comes the section title itself.
%    \begin{macrocode}
        #6{\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
%    \end{macrocode}
%  Unnumbered sections
%    \begin{macrocode}
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8}%
      \csname #1mark\endcsname{#7}%
      \addcontentsline{toc}{#1}{%
        \ifnum #2>\c@secnumdepth \else
          \protect\numberline{\csname the#1\endcsname}%
        \fi
        #7}}%
  \fi
  \@xsect{#5}%
  \ifnum #2>\c@secnumdepth %
%    \end{macrocode}
%  Don't generate an automatic label for unnumbered sections.
%    \begin{macrocode}
  \else %
  \label{autolabel:\theautolabels}%
  \fi %
  }
%    \end{macrocode}
%
% \section{Boxes extending into the margin}
%
% \begin{macro}{\fullwidthbox}
%  Macro that can typeset things into the margin and uses
%  the full available width of the document
%    \begin{macrocode}
\long\def\fullwidthbox#1{%
  \stepcounter{autolabels}%
%    \end{macrocode}
%  Save the label of this box for later, in case
%  the counter |autolabels| is changed within the argument.
%    \begin{macrocode}
  \def\@fullwidthboxlabel{autolabel:\theautolabels}%
  \expandafter\ifx\csname r@autolabel:\theautolabels \endcsname\relax %
    \edef\ThePage{1}%
  \else %
    \edef\ThePage{\pageref{autolabel:\theautolabels}}%
  \fi %
  \ifodd\ThePage %
%    \end{macrocode}
%  No shift on odd pages.
%    \begin{macrocode}
  \else %
%    \end{macrocode}
%  Shift to the left edge of the margin on even pages.
%    \begin{macrocode}
    \hbox{}\hskip-\marginparwidth \hskip-\marginparsep %
  \fi %
  \makebox[0pt][l]{%
    \begin{minipage}{\linewidth+\marginparwidth+\marginparsep}%
      #1%
    \end{minipage}%
    }%
%    \end{macrocode}
%  The following line is adapted from the definition of
%  |\refstepcounter| in |latex.ltx| (actually |ltxref.dtx|).  It
%  forces |\label| on the line after to write down the correct
%  page number.
%    \begin{macrocode}
      \protected@edef\@currentlabel{\relax}%
      \label{\@fullwidthboxlabel}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fullwidthinfloat}
%  The same again for use in Figures and other floats that already
%  have a label.  Arguments: |#1| is the label, |#2| contains whatever
%  goes into the box.
%    \begin{macrocode}
\long\def\fullwidthinfloat#1#2{%
  \expandafter\ifx\csname r@#1\endcsname\relax %
    \edef\ThePage{1}%
  \else %
    \edef\ThePage{\pageref{#1}}%
  \fi %
  \ifodd\ThePage %
  \else %
    \hbox{}\hskip-\marginparwidth \hskip-\marginparsep %
  \fi %
  \makebox[0pt][l]{%
    \parbox{\linewidth+\marginparwidth+\marginparsep}{%
      \ifodd\ThePage %
      \else %
      \null \hfill %
      \fi %
      \ifodd\ThePage \raggedright \else \raggedleft \fi %
      #2%
      }%
    }%
  }%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Abstract}
% \begin{macro}{\MarginPar}
% \begin{macro}{\MarginParVar}
%  Margin Paragraphs whose contents are aligned differently on even and odd
%  pages.  |\Abstract| makes a margin paragraph in |\foortnotesize|
%  that is left-aligned on even pages and right-aligned on odd pages.
%  |\MarginPar| does the same without changing the font size.
%  |\MarginParVar| is right-aligned on even pages and left-aligned
%  on odd pages.
%    \begin{macrocode}
\newcommand{\Abstract}[1]{%
  {\footnotesize %
  \marginpar[\footnotesize\raggedright\hspace{0pt}{#1}]%
  {\footnotesize\raggedleft\hspace{0pt}{#1}}}}
\newcommand{\MarginPar}[1]{%
  \marginpar[\RaggedRight\hspace{0pt}{#1}]{\RaggedLeft\hspace{0pt}{#1}}}
\newcommand{\MarginParVar}[1]{%
  \marginpar[\RaggedLeft\hspace{0pt}{#1}]{\RaggedRight\hspace{0pt}{#1}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \section{Background environment}
%
% \begin{environment}{background}
%  Described in the introduction.  It just changes the font.
%    \begin{macrocode}
\newenvironment{bkgnd}{\begingroup \BackgroundFont}{\endgroup}
%    \end{macrocode}
% \end{environment}
%
% \clearpage
% \section{Title Page \ldots}
%
% \begin{macro}{\DTauthor}
% \begin{macro}{\DTborn}
% \begin{macro}{\DTcitizen}
% \begin{macro}{\DTdate}
% \begin{macro}{\DTdegree}
% \begin{macro}{\DTexaminers}
% \begin{macro}{\DTnumber}
% \begin{macro}{\DTtitle}
% \begin{macro}{\DTvolume}
% \begin{macro}{\DTissn}
% \begin{macro}{\DTisbn}
% \begin{macro}{\DTprice}
% \begin{macro}{\DTimage}
%  These thirteen macros contain the information to be typeset on the
%  title page.  |\DTimage| may contain the file name of image,
%  which must be in EPS and have aspect ratio 32x202\@. The image
%  should be comparatively dark, since the writing on top of it is white.
%  If no image file is given, a black rectangle is used.
%    \begin{macrocode}
\newcommand{\DTauthor}{Hanspeter Schmid}
\newcommand{\DTborn}{February 8, 1969}
\newcommand{\DTcitizen}{H\"arkingen SO}
\newcommand{\DTdate}{November 2000}
\newcommand{\DTdegree}{dipl.\ El.-Ing.\ ETH}
\newcommand{\DTexaminers}{Prof.\ Dr.\ George S. Moschytz, examiner\\
  Prof.\ Dr.\ Qiuting Huang, co-examiner}
\newcommand{\DTnumber}{13878}
\newcommand{\DTtitle}{Single-Amplifier\\ Biquadratic\\ MOSFET--C Filters}
\newcommand{\DTvolume}{1}
\newcommand{\DTissn}{1616-671X}
\newcommand{\DTisbn}{3-89649-616-6}
\newcommand{\DTprice}{98,--}
%\newcommand{\DTimage}{test1g.eps}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%  The following code defines the text for the title page
%  according to the options passed to |hpsdiss.cls|.
%    \begin{macrocode}
\newcommand{\DT@accepted}{accepted on the recommendation of}
\newcommand{\DT@born}{born on}
\newcommand{\DT@citizen}{citizen of}
\newcommand{\DT@dissertation}{A dissertation submitted to the\\
  Swiss Federal Institute of Technology, Z\"urich\\
  for the degree of}
\newcommand{\DT@dissertationB}{}
\newcommand{\DT@doctor}{Doctor of Technical Sciences}
\ifx\DT@scnat\undefined\else
  \renewcommand{\DT@doctor}{Doctor of Natural Sciences}
\fi
\ifx\DT@scmath\undefined\else
  \renewcommand{\DT@doctor}{Doctor of Mathematics}
\fi
\newcommand{\DT@number}{Diss.~ETH No~}
\newcommand{\DT@presented}{presented by}
\ifx\DT@deutsch\undefined\else
  \renewcommand{\DT@accepted}{Angenommen auf Antrag von}
  \renewcommand{\DT@born}{geboren am}
  \renewcommand{\DT@citizen}{von}
  \renewcommand{\DT@dissertation}{Abhandlung\\
    zur Erlangung des Titels}
  \renewcommand{\DT@dissertationB}{\\der Eidgen\"ossischen 
    Technischen Hochschule Z\"urich}
  \ifx\DT@female\undefdined
    \newcommand{\DT@@doctor}{Doktor}
  \else
    \newcommand{\DT@@doctor}{Doktorin}
  \fi
  \renewcommand{\DT@doctor}{\DT@@doctor\ der technischen 
    Wissenschaften}
  \ifx\DT@scnat\undefined\else
    \renewcommand{\DT@doctor}{\DT@@doctor\ der Naturwissenschaften}
  \fi
  \ifx\DT@scmath\undefined\else
    \renewcommand{\DT@doctor}{\DT@@doctor\ der Mathematik}
  \fi
  \renewcommand{\DT@number}{Diss.~ETH Nr.~}
  \renewcommand{\DT@presented}{vorgelegt von}
\fi
\ifx\DT@italiano\undefined\else
  \renewcommand{\DT@accepted}{accettata su proposta di}
  \renewcommand{\DT@born}{nato il}
  \renewcommand{\DT@citizen}{attinente di}
  \renewcommand{\DT@dissertation}{Dissertatzione presentata al\\
    Politecnico Federale di Zurigo\\
    per il conseguimento del titolo di}
  \renewcommand{\DT@doctor}{Dottore in scienze techniche}
  \ifx\DT@scnat\undefined\else
    \renewcommand{\DT@doctor}{Dottore in scienze naturali}
  \fi
  \ifx\DT@scmath\undefined\else
    \renewcommand{\DT@doctor}{Dottore in matematica}
  \fi
  \renewcommand{\DT@number}{Diss.~ETH no~}
  \renewcommand{\DT@presented}{da}
\fi
\ifx\DT@francais\undefined\else
  \renewcommand{\DT@accepted}{accept\'ee sur proposition du}
  \ifx\female\undefined
    \renewcommand{\DT@born}{n\'e le}
  \else
    \renewcommand{\DT@born}{n\'ee le}
  \fi
  \renewcommand{\DT@citizen}{originaire de}
  \renewcommand{\DT@dissertation}{pr\'esent\'ee \`a\\
    L'\'Ecole Polytechnique F\'ed\'erale Z\"urich\\
    pour l'obtention du titre de}
  \renewcommand{\DT@doctor}{Docteur d\'es sciences techniques}
  \ifx\DT@scnat\undefined\else
    \renewcommand{\DT@doctor}{Docteur d\'es sciences naturelles}
  \fi
  \ifx\DT@scmath\undefined\else
    \renewcommand{\DT@doctor}{Docteur d\'es sciences math\'ematiques}
  \fi
  \renewcommand{\DT@number}{Th\`ese~EPFZ No~}
  \renewcommand{\DT@presented}{par}
\fi
%    \end{macrocode}
%
% \begin{macro}{\disstitle}
% \begin{macro}{\dissinnertitle}
% \begin{macro}{\dissback}
%  These macros print the title page, the internal title page
%  (without the image or black rectangle, but with the name
%  of the publisher in front of the date),
%  and the back side of the book.
%
%  The correct numbers in the command |\begin{picture}(0,0)(220,110)|
%  depend on the page layout.
%    \begin{macrocode}
\newcommand{\dissinnertitle}{%
  \newcommand{\DT@innertitle}{\relax}%
  \disstitle}
\newcommand{\disstitle}{%
  \thispagestyle{empty}%
  {\parskip=0pt%
    \parindent=0pt%
    \unitlength=0.1mm%
    \null\vfill%
    \begin{picture}(0,0)(220,110)%
      \ifx\DT@innertitle\undefined
      \put(40,40){%
        \makebox(0,0)[bl]{%
          \ifx\DTimage\undefined %
          \rule{32mm}{202mm}%
          \else %
          \includegraphics[width=32mm,height=202mm]{\DTimage}%
          \fi %
          }}
      \fi
      \put(60,2020){%
        \makebox(0,0)[tl]{%
          \hbox to 28mm{%
            \vbox to 194mm{%
              \begin{minipage}[t]{28mm}
                \DTfont@series \Large \raggedleft
                \White{Series in}%
                \makebox[0cm][l]{\null\hspace*{6mm}\hbox{%
                    \normalsize \DTfont@normal %
                    \DT@number \DTnumber}}\\
                \White{Signal and}\\
                \White{Information}\\
                \White{Processing}\\[1.5ex]
                \White{Volume \DTvolume}
              \end{minipage}

              \vfill

              \begin{minipage}[b]{28mm}
                \DTfont@series \Large \raggedleft
                \White{Hartung}\\
                \White{Gorre}\\
                \White{Konstanz}%
                \makebox[0cm][l]{\null\hspace*{6mm}\hbox{%
                    \normalsize \DTfont@normal %
                    \ifx\DT@innertitle\undefined\else %
                      Hartung-Gorre Verlag, Konstanz, %
                    \fi %
                    \DTdate}}
              \end{minipage}}}}}
      \put(400,2020){%
        \makebox(0,0)[tl]{%
          \hbox to 97mm{%
            \vbox to 194mm{%
              \DTfont@normal \phantom{\DT@number \DTnumber}
              
              \vfill
              
              \Huge {\DTfont@title \DTtitle}
              
              \normalsize
              
              \vfill
              
              \DT@dissertation\\
              \DT@doctor \DT@dissertationB
              
              \vfill
              
              \DT@presented
              
              \medskip
              
              \LARGE {\DTfont@author \DTauthor}
              \normalsize
              
              \medskip
              \DTdegree\\
              \DT@born\ \DTborn\\
              \DT@citizen\ \DTcitizen
              
              \vfill
              
              \DT@accepted\\
              \DTexaminers
              
              \bigskip
              
              \phantom{\DTdate}
              }}}}%
    \end{picture}%
    }%
  \clearpage
  \thispagestyle{empty}
  \hbox{}
  \clearpage}
\newcommand{\dissback}{%
  \thispagestyle{empty}
  \hbox{}
  \clearpage
  \thispagestyle{empty}%
  {\parskip=0pt%
    \parindent=0pt%
    \unitlength=0.1mm%
    \null\vfill%
    \begin{picture}(0,0)(360,110)%
      \put(80,2020){%
        \makebox(0,0)[tl]{%
          \hbox to 132.5mm{%
            \vbox to 194mm{%
              \null\vfill
              
              \begin{minipage}[b]{132.5mm}
              \Large
              \DTfont@series 
              Series in Signal and Information Processing\\
              \DTfont@normal edited by Hans-Andrea Loeliger\\[1.5ex]
              $\boldsymbol \sum$ Hartung-Gorre Verlag 
              Konstanz\\[1.5ex]
              ISSN \DTissn\quad ISBN \DTisbn\quad DM \DTprice
              \end{minipage}
              }}}}%
    \end{picture}%
    }}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \section{Conclusion}
%
%  I was convinced by people on |comp.text.tex| to submit this class
%  to CTAN such that people might learn from it.  Thanks to everybody
%  who commented on my layout, I have used some of the comments to
%  improve the look of my dissertation.
%
% \Finale
%