% -*- latex -*-
% This stuff usually shows up in the decls.tex file of one my papers.
\makeatletter

%%% The DH4000 Apple Laserwriter subtracts a bit from the leftmargin (3.5pt)
%%% The Iron City DEC LPS-40     adds      a bit from to  leftmargin 
%%% The Laserwriter II Beryl     does it right --- 0 offset.
%\hoffset=4pt	% Laserwriter I
%\hoffset=-5pt   % LPS (calculated 7.12pt)

%% Headings for drafts:   date -- time         DRAFT         chap/page
%Compute the time
\newcount\timehh\newcount\timemm
\timehh=\time 
\divide\timehh by 60 \timemm=\time
\count255=\timehh\multiply\count255 by -60 \advance\timemm by \count255
\def\draftbox{{\protect\small\bf \fbox{DRAFT}}}
\def\drafttime{{\protect\small\sl\today\ -- 
\ifnum\timehh<10 0\fi\number\timehh\,:\,\ifnum\timemm<10 0\fi\number\timemm}}
\def\drafttimer{\protect\makebox[0pt][r]{\drafttime}}
\def\drafttimel{\protect\makebox[0pt][l]{\drafttime}}
\def\chappagel{\protect\makebox[0pt][l]{\rm\rightmark\thepage}}
\def\chappager{\protect\makebox[0pt][r]{\rm\leftmark\thepage}}
\def\draftheaders{
  \pagestyle{myheadings}
  \def\chaptermark##1{\markboth{\rm\ifnum\c@secnumdepth>\m@ne\thechapter/\fi}
			       {\rm\ifnum\c@secnumdepth>\m@ne\thechapter/\fi}}
  \def\sectionmark##1{}
  \def\@oddhead{\drafttimel\hfil\draftbox\hfil\chappager}
  \if@twoside \def\@evenhead{\chappagel\hfil\draftbox\hfil\drafttimer}
  \else \def\@evenhead{\drafttimel\hfil\draftbox\hfil\chappager}
  \fi
}

