% A format file for 18.310J/6.046J: Intro. to Algorithms

% All of these are amgreene's macros.  (Thanks, Rhu!)
\input fonts
\input margins
\input environments
\input shorthand

% Let's use Rhu's defaults.
\setmargins

% Change some standard dimens
\parskip=2\parskip

% Activate @
\expandafter\xdef\csname c@tcode\endcsname{\the\catcode`\@}
\catcode`\@=11

% This needs to be run while @ is active
% Only use times-roman if working on the final copy.  Otherwise, it screws
% with xdvi.
\expandafter\ifx\csname timesroman\endcsname\relax%
\relax%
\else%
\input PS-timrom%
\fi

% Or use newcen.
\expandafter\ifx\csname newcen\endcsname\relax%
\relax%
\else%
\input PS-newcen%
\fi

% Or use bookman.
\expandafter\ifx\csname bookman\endcsname\relax%
\relax%
\else%
\input PS-bookman%
\fi


% The title
% Massachusetts Institute of Technology       	   DATE
% 6.046J/18.410J: Intro...                   RECITATION
% MY NAME
% -----------------------------------------------------
%               Problem Set Number

\def\maketitle{%
\line{Massachusetts Institute of Technology\hfil\d@te}%
\line{18.410J/6.046J: Introduction to Algorithms\hfil Recitation \recit@tion}%
\line{\n@me\hfil}%
\line{\hrulefill}
\bigskip
\centerline{\larger **Problem Set \@psnum**}
\medskip
}

% Title info
\def\name#1{\def\n@me{#1}}
\def\psnum#1{\def\@psnum{#1}}
\def\date#1{\def\d@te{#1}}
\def\recitation#1{\def\recit@tion{#1}}


% No headline on page one.  On other pages, look kinda like Leiserson's
% handouts.
%
% Name              Problem Set Number            Page Number

\headline={%
\ifnum\pageno=1 \hfil% 
\else\sl\n@me\hss Problem Set \@psnum\hss Page \folio% 
\fi%
}

% No footline

\footline{%
}

% New math functions
\def\lg{\mathop{\hbox{\rm lg}}\nolimits}

% Macros for exercise and problems
\def\exercise#1{\bgroup%
\par\bigskip\noindent{\bf Exercise \@psnum.#1}\quad%
}
\def\endexercise{\par\egroup\bigskip}

\def\problem#1{\bgroup%
\f@@tnum=0%		Reset the footnote number.
\centerline{\large \bf Problem \@psnum-#1}%
\medskip%
}
\def\endproblem{\par\egroup\vfill\eject}

% Encourage page breaks at new parts.
\def\part #1\par{\vskip0pt plus.3\vsize\penalty-250%
\vskip0pt plus-.3\vsize
\noindent\llap{**#1**\enspace}}

% An environment for pseudo-code.  Stolen and translated from bjaspan.
%% Boldface pseudo-programming keywords
\def\cfor{{\bf for\ }}
\def\cto{{\bf to\ }}
\def\cdo{{\bf do\ }}
\def\cif{{\bf if\ }}
\def\cthen{{\bf then\ }}
\def\celse{{\bf else\ }}
\def\cwhile{{\bf while\ }}
\def\cand{{\bf and\ }}
\def\creturn{{\bf return\ }}

%% An environment for functions
\def\gets{$\leftarrow$}
\def\swap{$\leftrightarrow$}
\def\fcall#1#2{{\sc #1}($#2$)}
\def\fname#1{{\sc #1}}
\def\comment{$\triangleright$\enskip}

% This count register is for line counting
\newcount\@lineno

% !!!! Need to deal with the unaligned line numbers.

% The function environment for pseudo-code
\def\function#1#2{\medskip\bgroup%
\@lineno=0\relax%
\def\myreturn{\cr}%
\let\par=\myreturn%
\def~{\advance\@lineno by 1\tabalign&&\hskip2pt\the\@lineno&}%
\settabs 20 \columns\obeylines%
\tabalign%
&&\fcall{#1}{#2}%
}

\def\endfunction{\egroup\medskip}

% Save old value of \end and \bye since I'm about to trash them
\let\@@end=\end
\def\bye{\par\vfill\supereject\@@end}

% Simple environment commands that I think will work.
\def\begin#1{\csname #1\endcsname}
\def\end#1{\csname end#1\endcsname}

%% Footnote stuff
\let\f@@tnote=\footnote
\def\footnote#1{\advance\f@@tnum by1\f@@tnote{\prf@@tnum}{#1}}
\def\prf@@tnum{$^\the\f@@tnum$}
\newcount\f@@tnum
\f@@tnum=0

% 12 point default
\elevenpoint

% Deactivate %
\catcode`\@=\c@tcode




