% This is latexpicobjs.tex, Version 1.1  9/11/87

% This file makes the LaTeX line, vector, circle, and oval constructions 
% available to PiCTeX users who are running under plain TeX.
% It is distributed with Leslie Lamport's permission.

% Do not \input the files prepictex.tex and postpictex.tex along with
% this file.

\catcode`@=11 \catcode`!=11

% Save the meaning of plain TeX's \line command
\let\!texline=\line

% load LaTeX line and circle fonts
\font\tenln=line10
\font\tenlnw=linew10
\font\tencirc=lcircle10
\font\tencircw=lcirclew10

% set up LaTeX hacks
\let\@tfor=\!tfor
\let\@ifnextchar=\!ifnextchar

\def\@whilenoop#1{}
\def\@whiledim#1\do #2{\ifdim #1\relax#2\@iwhiledim{#1\relax#2}\fi}
\def\@iwhiledim#1{\ifdim #1\let\@nextwhile=\@iwhiledim 
        \else\let\@nextwhile=\@whilenoop\fi\@nextwhile{#1}}

\def\@ifstar#1#2{\@ifnextchar *{\def\@tempa*{#1}\@tempa}{#2}}

\def\@height{height}
\def\@depth{depth}
\def\@width{width}


% The following are slightly modified versions of the LaTeX
% \@badlinearg and \@warning commands.
\def\!@badlinearg{%
   \errmessage{Bad LaTeX \string\line\space or \string\vector
   \space argument. See the LaTeX manual for an explanation.}}
\def\!@warning#1{\immediate\write16{LaTeX Warning: #1.}\ignorespaces}

% allocate registers
\newdimen\@tempdima
\newdimen\@tempdimb
\newcount\@tempcnta
\newcount\@tempcntb
\newbox\@tempboxa

% Until further notice (near the end) what follows are 
% (slightly modified versions of) LaTeX's line/vector/circle/oval macros.
% See the latex.tex macro package for commentary.
\newdimen\@wholewidth
\newdimen\@halfwidth
\newdimen\unitlength \unitlength =1pt

\def\thinlines{%
  \let\@linefnt\tenln \let\@circlefnt\tencirc
  \@wholewidth\fontdimen8\tenln \@halfwidth .5\@wholewidth}
\def\thicklines{%
  \let\@linefnt\tenlnw \let\@circlefnt\tencircw
  \@wholewidth\fontdimen8\tenlnw \@halfwidth .5\@wholewidth}

\newif\if@negarg

\def\line(#1,#2)#3{%
  \@xarg #1\relax 
  \@yarg #2\relax
  \@linelen=#3\unitlength
  \ifnum\@xarg =0 
    \@vline 
  \else 
    \ifnum\@yarg =0 
      \@hline 
    \else 
      \@sline
    \fi
  \fi}

\def\@sline{%
  \ifnum\@xarg< 0 
    \@negargtrue 
    \@xarg -\@xarg 
    \@yyarg -\@yarg
  \else 
    \@negargfalse 
    \@yyarg \@yarg 
  \fi
  \ifnum \@yyarg >0 
    \@tempcnta\@yyarg 
  \else 
    \@tempcnta -\@yyarg 
  \fi
  \ifnum\@tempcnta>6 
    \!@badlinearg
    \@tempcnta0 
  \fi
  \ifnum\@xarg>6 
    \!@badlinearg
    \@xarg 1 
  \fi
  \setbox\@linechar\hbox{\@linefnt\@getlinechar(\@xarg,\@yyarg)}%
  \ifnum \@yarg >0 
    \let\@upordown\raise 
    \@clnht\z@
  \else
    \let\@upordown\lower 
    \@clnht \ht\@linechar
  \fi
  \@clnwd=\wd\@linechar
  \if@negarg 
    \hskip -\wd\@linechar 
    \def\@tempa{\hskip -2\wd\@linechar}%
  \else
    \let\@tempa\relax 
  \fi
  \@whiledim \@clnwd <\@linelen \do
    {\@upordown\@clnht\copy\@linechar
    \@tempa
    \advance\@clnht \ht\@linechar
    \advance\@clnwd \wd\@linechar}%
  \advance\@clnht -\ht\@linechar
  \advance\@clnwd -\wd\@linechar
  \@tempdima\@linelen
  \advance\@tempdima -\@clnwd
  \@tempdimb\@tempdima
  \advance\@tempdimb -\wd\@linechar
  \if@negarg 
    \hskip -\@tempdimb 
  \else 
    \hskip \@tempdimb 
  \fi
  \multiply\@tempdima \@m
  \@tempcnta \@tempdima 
  \@tempdima \wd\@linechar 
  \divide\@tempcnta \@tempdima
  \@tempdima \ht\@linechar 
  \multiply\@tempdima \@tempcnta
  \divide\@tempdima \@m
  \advance\@clnht \@tempdima
  \ifdim \@linelen <\wd\@linechar
    \hskip \wd\@linechar
  \else
    \@upordown\@clnht\copy\@linechar
  \fi}

\def\@hline{%
  \ifnum \@xarg <0 \hskip -\@linelen \fi
  \vrule \@height \@halfwidth \@depth \@halfwidth \@width \@linelen
  \ifnum \@xarg <0 \hskip -\@linelen \fi}

\def\@getlinechar(#1,#2){%
  \@tempcnta#1\relax
  \multiply\@tempcnta 8
  \advance\@tempcnta -9 
  \ifnum #2>0 
    \advance\@tempcnta #2\relax
  \else
    \advance\@tempcnta -#2\relax
    \advance\@tempcnta 64 
  \fi
  \char\@tempcnta}

\def\vector(#1,#2)#3{%
  \@xarg #1\relax 
  \@yarg #2\relax
  \@tempcnta \ifnum\@xarg<0 -\@xarg\else\@xarg\fi
  \ifnum\@tempcnta<5\relax
    \@linelen=#3\unitlength
    \ifnum\@xarg =0 
      \@vvector 
    \else 
      \ifnum\@yarg =0 
        \@hvector 
      \else 
        \@svector
      \fi
    \fi
  \else
    \!@badlinearg
  \fi}

\def\@hvector{%
  \@hline
  \hbox to 0pt{%
    \@linefnt 
    \ifnum \@xarg <0 
      \@getlarrow(1,0)\hss
    \else
      \hss\@getrarrow(1,0)%
    \fi}}

\def\@vvector{\ifnum \@yarg <0 \@downvector \else \@upvector \fi}

\def\@svector{%
  \@sline
  \@tempcnta\@yarg 
  \ifnum\@tempcnta <0 
    \@tempcnta=-\@tempcnta
  \fi
  \ifnum\@tempcnta <5
    \hskip -\wd\@linechar
    \@upordown\@clnht \hbox{%
      \@linefnt  
      \if@negarg 
        \@getlarrow(\@xarg,\@yyarg) 
      \else 
        \@getrarrow(\@xarg,\@yyarg) 
      \fi}%
  \else
    \!@badlinearg
  \fi}

\def\@getlarrow(#1,#2){%
  \ifnum #2 =\z@ 
    \@tempcnta='33
  \else
    \@tempcnta=#1\relax
    \multiply\@tempcnta \sixt@@n 
    \advance\@tempcnta -9 
    \@tempcntb=#2\relax
    \multiply\@tempcntb \tw@
    \ifnum \@tempcntb >0 
      \advance\@tempcnta \@tempcntb\relax
    \else\advance\@tempcnta -\@tempcntb
      \advance\@tempcnta 64
    \fi
  \fi
  \char\@tempcnta}

\def\@getrarrow(#1,#2){%
  \@tempcntb=#2\relax
  \ifnum\@tempcntb < 0 
    \@tempcntb=-\@tempcntb\relax
  \fi
  \ifcase \@tempcntb\relax 
    \@tempcnta='55 
  \or 
    \ifnum #1<3 
      \@tempcnta=#1\relax
      \multiply\@tempcnta 24 
      \advance\@tempcnta -6 
    \else 
      \ifnum #1=3 
        \@tempcnta=49
      \else
        \@tempcnta=58 
      \fi
    \fi
  \or 
    \ifnum #1<3 
      \@tempcnta=#1\relax
      \multiply\@tempcnta 24 
      \advance\@tempcnta -3 
    \else 
      \@tempcnta=51
    \fi
  \or 
    \@tempcnta=#1\relax
    \multiply\@tempcnta \sixt@@n 
    \advance\@tempcnta -\tw@ 
  \else
    \@tempcnta=#1\relax
    \multiply\@tempcnta \sixt@@n 
    \advance\@tempcnta 7 
  \fi
  \ifnum #2<0 
    \advance\@tempcnta 64 
  \fi
  \char\@tempcnta}

\def\@vline{%
  \ifnum \@yarg <0 
    \@downline 
  \else 
    \@upline
  \fi}

\def\@upline{%
  \hbox to \z@{%
    \hskip -\@halfwidth 
    \vrule \@width \@wholewidth \@height \@linelen \@depth \z@\hss}}

\def\@downline{%
  \hbox to \z@{%
    \hskip -\@halfwidth 
    \vrule \@width \@wholewidth \@height \z@ \@depth \@linelen \hss}}

\def\@upvector{%
  \@upline
  \setbox\@tempboxa\hbox{%
    \@linefnt\char'66}%
    \raise \@linelen \hbox to\z@{\lower \ht\@tempboxa\box\@tempboxa\hss}}

\def\@downvector{%
  \@downline
  \lower \@linelen \hbox to \z@{\@linefnt\char'77\hss}}


\newif\if@ovt 
\newif\if@ovb 
\newif\if@ovl 
\newif\if@ovr 
\newdimen\@ovxx
\newdimen\@ovyy
\newdimen\@ovdx
\newdimen\@ovdy
\newdimen\@ovro
\newdimen\@ovri

\def\@getcirc#1{%
  \@tempdima #1\relax 
  \@tempcnta\@tempdima
  \@tempdima 4pt\relax 
  \divide\@tempcnta\@tempdima
  \ifnum \@tempcnta > 10\relax 
    \@tempcnta 10\relax
  \fi
  \ifnum \@tempcnta >\z@ 
    \advance\@tempcnta \m@ne
  \else 
    \!@warning{Oval too small}%
  \fi
  \multiply\@tempcnta 4\relax
  \setbox \@tempboxa \hbox{\@circlefnt \char \@tempcnta}%
  \@tempdima \wd \@tempboxa}

\def\@put#1#2#3{%
  \raise #2\hbox to \z@{\hskip #1#3\hss}}

\def\oval(#1,#2){%
  \@ifnextchar[{\@oval(#1,#2)}{\@oval(#1,#2)[]}}

\def\@oval(#1,#2)[#3]{%
  \begingroup
    \boxmaxdepth \maxdimen
    \@ovttrue \@ovbtrue \@ovltrue \@ovrtrue
    \@tfor\@tempa :=#3\do{%
      \csname @ov\@tempa false\endcsname}%
    \@ovxx #1\unitlength 
    \@ovyy #2\unitlength
    \@tempdimb \ifdim \@ovyy >\@ovxx \@ovxx\else \@ovyy \fi
    \@getcirc \@tempdimb
    \@ovro \ht\@tempboxa 
    \@ovri \dp\@tempboxa
    \@ovdx\@ovxx 
    \advance\@ovdx -\@tempdima 
    \divide\@ovdx \tw@
    \@ovdy\@ovyy 
    \advance\@ovdy -\@tempdima 
    \divide\@ovdy \tw@
    \@circlefnt 
    \setbox\@tempboxa \hbox{%
      \if@ovr 
        \@ovvert32\kern -\@tempdima 
      \fi
      \if@ovl 
        \kern \@ovxx 
        \@ovvert01\kern -\@tempdima 
        \kern -\@ovxx 
      \fi
      \if@ovt 
        \@ovhorz \kern -\@ovxx 
      \fi
      \if@ovb 
        \raise \@ovyy \@ovhorz 
      \fi}%
    \advance\@ovdx\@ovro
    \advance\@ovdy\@ovro 
    \ht\@tempboxa\z@ 
    \dp\@tempboxa\z@
    \@put{-\@ovdx}{-\@ovdy}{\box\@tempboxa}%
  \endgroup}

\def\@ovvert#1#2{%
  \vbox to \@ovyy{%
    \if@ovb 
      \@tempcntb \@tempcnta 
      \advance \@tempcntb by #1\relax
      \kern -\@ovro 
      \hbox{\char \@tempcntb}%
      \nointerlineskip
    \else 
      \kern \@ovri 
      \kern \@ovdy 
    \fi
    \leaders\vrule width \@wholewidth\vfil 
    \nointerlineskip
    \if@ovt 
      \@tempcntb \@tempcnta 
      \advance \@tempcntb by #2\relax
      \hbox{\char \@tempcntb}%
    \else 
      \kern \@ovdy 
      \kern \@ovro 
    \fi}}

\def\@ovhorz{%
  \hbox to \@ovxx{%
    \kern \@ovro
    \if@ovr 
    \else 
      \kern \@ovdx 
    \fi
    \leaders \hrule height \@wholewidth \hfil
    \if@ovl 
    \else 
      \kern \@ovdx 
    \fi
    \kern \@ovri}}

\def\circle{%
  \@ifstar{\@dot}{\@circle}}
\def\@circle#1{%
  \begingroup 
    \boxmaxdepth \maxdimen 
    \@tempdimb #1\unitlength
    \ifdim \@tempdimb >15.5pt\relax 
      \@getcirc\@tempdimb
      \@ovro\ht\@tempboxa 
      \setbox\@tempboxa\hbox{%
        \@circlefnt
        \advance\@tempcnta\tw@ 
        \char \@tempcnta
        \advance\@tempcnta\m@ne 
        \char \@tempcnta 
        \kern -2\@tempdima
        \advance\@tempcnta\tw@
        \raise \@tempdima \hbox{\char\@tempcnta}%
        \raise \@tempdima \box\@tempboxa}%
      \ht\@tempboxa\z@ 
      \dp\@tempboxa\z@
      \@put{-\@ovro}{-\@ovro}{\box\@tempboxa}%
    \else  
      \@circ\@tempdimb{96}%
    \fi
  \endgroup}

\def\@dot#1{%
  \@tempdimb #1\unitlength 
  \@circ\@tempdimb{112}}

\def\@circ#1#2{%
  \@tempdima #1\relax 
  \advance\@tempdima .5pt\relax
  \@tempcnta\@tempdima 
  \@tempdima 1pt\relax
  \divide\@tempcnta\@tempdima 
  \ifnum\@tempcnta > 15\relax 
  \@tempcnta 15\relax \fi    
  \ifnum 
    \@tempcnta >\z@ 
    \advance\@tempcnta\m@ne
  \fi
  \advance\@tempcnta #2\relax
  \@circlefnt 
  \char\@tempcnta}

\thinlines   

\newcount\@xarg
\newcount\@yarg
\newcount\@yyarg
\newcount\@multicnt 
\newdimen\@xdim
\newdimen\@ydim
\newbox\@linechar
\newdimen\@linelen
\newdimen\@clnwd
\newdimen\@clnht

% That's the end of the definitions of lines/vectors/circles/ovals.


% Save LaTeX's meaning of \line
\let\!latexline=\line

% Set variable meaning of line
\def\line{\!ifnextchar(\!latexline\!texline}

\catcode`@=12 \catcode`!=12