%% Headings for non-draft (like default, but no uppercasing):
\def\myheaders{%
  \def\chaptermark##1{\markboth%
    {\ifnum \c@secnumdepth > \m@ne \@chapapp\ \thechapter. \ \fi ##1}%
    {}}%
  \def\sectionmark##1%
    {\markright{\ifnum \c@secnumdepth > \z@ \thesection. \ \fi ##1}}%
}

% rep12.sty makes it 0 + 1, which is horrible for math.
\parskip 2pt plus 3pt

%Squeeze those figures onto pages.
%\renewcommand{\floatpagefraction}{0.25}
\renewcommand{\floatpagefraction}{0.7}
\renewcommand{\topfraction}{.9}
\renewcommand{\bottomfraction}{.9}
\renewcommand{\textfraction}{.1}
%\floatsep 4pt plus 2pt minus 4pt

%% Number figures and tables in the same sequence.
%% If you go to a list-of-tables or list-of-figures, you'll have to
%% do a little more than this.
\let\defaulttable\table
\let\defaultendtable\endtable
\def\table{%
  \bgroup\def\caption{\refstepcounter{figure} \@dblarg{\@caption{table}}}%
  \figure}
\def\endtable{\endfigure\egroup}
\def\fnum@table{Table \thefigure}
\def\ext@table{lof}

%% What you frequently want when you say \tt:
\def\ttt{\tt\catcode``=13\@noligs\frenchspacing}

\newcommand{\ttn}{\normalsize\ttt}
\newcommand{\tts}{\small\ttt}
\newcommand{\ttf}{\footnotesize\ttt}
\newcommand{\ttsc}{\scriptsize\ttt}

% Works in math mode; all special chars remain special; cheaper than \cd.
% Will not be correct size in super and subscripts, though.
\newcommand{\ex}[1]{\mbox{\ttt #1}} 

% Indent code examples -- for one line examples only. Blech.
%\newcommand{\codex}[1]
% {\begin{list}{}%
%	{\topsep=1mm\parsep=0pt\leftmargin=0pt\rightmargin=0pt}%
%	\item[]\centering\ttt{}#1%
%  \end{list}\vspace{-1\parskip}}

% This will lose in left-eqn mode.
\newcommand{\codex}[1]%		One line, centred. Tight spacing.
  {$$\abovedisplayskip=.75ex plus 1ex minus .5ex%
     \belowdisplayskip=\abovedisplayskip%
     \abovedisplayshortskip=0ex plus .5ex%
     \belowdisplayshortskip=\abovedisplayshortskip%
     \hbox{\ttt #1}$$}

%% TeX won't break words in \tt font. If you have a word like
%% 	call-with-current-continuation
%% you lose. If you mark potential breaks with \-'s, then when TeX
%% breaks the word, it adds its own hyphen, in roman font, in addition
%% to the \tt hyphen that's part of the variable name. So, instead,
%% mark the optional break with \ob.
%\newcommand{\ob}{\linebreak[0]} 
\renewcommand{\=}{\discretionary{-}{}{-}}

\newcommand{\remark}[1]{\mbox{$<<$}{\bf #1}\mbox{$>>$}}

% \boxit{3in}{stuff...} makes a 3in wide box, centred on the page.
\newcommand{\boxit}[2]{\makebox[\linewidth]{\fbox{\parbox{#1} {#2}}}}

\newcommand{\note}[1]{\{Note #1\}}
\newcommand{\itum}[1]{\item{\bf #1}\\*}
\newcommand{\itam}[1]{\item{\bf #1}} % if following text is math

\def\ie{\mbox{\em i.e.}}	% \mbox keeps the last period from
\def\Ie{\mbox{\em I.e.}}	% looking like an end-of-sentence.
\def\eg{\mbox{\em e.g.}}
\def\Eg{\mbox{\em E.g.}}
\def\etc{\mbox{\em etc.}}

\def\Lisp{{\sc Lisp}}
\def\FORTRAN{{\sc Fortran}}
\def\Orbit{{\sc Orbit}}
\def\sharpf{{\tt\#f}}

% For use in code. The \llap magicness makes the lambda exactly as wide as
% the other chars in \tt; the \hskip shifts it right a bit so it doesn't
% crowd the left paren -- which is necessary if \tt is cmtt.
% Note that (\l{x y} (+ x y)) uses the same number of columns in TeX form
% as it produces when typeset. This makes it easy to line up the columns
% in your input. \l is bound to some useless command in LaTeX, so we have to
% define it w/renewcommand.
\let\oldl\l %Save the old \l on \oldl
\renewcommand{\l}[1]{\ \llap{$\lambda$\hskip-.05em}\ (#1)}

%% Here are regexps to give gnumacs that will convert between lambda and \l:
%% (lambda (\([^)]*\))		(\\l{\1}
%% (\\l{\([^}]*\)}		(lambda (\1)
%%
%% And here are gnumacs functions to do same:
%% (defun detexify-lambdas () (interactive)
%%   (query-replace-regexp "(\\\\l{\\([^}]*\\)}" "(lambda (\\1)" nil))
%% (defun texify-lambdas () (interactive)
%%   (query-replace-regexp "(lambda (\\([^)]*\\))" "(\\\\l{\\1}" nil))


\newenvironment{inset}
 {\bgroup\parskip=1ex plus 1ex\begin{list}{}%
	{\topsep=0pt\rightmargin\leftmargin}%
	\item[]}%
 {\end{list}\leavevmode\egroup\global\@ignoretrue}

\newenvironment{tightinset}
 {\bgroup\parskip=0pt\begin{list}{}%
	{\topsep=0pt\rightmargin\leftmargin}%
	\item[]}%
 {\end{list}\leavevmode\egroup\ignorespaces}

% Make : ord so it will bind tightly as a code label.
\mathcode`\:="003A

\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}

%% \lreqn{left-side}{=}{right-side}. 
%% For long eqns that must be split onto two lines.
%% Left side flush left; right side flush right on next line.
\newcommand{\lreqn}[3]{$$\displaylines{\quad#1#2\hfill\cr\hfill{}#3\quad}$$}

%\newcommand{\proof}{\\{\bf Proof}\ }
\newcommand{\proof}{{\bf Proof:}\ }
%\newcommand{\qed}{\quad\hfill\mbox{$\Box$}}

% If this defn sticks the QED on its own line, it tries to disallow a
% pagebreak between the QED and the last line of the proof.
% Adapted from the TeXbook, pg. 106.
\newcommand{\qed} % in hmode case, can only break at the \penalty1
  {\ifhmode\bgroup\unskip\vadjust{\penalty10000}\nobreak\hfill\penalty1%
	   \hskip3em\hbox{}\nobreak\hfill\mbox{Q.E.D.}%
	   \vadjust{\penalty\interlinepenalty}%
	   \parfillskip=0pt\finalhyphendemerits=0\par\egroup%
   \else\penalty10000\hbox to\linewidth{\hfill Q.E.D.}%
	\penalty\interlinepenalty\fi}

% For multiletter vars in math mode:
\newcommand{\var}[1]{{\it #1}}

%% For chapter and section quotes:
\newcommand{\headingquote}[2]
{\begin{flushright}\em\begin{tabular}{@{}l@{}}#1 \\
    {\rm \qquad --- \begin{tabular}[t]{@{}l@{}}#2\end{tabular}}\end{tabular}
    \end{flushright}\par\noindent}

\newcommand{\halfpage}[1]{\parbox[t]{0.5\textwidth}{#1}}

\makeatother
\typeout{end of decls}
