\def\fileversion{2.5}
\def\filedate{94/11/11}
\def\docdate {94/11/11}
%
% \iffalse
%% File: rotating.dtx Copyright (C) 1994 Sebastian Rahtz and Leonor Barroca
% A package to provide a rotation environment, and
% rotating floats and captions
% 
%  This package is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%
%<*driver>
\documentclass{ltxdoc}
\begin{document}
 \title{A style option for rotated objects in \LaTeX\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
 \author{Sebastian Rahtz \and Leonor Barroca}
 \author{Leonor Barroca}
 \date{\filedate}
 \maketitle
 \tableofcontents
 \listoffigures
 \listoftables
 \DocInput{rotating.dtx}
\end{document}
%</driver>
% \fi
% \CheckSum{279}
% \begin{abstract}
% This article documents a \LaTeX\ package, `rotating.sty',
% which perform all the different sorts of
% rotation one might like, including complete figures.
% \end{abstract}
% \section{History}
% Sebastian Rahtz first wrote rotation macros in  1988, and has been fighting
% with them since. The original trigonometry macros came from Jim Walker (Dept
% Mathematics,  University of South Carolina); we later borrowed
% the trigonometry macros in psfig 1.8.
% This set of macros is a complete overhaul of the practice
% of rotated \LaTeX\ boxes destined for a PostScript driver.
%
% We finally decided to clean
% these macros up and document them to bare-bones `doc' standard in
% order to avoid doing some real work in January 1992. We must thank
% Frank Mittelbach and Rainer Sch\"opf for promoting this style of literate
% macro writing, and inspiring the rest of us to patch up our sorry
% efforts. We apologize for the fact that we have not attempted to make
% these macros compatible with `plain'. Life is just too short.
%
% A modification was supplied 9/2/92 by A. Mason to handle the \TeX
% tures driver, chosen with the |\rotdriver{TEXTURES}| option.
% The `sidewaysfigure' environment was fixed on 17/3/92 after
% suggestions by Rainer Sch\"opf.
%
% Version 1.7 (5.93) contains modifications (by David Carlisle, {\tt
% carlisle@cs.man.ac.uk}) to avoid extra
% spaces being generated in the output. Previous versions generated
% spaces at the begining of the box if a |%| was not used after the
% |\begin{rotate}|, also a space would be produced if a \TeX\
% counter was used instead of an explicit number for the rotation
% argument. Similarly white space is now removed at the end of the box.
% Also the |\rotatedirection{|\emph{direction}|}|
% command has been added. If the argument is anything other than {\tt
% clockwise} (the default) then the {\tt rotate} and {\tt turn}
% arguments will rotate anti-clockwise if given a positive argument.
%
% Version 1.8 replaces the fixed names for Figure and Table with the
% \LaTeX standard\ |\figurename| and |\tablename|; 
% thanks to Johannes Braams for pointing out the need for this change. 
% We also belatedly record in the source the fact that the trigonometry 
% macros were written by Phil Taylor!
%
% Version 1.9 changed the sideways figure commands according to suggestions
% from Donald Arseneau to not use their own numbering etc arrangement, but just
% follow the normal figures and tables.
%
% Version 2.0 is a complete re-write, with most of the work now
% being done by the \LaTeXe\ graphics package.
%
% Version 2.1 provides a `clockwise' option to reinstate the behaviour
% described in the `\LaTeX\ Companion'
%
% Version 2.2 just intercepts the standard float macros instead
% of copying and changing the. The `twoside' option is obeyed.
% \section{Usage} 
% This style option provides three \LaTeX\ environments:
%   \begin{description}
% \item[sideways] prints the contents turned through 90 degrees
%      counterclockwise
% \item[turn] prints the contents turned through an arbitrary angle
% \item[rotate] prints the contents turned through an arbitrary angle
%      but does \emph{not} leave any space for the result
% \end{description}
% A full set of examples are given in the file |examples.tex|
% Now we present the documented code.
% \section{Setup}
% \StopEventually{}
%    \begin{macrocode}
%<*package>
\ProvidesPackage{rotating}[\filedate\space\fileversion\space Rotation package]
\NeedsTeXFormat{LaTeX2e}
\DeclareOption{clockwise}{% this is for compatibility
 \AtBeginDocument{\setkeys{Grot}{units=360}}%
}
\DeclareOption{counterclockwise}{%
 \AtBeginDocument{\setkeys{Grot}{units=-360}}%
}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphics}}
\PassOptionsToPackage{dvips}{graphics}
\ExecuteOptions{clockwise}
\ProcessOptions
\RequirePackage{graphicx}
\RequirePackage{ifthen}
\def\rotdriver#1{\makeatletter\input{#1.def}\makeatother}
\newcount\r@tfl@t
\r@tfl@t0
%    \end{macrocode}
% \section{Turning and rotation environments}
% \begin{macro}{sideways}
% Environment to turn the contents through 90 degrees.
%    \begin{macrocode}
\def\sideways{%
  \Grot@setangle{90}%
  \setbox\z@\hbox\bgroup\ignorespaces}
\def\endsideways{%
  \unskip\egroup
  \Grot@x\z@
  \Grot@y\z@
  \Grot@box
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{turn}
% Rotate the contents of the environment, leaving the appropriate space
%    \begin{macrocode}
\def\turn#1{%
  \Grot@setangle{#1}%
  \setbox\z@\hbox\bgroup\ignorespaces}
\def\endturn{%
  \unskip\egroup
  \Grot@x\z@
  \Grot@y\z@
  \Grot@box
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{rotate}
% Rotate the contents of the environment, leaving \emph{no space}.
%    \begin{macrocode}
\def\rotate#1{%
  \Grot@setangle{#1}%
  \setbox\z@\hbox\bgroup\ignorespaces}
\def\endrotate{%
  \unskip\egroup
  \Grot@x\z@
  \Grot@y\z@
  \wd0\z@\dp0\z@\ht0\z@
  \Grot@box
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\turnbox}
% A macro version of the `rotate' environment. 
%    \begin{macrocode}
\def\turnbox#1#2{%
  \Grot@setangle{#1}%
  \setbox\z@\hbox{{#2}}%
  \Grot@x\z@\Grot@y\z@
  \wd0\z@\dp0\z@\ht0\z@
  \Grot@box
}
%    \end{macrocode}
% \end{macro}
% \section{Sideways figures and tables}
% Now for the macros to provide a complete
% environment for sideways figures and tables.
% We define two environments |sidewaysfigure| and 
% |sidewaystable| that
% fit in with the normal table and figure floats. These are `fixed'
% environments that  just do 90 degree rotation, but it would be easy
% to parameterize this to do other rotations if needed (the mind
% boggles\ldots)
% 
% First a
% generalised `rotfloat' environment. We need to intercept
% \LaTeX's float macros, in order to change the assumed width of a
% float being |\columnwidth|. We want it to work on a width of
% |\textheight| so that when we rotate the float, it comes out
% the right height. This is not actually very satisfactory, since what
% we \emph{really} want is for rotated floats to occupy the space they
% actually \emph{use}. The captions are a problem --- since they can
% precede the figure or table, we cannot set them in a box of the
% right width (ie the \emph{height} of the forthcoming object), because
% it has not happened yet. The result of these difficulties is that
% rotated figures  always end up as full page figures.
%    \begin{macrocode}
\def\@rotfloat#1{\@ifnextchar[{\@xrotfloat{#1}}{%
\edef\@tempa{\noexpand\@xrotfloat{#1}[\csname fps@#1\endcsname]}\@tempa}}
\def\@xrotfloat#1[#2]{
  \@xfloat#1[#2]%
%    \end{macrocode}
% The only part changed is the setting of |\hsize| within the
% |\vbox| to be |\textheight| instead of |\columnwidth|. 
%    \begin{macrocode}
  \hsize\textheight \@parboxrestore
 }
%    \end{macrocode}
% We call |\end@float| macro having previously rotated
% the box |\@currbox|
% The rotation is either clockwise or
% anti-clockwise, depending on whether the page is odd or even;
% in oneside mode it is always odd.
%    \begin{macrocode}
\def\end@rotfloat{%
%    \end{macrocode}
% If we are going to know whether pages are odd or even, 
% we need to use the |\pageref| mechanism, and labels. But
% Labels won't work \emph{unless} the user has put in a
% caption. Beware!
%    \begin{macrocode}
   \global\advance\r@tfl@t by 1
   \label{RF\the\r@tfl@t}%
   \color@endgroup
   \outer@nobreak
   \egroup
   \message{Adding sideways figure on }%
   \global\setbox\@tempboxa\box\@currbox
   \def\R@@page{\pageref{RF\the\r@tfl@t}}%
   \global\setbox\@currbox\vbox to \wd\@tempboxa{%
   \if@twoside\else\def\R@@page{1}\fi
   \ifthenelse{\isodd{\R@@page}}{%
    \message{ right hand page}%
    \centerline{%
       \hbox to \ht\@tempboxa{\turnbox{-90}{\box\@tempboxa}\hfill}%
               }\vfill
         }{%
    \message{ left hand page}%
    \vfill\centerline{%
       \hbox to \ht\@tempboxa{\hfill\turnbox{90}{\box\@tempboxa}}%
                }%
       }%
   }%
%    \end{macrocode}
% We stole the |\egroup| etc that |\@end@float| will want, so put in
% a dummy group to keep it quiet.
%    \begin{macrocode}
   \global\setbox\@tempboxa\vbox\bgroup
   \color@begingroup
   \hsize\columnwidth \@parboxrestore
   \if@nobreak
     \def\outer@nobreak{\global\@nobreaktrue}\global\@nobreakfalse
   \fi
   \end@float
}
%    \end{macrocode}
% The following definitions set up two environments, 
% \texttt{sidewaystable} and \texttt{sidewaysfigure}, which uses this
% type of float. Naturally, users may need to change these to suit
% their local style. Both contribute to the normal lists of figures
% and tables.
%    \begin{macrocode}
\def\sidewaysfigure{\let\make@caption\make@rcaption
\@rotfloat{figure}}
%
\let\endsidewaysfigure\end@rotfloat
%
\def\sidewaystable{\let\make@caption\make@rcaption
\@rotfloat{table}}
\let\endsidewaystable\end@rotfloat
%    \end{macrocode}
%We need to copy a standard
%|\@makecaption| to set the caption on a width of the \emph{height}
%of the float (ie the text height). This macro is normally defined in
%\LaTeX\ style files, so style file writers who change that will also
%need to redefine |\r@caption|.
%    \begin{macrocode}
\long\def\@makercaption#1#2{%
   \vskip 10\p@
   \setbox\@tempboxa\hbox{#1: #2}%
   \ifdim \wd\@tempboxa >\vsize
       #1: #2\par
     \else
       \hbox to\vsize{\hfil\box\@tempboxa\hfil}%
   \fi}%
%    \end{macrocode}
%\subsection{Rotated captions only}
% Sometimes you may find that the rotation of complete figures does
% not give quite the right result, since they always take up the whole
% page. You may prefer to rotate the caption and the float contents
% separately within a conventional figure. Here we offer a suggestion
% for a |\rotcaption| command, which inserts the caption rotated
% by 90 degrees. It is essentially a copy of the normal captioning
% code.
% Styles which define the |\@makecaption| command may also need
% to define |\@makerotcaption|.
%    \begin{macrocode}
\def\rotcaption{\refstepcounter\@captype\@dblarg{\@rotcaption\@captype}}
\long\def\@rotcaption#1[#2]#3{%
\addcontentsline{\csname ext@#1\endcsname}{#1}{%
 \protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  \par
  \begingroup
    \@parboxrestore
    \normalsize
    \@makerotcaption{\csname fnum@#1\endcsname}{#3}%
  \endgroup}
\long\def\@makerotcaption#1#2{%
 \setbox\@tempboxa\hbox{#1: #2}%
 \ifdim \wd\@tempboxa > .8\vsize
    \rotatebox{90}{%
    \begin{minipage}{.8\textheight}#1 #2\end{minipage}%
    }\par
 \else%
    \rotatebox{90}{\box\@tempboxa}%
 \fi
 \hspace{12pt}%
}
%    \end{macrocode}
%</package>
% \Finale
\endinput
%

