rokicki@polya.Stanford.EDU (Tomas G. Rokicki) (10/06/89)
I've been asked about rotating boxes (ie, landscape tables on a portrait
page) when using TeX and a PostScript driver. Here's my solution for
dvips; it should be trivial to modify for other drivers. The only thing
that should need changing is the \escspec{} macro.
===rotate.tex===
%
% These macros allow you to rotate or flip a \TeX\ box. Very useful for
% sideways tables or upsidedown answers.
%
% To use, create a box containing the information you want to rotate.
% (An hbox or vbox will do.) Now call \rotr\boxnum to rotate the
% material and create a new box with the appropriate (flipped) dimensions.
% \rotr rotates right, \rotl rotates left, \rotu turns upside down, and
% \rotf flips. These boxes may contain other rotated boxes.
%
\newbox\rotbox\newdimen\rotdimen
\def\escspec#1{\special{"@endspecial #1 @beginspecial @setspecial}}%
\def\rotfinish{\escspec{currentpoint grestore moveto}}%
%
% First, the rotation right.
%
\def\rotr#1{\rotdimen=\ht#1\advance\rotdimen by\dp#1%
\hbox to\rotdimen{\hskip\ht#1\vbox to\wd#1{\escspec{gsave
currentpoint currentpoint translate 90 rotate neg exch neg exch
translate}\box#1\vss}\hss}\rotfinish}
%
% Next, the rotation left.
%
\def\rotl#1{\rotdimen=\ht#1\advance\rotdimen by\dp#1%
\hbox to\rotdimen{\vbox to\wd#1{\vskip\wd#1\escspec{gsave
currentpoint currentpoint translate 270 rotate neg exch neg exch
translate}\box#1\vss}\hss}\rotfinish}%
%
% Upside down is simple.
%
\def\rotu#1{\rotdimen=\ht#1\advance\rotdimen by\dp#1%
\hbox to\wd#1{\hskip\wd#1\vbox to\rotdimen{\vskip\rotdimen
\escspec{gsave currentpoint currentpoint translate 180 rotate neg exch
neg exch translate}\box#1\vss}\hss}\rotfinish}%
%
% And flipped end for end is pretty easy too.
%
\def\rotf#1{\hbox to\wd#1{\hskip\wd#1\vbox{\escspec{gsave currentpoint
currentpoint translate -1 1 scale neg exch neg exch translate}\box#1}%
\hss}\rotfinish}%
===rotate.tex===
===rotsamp.tex===
\input rotate
\newbox\rottwo
%
\font\big=cmr17 scaled\magstep4
This is a \setbox\rotbox=\hbox{simple}\rotl\rotbox\ test of
\setbox\rotbox=\hbox{some}\rotu\rotbox\ rotation primitives that
\setbox\rotbox=\hbox{\big work}\rotr\rotbox.
Or maybe \setbox\rotbox=\hbox{\vrule height .2in width .2in}\rotl\rotbox\
not.
\bigskip
\centerline{\vbox{\offinterlineskip
\def\tablerule{\noalign{\hrule}}
\def\allfive#1{&\global\setbox\rottwo=\hbox{\strut#1}\copy\rottwo&&%
\setbox\rotbox=\copy\rottwo\rotl\rotbox&&%
\setbox\rotbox=\copy\rottwo\rotu\rotbox&&%
\setbox\rotbox=\copy\rottwo\rotr\rotbox&&%
\rotf\rottwo&\cr\tablerule}
\halign{\vrule#&\hfil\ #\ \hfil&\vrule#&\hfil\ #\ \hfil&\vrule#&%
\hfil\ #\ \hfil&\vrule#&\hfil\ #\ \hfil&\vrule#&\hfil\ #\ \hfil&\vrule#\cr
\tablerule
&\strut Upside&&Leftside&&Rightside&&Downside&&Flipside&\cr\tablerule
\allfive{\strut gnus}
\allfive{$-b-\sqrt{b^2-4ac}\over2a$}
\allfive{{\big A}}}}}%
\bye
===rotsamp.tex===