% ----------------------------------------------------------------------
% Producing slides for selected lectures
% ----------------------------------------------------------------------

\newcounter{lecture}

\newcommand{\sublecture}{}
\renewcommand{\theslide}{\thelecture\sublecture.\arabic{slide}}
\newcommand{\class}[2]{
  \setcounter{lecture}{#1#2}
  \blackandwhite{lecture#1#2}
 }
\newcommand{\subclass}[3]{
  \setcounter{lecture}{#1#2}
  \begingroup
   \renewcommand{\sublecture}{#3}
   \blackandwhite{lecture#1#2#3}
  \endgroup
}

% ----------------------------------------------------------------------
% Table of Contents from Tim Freeman <tsf+@cs.cmu.edu>
% ----------------------------------------------------------------------

\newbox\toc
\global\setbox\toc=\vbox{}
% Use this when you know you'll need to do something to your document
% after it comes out of the printer.  First argument is the text to
% print on the terminal and put in the summary, second argument is the
% text to insert into your document.
\newcommand{\addtoc}[1]{
% Append it to the table of contents.
\global\setbox\toc=\vbox{\tiny\unvbox\toc\hbox{\strut\arabic{slide}: #1\strut}}
}
% Insert this in your document where you want the table of contents to appear.
\newcommand{\inserttoc}{\ \\\ \\\unvbox\toc}

% ----------------------------------------------------------------------
% SliTeX customizations from Benjamin Pierce <bcp+@cs.cmu.edu>,
% modified for DIN A4 in Germany by Frank Pfenning <fp+@cs.cmu.edu>
% -----------------------------------------------------------------------

\newlength{\bcpextraheight}
\newlength{\bcpextrawidth}
\setlength{\bcpextraheight}{2.4cm}
\setlength{\bcpextrawidth}{0cm}

\addtolength{\textwidth}{\bcpextrawidth}
\addtolength{\textheight}{\bcpextraheight}
\addtolength{\oddsidemargin}{-.5\bcpextrawidth}
\addtolength{\evensidemargin}{-.5\bcpextrawidth}
\addtolength{\topmargin}{-.5\bcpextraheight}

% For DIN A4 use instead:
% \newlength{\afourextraheight}
% \newlength{\afourextrawidth}
% \setlength{\afourextraheight}{3.4cm}
% \setlength{\afourextrawidth}{1cm}
% 
% \addtolength{\textwidth}{\afourextrawidth}
% \addtolength{\textheight}{\afourextraheight}
% \addtolength{\oddsidemargin}{-.5\afourextrawidth}
% \addtolength{\evensidemargin}{-.5\afourextrawidth}
% \addtolength{\topmargin}{-.5\afourextraheight}

\newcommand{\slidetitle}[1]{
  {\large #1} \addtoc{#1} \vspace{.1cm} \par  
                            \hrule% \vspace{-.5cm}\noindent}
 }
\newcommand{\upitem}{\vspace{-.8cm}\item}

% ----------------------------------------------------------------------
% Typesetting deductions.
% ----------------------------------------------------------------------

\newbox\tempa
\newbox\tempb
\newdimen\tempc
\newbox\tempd

\def\mud#1{\hfil $\displaystyle{#1}$\hfil}
\def\rig#1{\hfil $\displaystyle{#1}$}

\def\inruleanhelp#1#2#3{\setbox\tempa=\hbox{$\displaystyle{\mathstrut #2}$}%
                        \setbox\tempd=\hbox{$\; #3$}%
		        \setbox\tempb=\vbox{\halign{##\cr
	\mud{#1}\cr
	\noalign{\vskip\the\lineskip}%
	\noalign{\hrule height 0pt}%
	\rig{\vbox to 0pt{\vss\hbox to 0pt{\copy\tempd \hss}\vss}}\cr
	\noalign{\hrule}%
	\noalign{\vskip\the\lineskip}%
	\mud{\copy\tempa}\cr}}%
		      \tempc=\wd\tempb
		      \advance\tempc by \wd\tempa
		      \divide\tempc by 2 }

\def\inrulean#1#2#3{{\inruleanhelp{#1}{#2}{#3}%
		     \hbox to \wd\tempa{\hss \box\tempb \hss}}}

\def\ian#1#2#3{{\lineskip 4pt\inrulean{#1}{#2}{#3}}}
\def\ibn#1#2#3#4{{\ian{#1\hspace{3em}#2}{#3}{#4}}}

% \def\lowerhalf#1{\hbox{\raise -0.8\baselineskip\hbox{#1}}}

\def\ianc#1#2#3{{\lineskip 4pt\inruleanhelp{#1}{#2}{#3}%
			     \box\tempb\hskip\wd\tempd}}
\def\ibnc#1#2#3#4{{\lineskip 4pt\ianc{#1\quad\qquad #2}{#3}{#4}}}

% ----------------------------------------------------------------------
% Abbreviating macros for examples and text
% ----------------------------------------------------------------------

% For Prolog examples
\newcommand{\ba}{$\leftarrow$\ }

% For language descriptions
\newcommand{\bnfas}{\mathrel{::=}}
\newcommand{\bnfalt}{\mathrel{\mid}}

\newcommand{\lam}{\lambda}
\newcommand{\oftp}{\mathord{:}}
\newcommand{\hastype}{\mathrel{:}}
\newcommand{\ldot}{\mathord{.}}
\newcommand{\ldott}{\mathrel{.}}

\newcommand{\arrow}{\mathbin{\rightarrow}}
\newcommand{\fa}{\mathbin{\Rightarrow}} \newcommand{\Fa}{$\fa$\ }
\newcommand{\all}{\mathord{\forall}} \newcommand{\All}{$\all$\ }
\newcommand{\vd}{\null\mathrel{\vdash}}
% \newcommand{\th}{\null\mathrel{\vdash}}
\newcommand{\goesto}{\Longrightarrow}

\newcommand{\evalsto}{\mathrel{\hookrightarrow}}

% ----------------------------------------------------------------------
% Environments and environment modifications.
% ----------------------------------------------------------------------

\newcommand{\rulestretch}{\renewcommand{\arraystretch}{3}}
\newcommand{\widerulestretch}{\renewcommand{\arraystretch}{4}}

\newcommand{\rulespacing}{\rulestretch \arraycolsep 3em}
\newcommand{\normalarrayspacing}{\renewcommand{\arraystretch}{1}
  \arraycolsep 0em}

\newcommand{\ssloppy}{\hfuzz 35pt}

\newenvironment{example}{
 \begingroup \begin{tabbing} \hspace{2em} \= \kill}{
 \end{tabbing}\endgroup}

\let\um=\"

\def\thebibliography#1{\list
 {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}\leftmargin\labelwidth
 \advance\leftmargin\labelsep
 \usecounter{enumi}}
 \def\newblock{\hskip .11em plus .33em minus .07em}
 \sloppy\clubpenalty4000\widowpenalty4000
 \sfcode`\.=1000\relax}
\let\endthebibliography=\endlist

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\uscore{{\tt\char`\_}}
\def\lbrace{{\tt\char`\{}}
\def\rbrace{{\tt\char`\}}}

