% 5 October, 1990
%
% \begin{rotbox}[c]
%  \end{rotbox}
%
%  c=l	 left rotation	default
%  c=r	 right rotation
%  c=u	 upside down
%  c=m	 mirror
%  c=i	 identity, no rotation
%
%  creates an  \hbox{\vbox{  rotated image}}
%
%  variable changes are local to environment
%
%  to use with center environment, or enter
%  paragraph mode from vertical mode, need to put in an \mbox{}
%  or use \leavevmode
%
% defaults to left rotation
%
% Also:
%   \zbox{}    : size zero box (vs. \mbox, which isn't a box)
%   \zbox[tblr]: size zero box centered somewhere else
%   \zbox[tblr ][lrumi]:  rotated zero box
% based on \makebox() macro.

\def\rotbox{\@ifnextchar [{\@rotbox} {\@rotbox[l]} }

\def\@rotbox[#1]{\bgroup
\if #1r \let\@@rotbox\@rotr
  \else \if #1u \let\@@rotbox\@rotu
    \else \if #1m \let\@@rotbox\@rotm
      \else \if #1i \let\@@rotbox\@roti
	 \else \let\@@rotbox\@rotl
      \fi%
    \fi%
  \fi%
\fi%
\setbox13=\vbox\bgroup}

\def\endrotbox{\egroup%
\@@rotbox%
\special{ps:currentpoint grestore moveto}\egroup}

\def\@rotspecial#1{\special{ps:gsave currentpoint currentpoint translate
   #1 neg exch neg exch translate}}
%
%  Right rotation
%
\def\@rotr{\dimen13=\ht13\advance\dimen13 by\dp13%
   \hbox to\dimen13{\hskip\ht13\vbox to\wd13{\@rotspecial{90 rotate}%
   \box13\vss}\hss}}
%
%   Left Rotation
%
\def\@rotl{\dimen13=\ht13\advance\dimen13 by\dp13%
   \hbox to\dimen13{\vbox to\wd13{\vskip\wd13\@rotspecial{270 rotate}%
   \box13\vss}\hss}}%
%
%   Upside down
%
\def\@rotu{\dimen13=\ht13\advance\dimen13 by\dp13%
   \hbox to\wd13{\hskip\wd13\vbox to\dimen13{\vskip\dimen13%
   \@rotspecial{-1 dup scale}\box13\vss}\hss}}%
%
%   Mirror image
%
\def\@rotm{\hbox to\wd13{\hskip\wd13\@rotspecial{-1 1 scale}%
   \box13\hss}}%
%
%   Identity
%
\def\@roti{\hbox to\wd13{\vbox{\@rotspecial{}\box13}}}%
%
%   Zerobox:  default to center, otherwise optional
%             arg for centering & optional arg for rotating
\def\zbox{\@ifnextchar [{\@zerobox}{\@@zerobox[]}}
\def\@zerobox[#1]{\@ifnextchar [{\@@rzerobox[#1]}{\@@zerobox[#1]}}
\long\def\@@zerobox[#1]#2{\hbox to 0pt
   {\let\mb@b\vss \let\mb@l\hss\let\mb@r\hss
    \let\mb@t\vss
    \@tfor\@tempa :=#1\do{\expandafter\let
        \csname mb@\@tempa\endcsname\relax}%
\mb@l\vbox to 0pt{\mb@t #2\mb@b}\mb@r}}
\long\def\@@rzerobox[#1][#2]#3{%
    \@@zerobox[#1]{\rotbox[#2]\hbox{#3}\endrotbox}}

