%
% Hungry.sty -- A LaTeX style file which will give all your hungry documents
%               the distinctive hungry style.
%
% (c) 1996 The Hungry Programmers
% (c) 1996 Harald Albrecht (albrecht@igpm.rwth-aachen.de)
% See the file PUBLIC for details.
%
\typeout{Hungry Documentation Style Extensions <25-DEC-1996>}
%
% --- First, some useful macros for typesetting ------------------------------
% \code{abc}        -- Typesets the string "abc" in a non-proportional type-
%                      writer font. As the P*stScr*pt Courier font looks
%                      slightly larger then a Times Roman font of the same
%                      point size the \code macro typesets the string "abc"
%                      in a smaller point size than the main text.
% \keycap{abc}      -- This will put the string "abc" into a box. This way, it
%                      looks much like a key.
% 
\newcommand{\code}[1]{{\texttt{\fontsize{10.5}{\f@baselineskip}\selectfont#1}}}
\newcommand{\@indexcode}[1]{{\texttt{\fontsize{9.5}{\f@baselineskip}\selectfont#1}}}
\newcommand{\keycap}[1]{%
  {\fontsize{8}{\f@baselineskip}\selectfont\raisebox{0pt}[0pt][0pt]{\fbox{\textsf{#1}}}}%
}
\newcommand{\bslash}{\symbol{92}}
\newcommand{\circled}[1]{\textcircled{\footnotesize#1}}
\newcommand{\leftbrace}{\symbol{123}}  % only valid for T1 encoding
\newcommand{\rightbrace}{\symbol{125}} % only valid for T1 encoding
%
\newlength{\@indlevel}
\newcommand{\ind}[1]{%
  \setlength{\@indlevel}{#1cm}%
  \divide\@indlevel by 3%
  \multiply\@indlevel by 2%
  \hspace*{\@indlevel}%
}%
%
% --- Indexing tools ---------------------------------------------------------
% \codeindex        -- Use whenever you want to include an identifier in the
%                      index. Identifiers and constants are typeset with the
%                      Courier font.
% \codecomposeindex -- much like \codeindex but takes two parameters. The
%                      first parameter is typeset with the Courier font where-
%                      as the second parameter is typeset in \normalfont.
% \LetterHeadFont   -- For internal use with makeindex only. This macro type-
%                      sets the letter head for each group of index entries
%                      in a 20pt bold Helvetica.
% {hungryindex}     -- New environment for use with makeindex only. Changes
%                      the page layout for the first index page slightly.
%
\newcommand{\codeindex}[1]{\index{#1@\string\code{#1}}}
\newcommand{\codecomposeindex}[2]{\index{#1\ #2@\string\code{#1}\ #2}}
\newcommand{\LetterHeadFont}%
  {\fontsize{20}{\f@baselineskip}\selectfont}
\newenvironment{hungryindex}
               {\if@twocolumn \@restonecolfalse \else \@restonecoltrue \fi
                \columnseprule \z@
                \columnsep 35\p@
                \twocolumn[\@makeschapterhead{\indexname}]%
                \@mkboth{\indexname}{\indexname}%
                \addcontentsline{toc}{chapter}{\indexname}%
                \parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \let\item\@idxitem
                \let\code\@indexcode
                \small}
               {\if@restonecol\onecolumn\else\clearpage\fi%
                \let\code=\code}
\newcommand{\backskip}{\vspace{-22pt}\vspace{-\f@baselineskip}}
%
% To get the index into the table of contents, we have to do dirty tricks
% here. If no index file "xxx.ind" yet exists, we create a dummy index page
% and add it to the toc. If we wouldn't create a dummy page, \addcontentsline
% won't add the index to the toc at all as there wouldn't get the index file
% "xxx.ind" included and as there wouldn't be a page at all.
%
\let\@oldprintindex=\printindex
\renewcommand{\printindex}{%
  \IfFileExists{\jobname.ind}%
    {\@oldprintindex}%
    {\typeout{No index \jobname.ind found. Don't care. Don't panic.}%
     \begin{hungryindex}\end{hungryindex}}
}
%
%
% --- New environments -------------------------------------------------------
% {itemlist}        -- Used for bullet'ed lists. In contrast to LaTeX's own
%                      itemize environment, there's almost no \topsep space
%                      before and after the item list. And the spacing between
%                      paragraphs has also been changed.
% {itemdescription} -- Used for explanations of structure items. Use \ITEM
%                      instead of \item for every item. This will typeset
%                      the item in the Courier font and begin the description
%                      on a new line.
% \ITEM             -- To be used within {itemdescription} environments.
% \shortstackl      -- Same as \shortstack[l]. Unfortunately \shortstack[l]
%                      can't be used with \ITEM or \item as the square brackets
%                      cause trouble.
%
\newenvironment{itemlist}%
  {\begin{itemize}%
     \parskip 0pt \topsep 0pt \partopsep 0pt \itemsep 0pt \parsep 0pt%
     \vspace{-.18in}}% Arrrgh! Empirial metrics!
  {\vspace{-.18in}\end{itemize}}%
\newcommand{\itemdescriptionlabel}[1]{\texttt{\fontsize{10.5}{\f@baselineskip}\selectfont#1}}%
\newcommand{\ITEM}[1][]{\item [{#1}]~\\}%
\newenvironment{itemdescription}%
  {\begin{list}{}{%
     \renewcommand{\makelabel}{\itemdescriptionlabel}%
     \parskip 0pt \topsep 5pt \partopsep 0pt \itemsep 3pt%
     \rightmargin 0pt%
     }}%
  {\end{list}}%
\gdef\shortstackl{\@shortstack[l]}
\newenvironment{itempacked}%
  {\begin{list}{}{%
     \parskip 0pt \topsep 5pt \partopsep 0pt \itemsep 3pt%
     \rightmargin 0pt%
     }}%
  {\end{list}}%
\gdef\shortstackl{\@shortstack[l]}
%
% --- This one changes the appearance of a chapter's front page --------------
% Always remember to put a \by command after the \chapter command, as the
% first macro closes the page and the following text will begin on the next
% page.
%
\def\@makechapterhead#1{%
  \vspace*{2.5cm}%
  {\parindent \z@\raggedright
    \ifnum \c@secnumdepth >\m@ne
      \begin{flushright}
        \ifnum \c@chapter > 0
          {\sffamily\fontsize{128}{\f@baselineskip}\selectfont\thechapter}\\
        \else
          {\sffamily\fontsize{128}{\f@baselineskip}\selectfont\vspace{75pt}}
        \fi
      \end{flushright}
      \rule{\textwidth}{0.5mm}\par
    \fi
    \begin{flushright}
      {\sffamily\bfseries\fontsize{24}{1ex}\selectfont#1}
    \end{flushright}
  }
}
% We need to set a new bottom fraction value in order to put the LessTif
% typesetting on the chapter head pages.
\renewcommand{\bottomfraction}{0.5}
\newcommand{\by}[1]{%
  \begin{flushright}#1\end{flushright}%
  \begin{figure}[b]\hfill\includegraphics[scale=1.3]{LessTif}\end{figure}%
  \clearpage%
}
%
\renewcommand{\@makeschapterhead}[1]{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \Huge\sffamily\bfseries\fontsize{24}{1ex}\selectfont#1\par\nobreak
    \vskip 40\p@
  }}
%
% The \chapter and \l@chapter macros have been ripped of the classes.dtx file
% from the LaTeX2e distribution. The macros have been changed slightly to
% use the empty page style with chapter title pages and to use a bold Helvetica
% in the table of contents.
%
\renewcommand{\chapter}{%
  \if@openright\cleardoublepage\else\clearpage\fi%
  \thispagestyle{empty}%
  \global\@topnum\z@
  \@afterindentfalse
  \secdef\@chapter\@schapter
}
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \sffamily \bfseries \large
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\normalsize\par
      \penalty\@highpenalty
    \endgroup
  \fi}
%
% The following macros redefine the page style for the table of contents,
% list of figures and list of tables. They all now use the hungry page style
% even for their first page.
%
\newcommand{\tableofxxx}[2]{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{#1\@mkboth{#1}{#1}}
    \thispagestyle{hungry}
    \@starttoc{#2}%
    \if@restonecol\twocolumn\fi
    }
\renewcommand{\tableofcontents}{\tableofxxx{\contentsname}{toc}}
\renewcommand{\listoffigures}{\tableofxxx{\listfigurename}{lof}}
\renewcommand{\listoftables}{\tableofxxx{\listtablename}{lot}}
%
% Redefines header and footer. The headings differ for either one-sided
% or two-sided printing. Three-sided printing isn't (yet) supported.
%
\def\ps@hungry{%
  \let\@mkboth\markboth
  \def\@oddhead{%
    \hrulefill\sffamily\bfseries\hspace*{0.3cm}{\small\rightmark}\hspace*{0.5cm}\thepage}%
  \def\@evenhead{%
    \sffamily\bfseries\thepage\hspace*{0.5cm}{\small\leftmark}\hspace*{0.3cm}\hrulefill}%
  \def\@oddfoot{}%
  \def\@evenfoot{}%
  \if@twoside
    \def\chaptermark##1{%
      \markboth{\ifnum \c@chapter > 0 {%
        {\ifnum \c@secnumdepth >\m@ne \thechapter.\ \fi ##1}}\else{{##1}}\fi}{}}%
    \def\sectionmark##1{%
      \markright {{\ifnum \c@secnumdepth >\z@ \thesection. \ \fi ##1}}}%
  \else
    \def\chaptermark##1{%
      \markright{\ifnum \c@chapter > 0 {%
        {\ifnum \c@secnumdepth >\m@ne \thechapter.\ \fi ##1}}\else{{##1}}\fi}}%
  \fi
}
%
\newcommand{\hungrypagestyle}[2]{%
  \@namedef{ps@#1}{\let\hungry@def\def#2\relax\ps@hungry}}
%
%
% --- New title page environment ---------------------------------------------
% {hungrytitle}     -- Creates a title page with the distinctive hungry look.
%                      Use the following macros to create some standard items
%                      on the title page. The name(s) of the author(s) is/are
%                      then simply typed and gets justified to the right
%                      border.
% \TitlepageMotifation -- Your motif for writing the book.
% \TitlepageTitle      -- The Title of the book.
% \TitlepageSubtitle   -- For subtitle and date/edition.
%
\newenvironment{hungrytitle}
  {\begin{titlepage}\begin{flushright}}
  {\end{flushright}\end{titlepage}}
\def\TitlepageMotifation#1{\textsc{#1}\\[3cm]}
\def\TitlepageTitle#1{\textrm{\textbf{\fontsize{48}{52}\selectfont#1}}\\\rule{\textwidth}{1mm}\\}
\def\TitlepageSubtitle#1{#1\\[2cm]}
%
% Figure captions are slightly changed.
%
%
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{{\bfseries #1:\ }{\itshape #2}}%
  \ifdim \wd\@tempboxa >\hsize
    {\bfseries #1:\ }{\itshape #2}\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}
%
% --- A slightly improved verbatim environment -------------------------------
% {verbatim}        -- Almost as the usual verbatim environment. The only
%                      exceptions are the "!" and the "°". The "!" switches
%                      to a bold font and back, whereas the "°" switches to
%                      an italic font and back. They can be nested. If you
%                      want the characters verbatim, double them: "!!" results
%                      in a single exclamation mark.
%
\renewcommand \verbatim@font{%
  \normalfont\ttfamily\fontsize{9}{10}\selectfont%
  \let\do\do@noligs%
  \verbatim@nolig@list%
  \catcode`\!=\active
  \catcode`\°=\active
}
\begingroup
  \catcode`\!=\active
  \catcode`\°=\active
  \gdef!{\@ifnextchar!\@handleexcl\@metaexcl}
  \gdef\@metaexcl#1!{\textbf{#1}}
  \gdef\@handleexcl!{\char`\!}
  \gdef°{\@ifnextchar°\@handlecirc\@metacirc}
  \gdef\@metacirc#1°{\textit{#1}}
  \gdef\@handlecirc°{\char`\°}
\endgroup
%
% These new border settings allow for printing either on European A4 paper
% size or on american legal size. We aren't metric yet, are we...?
%
\setlength{\textheight}    {210.0mm}
\setlength{\textwidth}     {150.0mm}
\ifdim \paperwidth = 210mm
  \typeout{Hungry paper size is "A4".}
  \setlength{\topmargin}     {  6.6mm} % I'm a mechanical engineer, you know.
  \setlength{\oddsidemargin} { -0.4mm}
  \setlength{\evensidemargin}{  9.6mm}
  \special{papersize=210mm,297mm} % instruct dvips
\else
  \ifdim \paperwidth = 8.5in
    \typeout{Hungry paper size is "letter".}
    \setlength{\topmargin}     {  0.4mm}
    \setlength{\oddsidemargin} {  2.1mm}
    \setlength{\evensidemargin}{ 13.0mm}
    \special{papersize=8.5in,11in} % instruct dvips
  \else
    \@latexerr{paper size must be either "a4size" or "lettersize"}\@eha
  \fi
\fi
%
\setlength{\parindent}     { 0cm}
\setlength{\parskip}       { 7pt}
%
% Mistakes will be punished 'till the third generation, you know...
%
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
%
\frenchspacing
% End of hungry.sty
