\def\~parskip{0pt plus 1pt}
\parskip\~parskip
\def\~beginsmall{\ninepoint\def\~parskip{0pt plus 1pt}\parskip\~parskip
      \ignorespaces}

\~definecounter{interlude}
\def\~co~interlude{\ifnum \~c~interlude >0 \~arabic{\~c~interlude}\else P\fi}
\def\~ca~interlude{{\~c~interlude}}
\def\~cr~interlude#1{\ifnum #1>0 \~arabic{#1}\else P\fi}

\def\interludesw{T} %Begins with an interlude.

\def\minvskip#1{\ifdim #1>\the\lastskip\vskip\minusthe\lastskip\vskip #1\fi}

\def\exercises{\par\vspace{25pt}\noindent {\bf Exercises}\par\nopagebreak
\vspace{15pt}}

\def\~beginexercise{\par\minvskip{1.5ex}\noindent 
\if\interludesw F\~refstepcounter{exercise}{\bf Exercise \~co~exercise:}\else
\~refstepcounter{iexercise}{\bf Exercise \~co~iexercise:}\fi}

\def\~endexercise{\par\vskip 1.5ex}

\~definecounter{exercise}
\~addtoreset{exercise}{chapter}
\def\~co~exercise{\~co~chapter.\~arabic{\~c~exercise}}
\def\~ca~exercise{{\~c~chapter}{\~c~exercise}}
\def\~cr~exercise#1#2{\~cr~chapter{#1}.\~arabic{#2}}

\~definecounter{iexercise}
\~addtoreset{iexercise}{interlude}
\def\~co~iexercise{\~co~interlude.\~arabic{\~c~iexercise}}
\def\~ca~iexercise{{\~c~interlude}{\~c~iexercise}}
\def\~cr~iexercise#1#2{\~cr~interlude{#1}.\~arabic{#2}}


\def\~beginsolution{\par \minvskip{1.5ex}\noindent\ninepoint
   {\bf Solution to Exercise 
     \if\interludesw F\~co~exercise\else\~co~iexercise\fi:}}
\def\~endsolution{\par\vskip 1.5ex}

\def\~beginquote{\~beginlist{}{\rightmargin{\~d~leftmargin}\topsep
  {1.2ex}}\ninepoint
\dispskip 2pt plus 1pt minus 1pt%
\dispaskip 0pt plus 1pt%
\dispbskip 2pt plus 1pt minus 1pt%
\item}
\def\~endquote{\~endlist\vspace{1.2ex}}

\def\qindent{\hspacer{.6em}}
\def\pindent{\hspacer{1em}}

\def\~beginprogram#1{\if\interludesw F\~begininsert{program}{Program}{#1}{lop}%
\else\~begininsert{iprogram}{Program}{#1}{lop}\fi}

\let\~endprogram=\~endfigure


\~definecounter{program}
\~addtoreset{program}{chapter}
\def\~co~program{\~co~chapter.\~arabic{\~c~program}}
\def\~ca~program{{\~c~chapter}{\~c~program}}
\def\~cr~program#1#2{\~cr~chapter{#1}.\~arabic{#2}}

\~definecounter{iprogram}
\~addtoreset{iprogram}{interlude}
\def\~co~iprogram{\~co~interlude.\~arabic{\~c~iprogram}}
\def\~ca~iprogram{{\~c~interlude}{\~c~iprogram}}
\def\~cr~iprogram#1#2{\~cr~interlude{#1}.\~arabic{#2}}


\def\~t~lop{F} % don'T produce .LOP file if no \listofprograms

% The \chapter macro must write a \def\interludesw{F} and the \interlude macro 
% must write \def\interludesw{T} on the .lop file.
% They should also write \def\skipsw{T} on the .lop file.

\def\~tr~lop#1#2#3#4{\if\skipsw T % skip 10 pt between programs
     \vskip 10pt\fi\def%                     % for different chapters
\skipsw{F}\hbox to \columnwidth
      {\hbox to 2.3em{\if\interludesw T \~cr~iprogram{#1}{#2}\else
        \~cr~program{#1}{#2}\fi.\hss}#3\~lead\hbox 
      to 1.25em{\hfil #4}}}

\def\listofprograms{\begin{center}
{\tit PROGRAMS}
\end{center}\par\vskip 10pt\def\~x~chap{-1}\begingroup
\~input{\jobname.lop}\endgroup\par
\if\~tfilesw T\gdef\~t~lop{T}\newwrite\~tf~lop\openout\~tf~lop=\jobname.lop\fi}

\def\interludesection#1{
     \par                                     % end previous paragraph     
     \vspace{25pt}                            % extra vertical space
     \if\~nobreak F\goodpagebreak\fi          % good place for page break if
     \~secmark{#1}                            %    not following \chapter
     \noindent{\~mainsize\bf #1}              % section heading 
     \tableentry{toc}{\hbox{\hskip .25in}#1}  % add table of contents line
     \nobreak                                 % very bad place for page break
     \def\~nobreak{T}
     \parskip15pt                             % space in front of first par.
     \everypar{\parskip\~parskip              % first par will restore \parskip
         \def\~nobreak{F}\everypar{\~everypar}}}

