% All this stuff comes from latex.tex, most of it from the                      
% picture environment. No changes!!!                                            
                                                                                
\catcode`\@=11                                                                  
\def\newcount{\alloc@0\count\countdef\insc@unt}
\def\newdimen{\alloc@1\dimen\dimendef\insc@unt}
\def\newskip{\alloc@2\skip\skipdef\insc@unt}
\def\newbox{\alloc@4\box\chardef\insc@unt}
\def\newwrite{\alloc@7\write\chardef\sixt@@n}


\def\@nnil{\@nil}
\def\@empty{}
\def\@fornoop#1\@@#2#3{}

\def\@for#1:=#2\do#3{\edef\@fortmp{#2}\ifx\@fortmp\@empty \else
    \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}\fi}

\def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
       #5\def#4{#2}\ifx #4\@nnil \else#5\@iforloop #3\@@#4{#5}\fi\fi}

\def\@iforloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
       \let\@nextwhile=\@fornoop \else
      #4\relax\let\@nextwhile=\@iforloop\fi\@nextwhile#2\@@#3{#4}}


\def\@tfor#1:=#2\do#3{\xdef\@fortmp{#2}\ifx\@fortmp\@empty \else
    \@tforloop#2\@nil\@nil\@@#1{#3}\fi}
\def\@tforloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
       \let\@nextwhile=\@fornoop \else
      #4\relax\let\@nextwhile=\@tforloop\fi\@nextwhile#2\@@#3{#4}}

\def\makebox{\@ifnextchar ({\@makepicbox}{\@ifnextchar
     [{\@makebox}{\mbox}}}

\def\mbox#1{\leavevmode\hbox{#1}}

\def\@makebox[#1]{\leavevmode\@ifnextchar [{\@imakebox[#1]}{\@imakebox[#1][x]}}

\long\def\@imakebox[#1][#2]#3{\hbox to#1{\let\mb@l\hss
\let\mb@r\hss \expandafter\let\csname mb@#2\endcsname\relax
\mb@l #3\mb@r}}

\def\@makepicbox(#1,#2){\leavevmode\@ifnextchar 
   [{\@imakepicbox(#1,#2)}{\@imakepicbox(#1,#2)[]}}

\long\def\@imakepicbox(#1,#2)[#3]#4{\vbox to#2\unitlength
   {\let\mb@b\vss \let\mb@l\hss\let\mb@r\hss
    \let\mb@t\vss
    \@tfor\@tempa :=#3\do{\expandafter\let
        \csname mb@\@tempa\endcsname\relax}%
\mb@t\hbox to #1\unitlength{\mb@l #4\mb@r}\mb@b}}

\def\newsavebox#1{\@ifdefinable#1{\newbox#1}}

\def\savebox#1{\@ifnextchar ({\@savepicbox#1}{\@ifnextchar
     [{\@savebox#1}{\sbox#1}}}

\def\sbox#1#2{\setbox#1\hbox{#2}}

\def\@savebox#1[#2]{\@ifnextchar [{\@isavebox#1[#2]}{\@isavebox#1[#2][x]}}

\long\def\@isavebox#1[#2][#3]#4{\setbox#1 \hbox{\@imakebox[#2][#3]{#4}}}

\def\@savepicbox#1(#2,#3){\@ifnextchar 
   [{\@isavepicbox#1(#2,#3)}{\@isavepicbox#1(#2,#3)[]}}

\long\def\@isavepicbox#1(#2,#3)[#4]#5{\setbox#1 \hbox{\@imakepicbox
     (#2,#3)[#4]{#5}}}

\def\usebox#1{\leavevmode\copy #1\relax}

%% The following definition of \frame was written by Pavel Curtis
\long\def\frame#1{\leavevmode
    \hbox{\hskip-\@wholewidth
        \vbox{\vskip-\@wholewidth
              \hrule \@height\@wholewidth
              \hbox{\vrule \@width\@wholewidth #1\vrule \@width  \@wholewidth}
  	      \hrule \@height \@wholewidth\vskip -\@halfwidth}
  	      \hskip-\@wholewidth}}

\newdimen\fboxrule
\newdimen\fboxsep

\long\def\fbox#1{\leavevmode\setbox\@tempboxa\hbox{#1}\@tempdima\fboxrule
    \advance\@tempdima \fboxsep \advance\@tempdima \dp\@tempboxa
   \hbox{\lower \@tempdima\hbox
  {\vbox{\hrule \@height \fboxrule
          \hbox{\vrule \@width \fboxrule \hskip\fboxsep
	    \vbox{\vskip\fboxsep \box\@tempboxa\vskip\fboxsep}\hskip 
			 \fboxsep\vrule \@width \fboxrule}
		   \hrule \@height \fboxrule}}}}

\def\framebox{\@ifnextchar ({\@framepicbox}{\@ifnextchar
     [{\@framebox}{\fbox}}}

\def\@framebox[#1]{\@ifnextchar [{\@iframebox[#1]}{\@iframebox[#1][x]}}

\long\def\@iframebox[#1][#2]#3{\leavevmode
  \savebox\@tempboxa[#1][#2]{\kern\fboxsep #3\kern\fboxsep}\@tempdima\fboxrule
    \advance\@tempdima \fboxsep \advance\@tempdima \dp\@tempboxa
   \hbox{\lower \@tempdima\hbox
  {\vbox{\hrule \@height \fboxrule
          \hbox{\vrule \@width \fboxrule \hskip-\fboxrule
	    \vbox{\vskip\fboxsep \box\@tempboxa\vskip\fboxsep}\hskip 
			 -\fboxrule\vrule \@width \fboxrule}
		   \hrule \@height \fboxrule}}}}

\def\@framepicbox(#1,#2){\@ifnextchar 
   [{\@iframepicbox(#1,#2)}{\@iframepicbox(#1,#2)[]}}

\long\def\@iframepicbox(#1,#2)[#3]#4{\frame{\@imakepicbox(#1,#2)[#3]{#4}}}

\def\parbox{\@ifnextchar [{\@iparbox}{\@iparbox[c]}}

\long\def\@iparbox[#1]#2#3{\leavevmode \@pboxswfalse
   \if #1b\vbox 
     \else \if #1t\vtop 
              \else \ifmmode \vcenter 
                        \else \@pboxswtrue $\vcenter
                     \fi
           \fi
    \fi{\hsize #2\@parboxrestore #3}\if@pboxsw $\fi}
