6 %% Copyright 1995--1999 Sebastian Rahtz and Leonor Barroca
7 %% Copyright 2001--2003,2007--2009 Robin Fairbairns
8 %% Copyright 2016 LaTeX3 Project
10 % This work may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % http://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2005/12/01 or later.
18 % This work has the LPPL maintenance status `maintained'.
21 % This work consists of the file rotating.dtx
22 % and the derived file rotating.sty, and testing material
23 % rotex.tex and cat.eps
26 \NeedsTeXFormat{LaTeX2e}
28 \ProvidesFile{rotating.dtx}%
30 %<package>\ProvidesPackage{rotating}%
32 %<package> rotated objects in LaTeX%
34 rotating package source file%
38 \documentclass{ltxdoc}
39 \GetFileInfo{rotating.dtx}
41 \title{A package for rotated objects in \LaTeX\thanks{This file has
42 version number \fileversion, last revised \filedate}}
43 \author{Robin Fairbairns
44 \and Sebastian Rahtz \and Leonor Barroca}
46 \MaintainedByLaTeXTeam{graphics}
51 \DocInput{rotating.dtx}
57 % This article documents a \LaTeX\ package, `rotating.sty',
58 % which performs most sorts of
59 % rotation one might like, including rotation of complete floating
63 % \section{Introduction}
65 % The package provides:
67 % \item two new environments, \texttt{sidewaystable} and
68 % \texttt{sidewaysfigure}, each of which produces a single page-size
69 % float with contents rotated $\pm90$\,degrees; and
70 % \item a variety of other rotation-related commands and environments.
73 % Note that the package uses rotation facilities from the
74 % \textsf{graphicx} package. When generating DVI output, users should
75 % note that rotation is typically \emph{not} visible in a DVI viewer:
76 % conversion to, and viewing, PostScript or PDF is necessary.
80 % \subsection{Package options}
82 % Sideways figures and tables always take up the whole page. In
83 % single-sided documents, they may be rotated so that the bottom of
84 % the figures is on the left (package option
85 % `\texttt{counterclockwise}') or the right (package option
86 % `\texttt{clockwise}'). The default is to turn so that the bottom is
87 % on the right (option `\texttt{clockwise}').
89 % Option `\texttt{anticlockwise}' is an alias for
90 % `\texttt{counterclockwise}'.
92 % If the `\texttt{twoside}' option has been given to the main document
93 % class (either explicitly, or implicitly as in the default for book
94 % class), the package will rotate sideways figures according to the
95 % page number (this requires at least two passes through \LaTeX{}).
96 % If you want the `\texttt{twoside}' option, but want the figures
97 % always in one direction, use the `\texttt{figuresright}' or
98 % `\texttt{figuresleft}' options to the package.
100 % The package can produce a lot of logging information; the
101 % amount of information is controlled by the package options
102 % `\texttt{quiet}' (fewest messages; default), `\texttt{log}' and
103 % `\texttt{chatter}' (most messages).
105 % All other options are passed to the \textsf{graphicx} package when
106 % it is loaded to provide rotation functions.
108 % \subsection{Float environments}
110 % The environments \texttt{sidewaystable} and \texttt{sidewaysfigure}
111 % introduce landscape-form floating tables and figures, respectively.
112 % (Each of the environments has a ``starred'' version, such as
113 % \texttt{sidewaystable*}, for a single-column float in a double-column
114 % area of the document.)
116 % New rotated environments may be declared using the combined
117 % facilities of the float and rotfloat packages.
119 % \subsection{Other environments and commands}
120 % The package provides other \LaTeX\ environments:
121 % \begin{description}
122 % \item[\mdseries\ttfamily sideways] prints the contents of the
123 % environment turned through 90 degrees counterclockwise;
124 % \item[\mdseries\ttfamily turn] prints the contents turned through an
125 % arbitrary angle (the argument to the environment);
126 % \item[\mdseries\ttfamily rotate] prints the contents turned through
127 % an arbitrary angle but does \emph{not} leave any space for the result
130 % The command \cs{turnbox}\marg{angle}\marg{matter to turn} is a macro
131 % version of the \texttt{rotate} environment.
133 % A set of examples is given in the file \texttt{rotex.tex}
135 % \subsection{Positioning}
137 % Floats appear one to a page, and are positioned by spacer skips that
138 % appear (logically) above and below the floating object. The skips,
139 % \cs{rotFPtop} and \cs{rotFPbot}, are initialised from the standard
140 % \LaTeX{} (internal) \cs{@fptop} and \cs{@fpbot} skips. As a result,
141 % by default, rotated floats appear horizontally centred on their
144 % Some sensible values for the registers are:
146 % \begin{tabular}{@{}llp{3in}@{}}
147 % \cs{rotFPtop} & \cs{rotFPbot} & Effect \\
149 % 0pt plus 1fil & 0pt plus 1fil & figure/table appears in middle
151 % 0pt & 0pt plus 1fil & figure/table appears with its top
152 % nearest the edge of the page \\
153 % 0pt plus 1fil & 0pt plus 2fil & figure/table's bottom appears
154 % twice as far from the edge as the
161 % Now we present the documented code. First, package options.
163 % Note that the \texttt{clockwise} and \texttt{counterclockwise}
164 % options are present for compatibility only.
167 \DeclareOption{clockwise}{%
168 \AtBeginDocument{\setkeys{Grot}{units=360}}%
170 \DeclareOption{counterclockwise}{%
171 \AtBeginDocument{\setkeys{Grot}{units=-360}}%
173 \DeclareOption{anticlockwise}{\ds@counterclockwise}
175 % Control figure orientation
177 \DeclareOption{figuresleft}{%
181 \DeclareOption{figuresright}{%
189 \newif\ifrot@messages
190 \DeclareOption{quiet}{%
192 \let\rot@message\@gobble % pro tem -- should suppress altogether
194 \DeclareOption{log}{%
196 \def\rot@message{\PackageInfo{rotating}}%
198 \DeclareOption{chatter}{%
200 \def\rot@message{\PackageWarning{rotating}}%
204 % \begin{macro}{\if@rot@twoside}
205 % \begin{macro}{\rot@LR}
206 % A couple of commands for passing rotation direction around
208 \newif\if@rot@twoside
219 % Pass any unknown options to the \textsf{graphicx} package, and
220 % set up defaults and process the options.
222 \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphicx}}
223 \ExecuteOptions{clockwise,quiet}
227 % Other initialisation
229 \RequirePackage{graphicx}
230 \RequirePackage{ifthen}
233 % \begin{macro}{\rotdriver}
234 % The command \cs{rotdriver} allows a user to specify an initialisation file,
235 % a sort of non-automatically-loaded driver (in the graphics, hyperref
238 \def\rotdriver#1{\makeatletter\input{#1.def}\makeatother}
242 % The \texttt{r@tfl@t} counter is used when generating `labels' for
243 % determining what side of the page the float is on, in twoside mode.
246 \setcounter{r@tfl@t}{0}
249 % Positioning skips (see above).
251 \newskip\rotFPtop \rotFPtop=\@fptop
252 \newskip\rotFPbot \rotFPbot=\@fpbot
255 % \section{Turning and rotation environments}
256 % \begin{macro}{sideways}
257 % Environment to turn the contents through 90 degrees.
261 \setbox\z@\color@hbox\ignorespaces}
271 % \begin{macro}{turn}
272 % Rotate the contents of the environment, leaving the appropriate space
276 \setbox\z@\color@hbox\ignorespaces}
285 % \begin{macro}{rotate}
286 % Rotate the contents of the environment, leaving \emph{no space}.
290 \setbox\z@\color@hbox\ignorespaces}
295 \wd0\z@\dp0\z@\ht0\z@
300 % \begin{macro}{\turnbox}
301 % A macro version of the `rotate' environment.
306 % Note: grouping within the box makes \cs{color@hbox} unnecessary, I think.
308 \setbox\z@\hbox{{#2}}%
310 \wd0\z@\dp0\z@\ht0\z@
315 % \section{Sideways figures and tables}
316 % Now for the macros to provide a complete
317 % environment for sideways figures and tables.
318 % We define two environments |sidewaysfigure| and
319 % |sidewaystable| that
320 % fit in with the normal table and figure floats. These are `fixed'
321 % environments that just do 90 degree rotation, but it would be easy
322 % to parameterize this to do other rotations if needed (the mind
325 % \begin{macro}{\@rotfloat}
326 % \begin{macro}{\@xrotfloat}
327 % \begin{macro}{\rot@float@box}
328 % First a generalised `rotfloat' environment. We need to intercept
329 % \LaTeX's float macros, in order to change the assumed width of a
330 % float being |\columnwidth|. We want it to work on a width of
331 % |\textheight| so that when we rotate the float, it comes out
332 % the right height. This is not actually very satisfactory, since what
333 % we \emph{really} want is for rotated floats to occupy the space they
334 % actually \emph{use}. The captions are a problem --- since they can
335 % precede the figure or table, we cannot set them in a box of the
336 % right width (ie the \emph{height} of the forthcoming object), because
337 % it has not happened yet. The result of these difficulties is that
338 % rotated figures always end up as full page figures.
340 \newsavebox\rot@float@box
344 {\edef\@tempa{\noexpand\@xrotfloat{#1}[\csname fps@#1\endcsname]}\@tempa}%
346 \def\@xrotfloat#1[#2]{%
349 % Set the float contents in
350 % a box of width \cs{textheight} instead of \cs{columnwidth}.
352 \begin{lrbox}\rot@float@box
353 \begin{minipage}\textheight
360 % \begin{macro}{\end@rotfloat}
361 % We call \LaTeX's \cs{end@float} macro having previously rotated
362 % the box \cs{@currbox}.
363 % The rotation is either clockwise or
364 % anti-clockwise, depending on whether the page is odd or even;
365 % in oneside mode it is always odd.
369 % If we are going to know whether pages are odd or even,
370 % we need to use the a variant \cs{pageref} mechanism and our own
371 % specialised labels.
373 \end{minipage}\end{lrbox}%
374 \stepcounter{r@tfl@t}%
375 \rot@label{RF\ther@tfl@t}%
376 \rot@pageref{RF\ther@tfl@t}{\R@@page}%
377 \edef\@tempa{Adding sideways \@captype\space on page \R@@page\space}
378 \rot@mess@toks\expandafter{\@tempa}
382 \vbox to \textheight{%
384 % We need to know for sure which direction rotation is going to
385 % be in, so locally reset the graphics units.
387 \setkeys{Grot}{units=360}%
392 \ifthenelse{\isodd{\R@@page}}{%
394 \rot@mess@toks\expandafter{\the\rot@mess@toks (right hand page)}%
399 \rotatebox{90}{\box\rot@float@box}%
404 \rot@mess@toks\expandafter{\the\rot@mess@toks (left hand page)}%
408 \rotatebox{-90}{\box\rot@float@box}%
413 \rot@message{\the\rot@mess@toks}
420 % \begin{macro}{\sidewaysfigure}
421 % \begin{macro}{\endsidewaysfigure}
422 % \begin{macro}{\sidewaystable}
423 % \begin{macro}{\endsidewaystable}
424 % The following definitions set up two environments,
425 % \texttt{sidewaystable} and \texttt{sidewaysfigure}, which uses this
426 % type of float. Naturally, users may need to change these to suit
427 % their local style. Both contribute to the normal lists of figures
430 \def\sidewaysfigure{\@rotfloat{figure}}
432 \let\endsidewaysfigure\end@rotfloat
434 \def\sidewaystable{\@rotfloat{table}}
435 \let\endsidewaystable\end@rotfloat
442 % \begin{macro}{\@rotdblfloat}
443 % \begin{macro}{\end@rotdblfloat}
444 % Handling double column floats
447 \if@twocolumn\expandafter\@rotdbflt\else\expandafter\@rotfloat\fi
449 \def\@rotdbflt#1{\@ifnextchar[{\@rotxdblfloat{#1}}{\@rotxdblfloat{#1}[tp]}}
450 \def\@rotxdblfloat#1[#2]{%
452 \hsize\textwidth\linewidth\textwidth
453 \begin{lrbox}\rot@float@box
454 \begin{minipage}\textheight
456 \def\end@rotdblfloat{%
458 % If we are going to know whether pages are odd or even,
459 % we need to use the \cs{pageref} mechanism, and labels. But
460 % Labels won't work \emph{unless} the user has put in a
463 \end{minipage}\end{lrbox}%
464 \stepcounter{r@tfl@t}%
465 \rot@label{RF\ther@tfl@t}%
466 \rot@pageref{RF\ther@tfl@t}{\R@@page}%
467 \edef\@tempa{Adding sideways \@captype\space on page \R@@page\space}
468 \rot@mess@toks\expandafter{\@tempa}
469 \@tempdima\ht\rot@float@box
470 \advance\@tempdima by \dp\rot@float@box
472 % \rot@message{BOX wd: \the\wd\rot@float@box,
473 % ht: \the\ht\rot@float@box, dp: \the\dp\rot@float@box:
474 % so shift by .5 of \the\@tempdima}%
479 \vbox to \textheight{%
481 % We need to know for sure which direction rotation is going to
482 % be in, so locally reset the graphics units.
484 \setkeys{Grot}{units=360}%
489 \ifthenelse{\isodd{\R@@page}}{%
492 \rot@mess@toks\expandafter{\the\rot@mess@toks (right hand page)}%
498 \rotatebox{90}{\box\rot@float@box}%
504 \rot@mess@toks\expandafter{\the\rot@mess@toks (left hand page)}%
509 \rotatebox{-90}{\box\rot@float@box}%
514 \rot@message{\the\rot@mess@toks}%
522 % \begin{environment}{sidewaysfigure*}
523 % \begin{environment}{sidewaystable*}
525 \newenvironment{sidewaystable*}
526 {\@rotdblfloat{table}}
528 \newenvironment{sidewaysfigure*}
529 {\@rotdblfloat{figure}}
536 % \begin{macro}{\rot@label}
537 % \begin{macro}{\rot@thepage}
538 % \begin{macro}{\rot@pageref}
539 % \begin{macro}{\rot@protected@write}
540 % \begin{macro}{\if@rot@refundefined}
541 % Note that we used \cs{rot@label}, not \cs{label}; this
542 % variant writes (just) the \emph{true} page number, not the
543 % value of \cs{thepage}; this ``true'' value then needs special
544 % treatment in \cs{protected@write}, just as
545 % \cs{thepage} already has.
546 % \cs{rot@pageref}\marg{generated label name}\marg{cs to set to
547 % pageno} then returns the labelled page's number (or 0 if label not
548 % yet defined). If label not defined, flags using
549 % \cs{rot@refundefinedtrue} for end-document to pick up. (later...)
551 \def\rot@thepage{\@arabic\c@page}
552 \def\rot@label#1{\@bsphack
553 \rot@protected@write{\@auxout}{}%
554 {\string\newlabel{#1}{\rot@thepage}}%
556 \def\rot@pageref#1#2{%
557 \expandafter\ifx\csname r@#1\endcsname\relax
558 \global\@rot@refundefinedtrue
561 \edef#2{\csname r@#1\endcsname}%
564 \long\def\rot@protected@write#1#2#3{%
566 \let\rot@thepage\relax
568 \let\protect\@unexpandable@protect
569 \edef\reserved@a{\write#1{#3}}%
572 \if@nobreak\ifvmode\nobreak\fi\fi
574 \newif\if@rot@refundefined
575 \global\@rot@refundefinedfalse
583 % \begin{macro}{\rot@mess@toks}
584 % A token register to build up debugging messages
586 \newtoks\rot@mess@toks
590 % \subsection{Rotated captions only}
592 % \begin{macro}{\rotcaption}
593 % \begin{macro}{\@makerotcaption}
594 % Sometimes you may find that the rotation of complete figures does
595 % not give quite the right result, since they always take up the whole
596 % page. You may prefer to rotate the caption and the float contents
597 % separately within a conventional figure. Here we offer a suggestion
598 % for a \cs{rotcaption} command, which inserts the caption rotated
599 % by 90 degrees. It is essentially a copy of the normal captioning
601 % Packages which define the \cs{@makecaption} command may also need
602 % to define \cs{@makerotcaption}.
604 \def\rotcaption{\refstepcounter\@captype\@dblarg{\@rotcaption\@captype}}
605 \long\def\@rotcaption#1[#2]#3{%
606 \addcontentsline{\csname ext@#1\endcsname}{#1}{%
607 \protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
612 \@makerotcaption{\csname fnum@#1\endcsname}{#3}%
614 \long\def\@makerotcaption#1#2{%
615 \setbox\@tempboxa\color@hbox#1: #2\color@endbox
616 \ifdim \wd\@tempboxa > .8\vsize
618 \begin{minipage}{.8\textheight}#1: #2\end{minipage}%
621 \rotatebox{90}{\box\@tempboxa}%
631 % \section{Last-minute infrastructure}
633 % \begin{macro}{\color@hbox}
634 % \begin{macro}{\color@endbox}
635 % These macros aren't provided in \LaTeX{}, by default (I seem to have
636 % assumed that they were\dots)
639 \providecommand\color@hbox{\hbox\bgroup}%
640 \providecommand\color@vbox{\vbox\bgroup}%
641 \providecommand\color@endbox{\egroup}%
649 % Version 2.0 is a complete re-write, with most of the work now
650 % being done by the \LaTeXe\ graphics package.
652 % Version 2.1 provides a `clockwise' option to reinstate the behaviour
653 % described in the `\LaTeX\ Companion'
655 % Version 2.2 just intercepts the standard float macros instead
656 % of copying and changing the. The `twoside' option is obeyed.
658 % Version 2.5 corrects problems in sideways figures.
660 % Version 2.6 is a rewrite of the sideways floats via Frank Mittelbach
661 % (to whom many thanks for looking at the mangy code).
663 % Version 2.7 is checked for \LaTeX\ of December 94, and adds the option
664 % of twoside behaviour independent of the general twoside.
666 % Version 2.8 cleans up some mistakes pointed out by Harald Axel
669 % Version 2.9 cleans up some (more) mistakes pointed out by Harald
672 % Version 2.13a permits positioning of rotated floats in the same way
673 % as they are positioned in `normal' floats.
675 % Version 2.14 is the first to be published anywhere as the outcome of
676 % maintenance by Robin Fairbairns.
678 % Version 2.15 deals with page-numbering bug for auto-float-rotation,
679 % and tidying of messages; published to ctan
681 % Version 2.16 uses colour boxes as necessary; published to ctan.
682 % Version 2.16a provides the colour box commands \cs{AtBeginDocument}.