 % environments to print text sideways
 \newsavebox{\swbox}\newlength{\spht}\newlength{\spwd}
 %
 \newenvironment{rotate}[1]{\def\rotangle{#1}\savebox{\swbox}\bgroup}{\egroup%
 \global\spwd=\dp\swbox\global\advance\spwd by \ht\swbox\global\spht=\wd\swbox%
 \special{pstext="gsave \rotangle\space newram"}%
 \dp\swbox=0pt\wd\swbox=0pt\ht\swbox=0pt%
 \usebox{\swbox}\special{pstext="grestore"}}
 %
 \newenvironment{sideways}{\begin{rotate}{-90}}{\end{rotate}%
 \rule{0pt}{\spht}\rule{\spwd}{0pt}%
 }
 %----------------------------------------------------------
 % macros to calculate sines from 90 to -90
 % Jim Walker,  Dept Mathematics,  University of South Carolina
 \newdimen\x
 \newdimen\y
 \newdimen\xsquare
 \newdimen\xfourth
 {%
     \catcode`\p=12
     \catcode`\t=12
     \gdef\numonly#1pt{%
         \def\xx{#1}%
     }%
 }%
 \def\MULTyBYx{%
     \expandafter\numonly\the\x
     \edef\b{\y=\xx\y}%
     \b
 }%
 \def\calcsin{% Find sin(\x) and put it in \y. Say \x is in degrees.
     \x=0.0174533\x % Convert to radians.
     \y=\x
     \MULTyBYx
     \xsquare=\y
     \MULTyBYx
     \MULTyBYx
     \xfourth=\y
     \y=1pt
     \advance\y by -0.1666666\xsquare
     \advance\y by 0.008333333\xfourth
     \MULTyBYx
 }%
 % Example of use:
 %\x=23pt \calcsin \expandafter\numonly\the\y
 % Now \xx should contain the sine of 23 degrees.
 %----------------------------------------------------------
 % given a box with width W and height H,  then its height after rotation by R
 % is W * sin(R) + H * cos(R),  and it extends W * cos(R) to the right
 % and H * sin(R) to the left
 % (arithmetic courtesy of Nico Poppelier)
 %
 \newdimen\xh\newdimen\xw\newdimen\xtemp\newdimen\xcos\newdimen\xsin
 \newdimen\xleft\newdimen\xright
 \def\MULTxtempBYxcos{\expandafter\numonly\the\xcos\edef\b{\xtemp=\xx\xtemp}\b}%
 \def\MULTxtempBYxsin{\expandafter\numonly\the\xsin\edef\b{\xtemp=\xx\xtemp}\b}%
 %--------------------------------------------------
 \newenvironment{turn}[1]{\def\rotangle{#1}\savebox{\swbox}\bgroup}%
 {\egroup%
 \global\spht=\dp\swbox\global\advance\spht by \ht\swbox\global\spwd=\wd\swbox%
 \xtemp=\rotangle pt % convert rotation to dimension
 \multiply\xtemp by -1
 \x=\xtemp\calcsin\xsin=\y
 \multiply\xtemp by -1\advance\xtemp by 90pt\x=\xtemp\calcsin\xcos=\y
 % \xsin =sin (R) and \xcos = cos(R)
  \xtemp=\spwd\MULTxtempBYxsin\xh=\xtemp
  \xtemp=\spht\MULTxtempBYxcos\advance\xh by \xtemp %\xh contains the height
  \xtemp=\spht\MULTxtempBYxsin\xleft=\xtemp
  \xtemp\spwd\MULTxtempBYxcos\xright=\xtemp % \xleft and \right are offsets
 \rule{\xleft}{0pt}%
 \special{pstext="gsave \rotangle\space newram"}%
 \dp\swbox=0pt\wd\swbox=0pt\ht\swbox=0pt%
 \rlap{\usebox{\swbox}}%
 \special{pstext="grestore"}%
 \rlap{\rule{0pt}{\xh}}\rule{\xright}{0pt}%
 }
