rotate.sty - a working version enclosed 

View this article only Newsgroups: comp.text.tex Date: 1991-09-10 15:00:55 PST

Enclosed below, thanks to Peter Bloomfield, is a modified version of the rotate.sty that I posted yesterday. This one has no dependence on any prologue file, but instead uses the capabilities of various DVI to PostScript drivers to output PostScript verbatim. See the comments for more details. Also, please read the notes on the difference between the turn and the rotate environments.

-- paul
%% LaTeX Macros for PostScript rotation of text
%% Sebastian Rahtz, Dept. of Computer Science, Southampton University
%% Paul Barton-Davis, Dept. of Computer Science, University of Washington

%% 10-sep-91 pad -      added code supplied by Peter Bloomfield from
%%                      Tom Rockiki's dvips to eliminate dependence
%%                      on the prologue.
%%
%% 13-Mar-89 pad -  added "global" keyword to \special to stop
%%   dvi2ps from wrapping the rotated text
%%   up in @begin-, @start- and @endspecials.

%% \@verbps{TEXT} outputs TEXT directly to the DVI file, with no
%% surrounding context. Following are 3 definitions for 3 different
%% DVI->PostScript drivers. The key part of these is that the
%% \special's argument must NOT be enclosed in any context saving
%% mechanism. Each driver has a different method for specifying this.
%%
%% For Rockiki's dvips
%%
%\def\@verbps#1{\special{ps:#1}}
%%
%% For a modified dvi2ps that has the "global" modifier for pstext
%%
%\def\@verbps#1{\special{global pstext="#1"}}
%%
%% For Bechtolstein's dvitps
%%
\def\@verbps#1{\special{dvitps: Literal "#1"}}
%%
%% The box we put rotated text into
%%
\newsavebox{\swbox}\newlength{\spht}\newlength{\spwd}
%%
%% \begin{rotate}{DEGREES}
%% TEXT
%% \end{rotate}
%%
%% rotates TEXT by DEGREES, but puts TEXT into a box with zero size.
%%      Use this for special effects. The "turn" environment, below,
%%      is probably closer to what you want for normal rotation,
%%      because it calculates the correct box size.

\newenvironment{rotate}[1]{\def\rotangle{#1}\savebox{\swbox}\bgroup}{%
 \egroup
 \global\spwd=\dp\swbox
 \global\advance\spwd by \ht\swbox
 \global\spht=\wd\swbox%
 %% do the PostScript magic
 \@verbps{gsave currentpoint currentpoint translate
\rotangle\space rotate neg exch neg exch translate}%
 \dp\swbox=0pt\wd\swbox=0pt\ht\swbox=0pt%
 \usebox{\swbox}
 %% End the PostScript magic
 \@verbps{grestore}
}
%
% 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}%
%%
%%
%% \begin{turn}{DEGREES}
%% TEXT
%% \end{turn}
%%
%%     rotates TEXT by DEGREES, and puts into a box corresponding to
%%     the size of the rotated material. Use this to rotate text when
%%     you want the surrounding material to take account of the rotation.

\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}%
 %% do the PostScript magic
 \@verbps{gsave currentpoint currentpoint translate
\rotangle\space rotate neg exch neg exch translate}%
 \dp\swbox=0pt\wd\swbox=0pt\ht\swbox=0pt%
 \rlap{\usebox{\swbox}}%
 \@verbps{grestore}
 \rlap{\rule{0pt}{\xh}}\rule{\xright}{0pt}%
}
%%
%%  Print it sideways
%%
\newenvironment{sideways}{\begin{turn}{-90}}{\end{turn}}

Paul Barton-Davis

rotate.sty - a working version enclosed 

NB, the latest version of rotating.sty in systems/mac/textures/latex/latex2e <http://www.ctan.org/tex-archive/systems/mac/textures/latex/latex2e/> is Nov 18, 1999, which is newer than Paul's hack.