% From page 415 of the Tex manual
\newdimen\pagewidth \newdimen\pageheight \newdimen\ruleht
\newdimen\fulllinewidth
\hsize=30pc \vsize=43pc \maxdepth=2.2pt \parindent=2pc
\pagewidth=\hsize \pageheight=\vsize \ruleht=.5pt \fulllinewidth=32pc
\abovedisplayskip=6pt plus 3pt minus 1pt
\belowdisplayskip=6pt plus 3pt minus 1pt
\abovedisplayshortskip=0pt plus 3pt
\belowdisplayshortskip=4pt plus 3pt
% From page 362-3 of the Tex manual
\countdef\pageno=0 \pageno=1              % first page is number 1
\newtoks\headline \headline={\hfil}       % headline is normally blank
\newtoks\footline \footline={\hss\tenrm\folio\hss}
       % footline is normally a centered page number in font \tenrm
\def\folio{\ifnum\pageno<0 \romannumeral-\pageno \else\number\pageno \fi}
\def\nopagenumbers{\footline={\hfil}}   % blank out the footline
\def\advancepageno{\ifnum\pageno<0 \global\advance\pageno by -1
  \else\global\advance\pageno by 1 \fi}   % increase |pageno|
\newif\ifr@ggedbottom
\def\raggedbottom{\topskip10pt plus60pt \r@ggedbottomtrue}
\def\normalbottom{\topskip10pt \r@ggedbottomfalse} % undoes \raggedbottom
% Next the \footnote macro from page 416 of the Tex manual
\def\footnote#1{\edef\@sf{\spacefactor\the\spacefactor}#1\@sf
  \insert\footins\bgroup\eightpoint
  \interlinepenalty100 \let\par=\endgraf
    \leftskip=0pt \rightskip=0pt
    \splittopskip=10pt plus 1pt minus 1pt \floatingpenalty=20000
    \smallskip\item{#1}\bgroup\strut\aftergroup\@foot\let\next}
\skip\footins=12pt plus 2pt minus 4pt % space added when footnote exists
\dimen\footins=30pc                   % maximum footnotes per page
% Next the titlepage and headline stuff from page 416 of the Tex manual
\newif\iftutorial
\def\tutorial{\global\tutorialtrue}
\newif\iftutorialtitle
\newif\iftitle
\def\titlepage{\global\titletrue}   % for pages without headlines
\def\leftheadline{\hbox to \pagewidth{%
    \vbox to 10pt{} % strut to position the baseline
    \tenrm\kern-3pc\folio\hfill
    \lhead}} % running head flush left
\def\rightheadline{\hbox to \pagewidth{\vbox to 10pt{}%
    \tenrm\kern-3pc\rhead % running head flush right
    \hfill\folio}} 
\def\tutorialleftheadline{\hbox to \pagewidth{%
    \vbox to 10pt{} % strut to position the baseline
    \tenrm\kern-3pc\folio T\hfill
    \lhead}} % running head flush left
\def\tutorialrightheadline{\hbox to \pagewidth{\vbox to 10pt{}%
    \tenrm\kern-3pc\rhead % running head flush right
    \hfill\folio T}} 
% Margin stuff from page 415
\newinsert\margin
\dimen\margin=\maxdimen
\count\margin=0 \skip\margin=0pt
% Index macro from page 423
\newwrite\inx
\immediate\openout\inx=index
\def\marginstyle{\sevenrm
  \vrule height6pt depth2pt width0pt}
\newif\ifsilent
\def\specialhat{\ifmmode\def\next{^}\else\let\next=\beginxref\fi\next}
\def\beginxref{\futurelet\next\beginxrefswitch}
\def\beginxrefswitch{\ifx\next\specialhat\let\next=\silentxref
  \else\silentfalse\let\next=\xref\fi \next}
\catcode`\^=\active \let ^=\specialhat
\def\silentxref^{\silenttrue\xref}
\chardef\bslsh=`\\
\def\xref{\futurelet\next\xrefswitch}
\def\xrefswitch{\begingroup\ifx\next|\aftergroup\vxref
  \else\ifx\next\<\aftergroup\anglexref
    \else\aftergroup\normalxref \fi\fi \endgroup}
\def\vxref|{\catcode`\\=\active \futurelet\next\vxrefswitch}
\def\vxrefswitch#1|{\catcode`\\=0
  \ifx\next\empty\def\xreftype{2}%
    \def\next{{\tt\bslash\text}}% code 2, |\arg|
  \else\def\xreftype{1}\def\next{{\tt\text}}\fi % code 1, |arg|
  \edef\text{#1}\makeref
{\catcode`\|=0 \catcode`\\=\active |gdef\{}}
\def\anglexref\<#1>{\def\xreftype{3}\def\text{#1}%
  \def\next{\<\text>}\makexref} % code 3, \<arg>
\def\normalxref#1{\def\xreftype{0}\def\text{#1}\let\next=\text\makexref}
\newif\ifproofmode
\proofmodefalse
\def\makexref{\ifproofmode\insert\margin{\hbox{\marginstyle\text}}%
  \xdef\writeit{\write\inx{\text\space!\xreftype\space
    \noexpand\number\pageno.}}\writeit
  \else\ifhmode\kern0pt \fi\fi
 \ifsilent\ignorespaces\else\next\fi}
% From page 416 of Tex manual
\def\makefootline{\bigskip\line{\the\footline}}
\def\onepageout#1{\ifodd\pageno\hoffset=2pc\else\hoffset=-1pc\fi
		  \shipout\vbox{ % here we define one page of output
    \offinterlineskip % butt the boxes together
    \vbox to 2.5pc{ % this part goes on top of the 41pc pages
      \iftitle % \setcornerrules
      \else\ninepoint\ifodd\pageno
                         \iftutorial \tutorialrightheadline
                         \else       \rightheadline\fi
		     \else
                         \iftutorial \tutorialleftheadline
                         \else       \leftheadline\fi
                     \fi\tenpoint
      \fi \vfill}
    \vbox to \pageheight{
      \ifvoid\topins \else\unvbox\topins\fi
      \ifvoid\margin\else % marginal info is present
       \rlap{\kern34pc\vbox to0pt{\kern4pt\box\margin \vss}}\fi
      #1 % now insert the main information
      \ifvoid\footins\else % footnote info is present
       \vskip\skip\footins \kern-3pt
       \hrule height\ruleht width\pagewidth \kern-\ruleht \kern3pt
       \unvbox\footins\fi
      \boxmaxdepth=\maxdepth}
      \iftutorialtitle\global\tutorialtitlefalse\global\titlefalse
               \bigskip\line{\hfill\tenpoint\folio T}
      \else\iftitle \global\titlefalse
               \bigskip\line{\hfill\tenpoint\folio}
           \else\makefootline\fi
      \fi}
  \advancepageno}
\def\setcornerrules{\hbox to \pagewidth{% for camera alignment
    \vrule width 1pc height\ruleht \hfil \vrule width 1pc}
  \hbox to \pagewidth{\llap{\sevenrm(page \folio)\kern1pc}%
    \vrule height1pc width\ruleht depth0pt
    \hfil \vrule width\ruleht depth0pt}}
\output{\specialbopemit\onepageout{\unvbox255}}
