summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/rotpages/rotpages.sty
blob: 30d4d37de4314eb581fdd9c48dc27fee29b4fe3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{rotpages}[2002/05/30 R3.0 Rotated Pages (SC)]
%%
%% INTERFACE
%%
%% Switch on and off the page rotation
%%   \rotboxpages
%%   \endrotboxpages
%%
%% Setting of the dimensions of the rotated pages or columns (its the
%% package user responsibility to assure that sensible values are employed)
%%   \setlenght{\rotboxheight}{...}
%%   \setlength{\rotboxwidht}{...}
%% Since the rotated column needs to fit the same space as the non
%% rotated one, scaling is used to correct the dimensions. If the
%% initial values are not properly selected, the column may result
%% distorted. Dimensions larger than usual can be introduced to get 
%% page scaling.
%%
%% Hooks for introducing frames and so on
%%   \renewcommand{\rotboxAtRotationHook}[1]{...}
%%   \renewcommand{\rotboxAtShippingHook}[1]{...}
%% In both command a box containing the page is passed as an
%% argument. The difference is that in the first case the hook is
%% invoked at the column preparation time (so that, e.g., the relative number
%% of the page among the rotated lot is available), while in the
%% second case the hook is invoked at the shipping time (so that,
%% e.g., the global page number is known).
%% Note: make sure the page processing hook returns a box whose global
%% height is all in the ``height'' height field and not in the
%% ``depth'' one.
%%
%% A command to test if we are rotating the pages or not (this uses
%% the ifthen package
%%   \ifthenelse{\boolean{rotboxactive}}{...}{...}

\RequirePackage{graphics}
\RequirePackage{ifthen} 
\RequirePackage{calc}

\newlength{\rotboxheight}
\newlength{\rotboxwidth}
\newboolean{rotboxactive}
\newbox\SC@deferredpages
\newbox\SC@curpage

%% Reasonable defaults for the hooks, the widths and the heights
%%\newcommand{\rotboxAtRotationHook}[1]{#1}
\newcommand{\rotboxAtRotationHook}[1]{%
  \begingroup\fboxsep=3ex\raisebox{\depth}[\height+\depth][0pt]
  {\fbox{#1}}\endgroup}
\newcommand{\rotboxAtShippingHook}[1]{#1}
%%\newcommand{\rotboxAtShippingHook}[1]{%
%%  \begingroup\fboxsep=3ex\raisebox{\depth}[\height+\depth][0pt]
%%  {\fbox{#1}}\endgroup}  
\setboolean{rotboxactive}{false}
\AtBeginDocument{%
  \setlength{\rotboxheight}{\vsize-6ex-1pt}
  \setlength{\rotboxwidth}{\hsize-6ex-1pt}}

\let\SC@makecol=\@makecol
\let\SC@makefcolumn=\@makefcolumn
\newlength\SC@pageh
\newlength\SC@pagev
%%\newlength\SC@boxw
%%\newlength\SC@boxh
%%\newlength\SC@boxd

%% Processing of the column in ``upside-down mode''
%% Here we simply apply the relevant hook and store the page onto the 
%% page stack
\def\SC@processpage{%
  \message{...deferring page...}%
  \global\setbox\SC@deferredpages\hbox{\unhbox\SC@deferredpages%
    \hbox{\rotboxAtRotationHook{%
        \raisebox{\depth}[\height+\depth][0pt]%
        {\scalebox{-1}{\copy\@outputbox}}}}}}

%% Shipping of the pages previously pushed onto the stack
\def\SC@shippagestack{%
  \global\setbox\SC@deferredpages\hbox{%
    \unhbox\SC@deferredpages%
    \global\setbox\SC@curpage\lastbox}%
  \ifhbox\SC@curpage%
  %%\settodepth\SC@boxd{\copy\SC@curpage}%
  %%\settoheight\SC@boxh{\copy\SC@curpage}%
  %%\typeout{vsize \the\vsize - sizeh \the\SC@boxh - sized \the\SC@boxd}
  \noindent\rotboxAtShippingHook{\box\SC@curpage}\newpage%
  {\SC@shippagestack}\fi}

%% Public command to activate the upside-down mode
\def\rotboxpages{%
  \newpage
  \setboolean{rotboxactive}{true}
  %% save standard page size
  \setlength\SC@pageh{\hsize}%
  \setlength\SC@pagev{\vsize}%
  \begingroup
  \def\@opcol{\relax}%
  \def\@startcolumn{\relax}%
  \def\@makecol{\SC@makecol\SC@processpage}%
  %%\def\@makefcolumn##1{\SC@makefcolumn{##1}\SC@processpage}%
  %% Alter page size to guarantee that there is space for the frame
  %% This is problematic as we have to change a number of measures. Currently 
  %% this works only if the columns are as high as the whole page.
  \setlength\hsize{\rotboxwidth} \setlength\vsize{\rotboxheight}
  \setlength\linewidth{\rotboxwidth}
  \setlength\columnwidth{\rotboxwidth}
  \setlength\textwidth{\rotboxwidth}
  \setlength\textheight{\rotboxheight}
  \setlength\@colht{\rotboxheight} \setlength\@colroom{\rotboxheight}}

%% Public command to deactivate the upside-down mode
\def\endrotboxpages{%
  \newpage
  \endgroup
  %% Restore the values that don't get updated by the \endgroup
  \setlength\hsize{\SC@pageh}
  \setlength\vsize{\SC@pagev}
  \SC@shippagestack
  \setboolean{rotboxactive}{false}}
%%

%% R3.0
%% * Note: revision 2 was a major nightmare
%% * this version is a complete rework

%% R2.0 
%% * Added: Arbitrary framing command
%% * Added: Arbitrary scaling of the rotated pages
%% * Fixed: incorrect global setting of the \fboxsep macro