summaryrefslogtreecommitdiff
path: root/obsolete/dviware/dvi2xx/2up.sty
blob: adb81628b95147464422c793e5ced727d6912874 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
%Article: 10393 of comp.text.tex
%From: tvz@zandtwerk.Princeton.EDU (Timothy Van Zandt)
%Newsgroups: comp.text.tex
%Subject: Here is a 2up.sty for LaTeX.
%Message-ID: <14650@princeton.Princeton.EDU>
%Date: 27 Sep 91 19:27:46 GMT
%Organization: Princeton University, Princeton NJ
%
%I seem to remember recent inquiries here or in comp.lang.postscript about
%printing TeX documents two-up. This can be achieved using a PostScript
%filter and/or a dvidvi converter.
%
%Here is another solution. It is a document style option for LaTeX which
%makes a few modifications to LaTeX's output routine. It does not require
%a PostScript output device.
%
%
%---------------------------BEGIN 2up.sty -----------------------------
\def\fileversion{v0.9}
\def\filedate{91/09/26}
%%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%% Document style option `2up', for use with LaTeX v2.09
%% By Timothy Van Zandt, tvz@Princeton.EDU
%%
%% It is recommended that this documentation be kept with the style file.
%%
%% *******************************************************************
%% **                         DESCRIPTION                           **
%% *******************************************************************
%%
%% This is style prints a document two-up. It does this by making a few
%% simple changes to LaTeX's output routine. It does not involve a dvidvi
%% converter or PostScript code. It produces a standard dvi file.
%%
%% As long as you have or can generate the needed font bitmaps (e.g., pk
%% files), fonts will not be scaled and output quality will be high.
%% Non-standard font sizes are needed if the document is reduced.
%% This is often necessary so that the two pages fit on the sheet of paper.
%%
%% If you have used `true' dimensions in your document, you cannot reduce
%% it and you may find it impossible to fit the two pages on a single one.
%% `true' dimensions are a no-no if you want to change the magnification
%% of a document.
%%
%% Otherwise, this style option should be compatible with any LaTeX styles
%% or options that do not change LaTeX's \@outputpage and \enddocument,
%% macros and that do not modify the commands and parameters that these
%% use in a non-standard way.
%%
%% In this documentation, the "source" layout is the layout of your document
%% the way it is usually printed. The "target" layout is the layout when it
%% is printed two-up.
%%
%% 
%% *******************************************************************
%% **                          PARAMETERS                           **
%% *******************************************************************
%%
%% After inputing this file, you must set the following parameters
%%    ***       ONCE AND ONLY ONCE, AND IN THIS ORDER.     ***
%%
%%
%% 1. Target magnification. Use the command
%%
%%     \targetmag{<num>}
%%
%% where
%%
%%   a. <num> is integer nearest to 1000 times the magnification, or
%%   b. <num> is \magstep<n> for a magnification of 1.2^n (n=0,...,5), or
%%   c. <num> is \magstepminus<n> for a magnification of 1.2^{-n} (n=0,...,5).
%%
%% To minimize the number of non-standard font magnifications, use (b) or (c),
%% and choose the magnification closest to 1 such that the source pages
%% fit properly in the target output.
%%
%%
%% 2. Source magnification. Use the command
%%
%%     \sourcemag{<num>}
%%
%% where <num> is as in (1), but for the source output.
%%
%%
%% 3. Target paper width and height. Use:
%%
%%    \targetpaperwidth{<width>true<unit>}
%%    \targetpaperheight{<height>true<unit>}
%%
%% where <unit> is cm, in, pt, etc., and <width> and <height> are the
%% true width and height of the paper, when looking at the target output
%% right side up.
%%
%%
%% 4. Source paper width and height. Use:
%%
%%    \sourcepaperwidth{<width><unit>}
%%    \sourcepaperheight{<height><unit>}
%%
%% where <unit>, <width> and <height> are as in (2), but for the source
%% output.
%%
%%
%% 5. Target layout. Use
%%
%%    \targetlayout{<layout>}
%%
%% where <layout> is "topbottom" if the two source pages are to be printed
%% one on top of the other, or "sidebyside" if the two source pages are
%% to be printed side by side. With the sidebyside layout and LaTeX's twoside
%% option, odd pages always appear on the right and even pages appear on the
%% left; blank pages are inserted if necessary.
%%
%%
%%
%% MAKE NO OTHER CHANGES TO YOUR DOCUMENT EXCEPT THE FOLLOWING:
%%
%% -- You have to see to it that the target output is printed with the
%% correct orientation.
%%
%% -- You can use \emptytwouppage to insert a completely blank half page in
%% the target, and \cleartwouppage to eject a complete target page. Ordinarily
%% you do not need to use these commands.
%%
%%
%% *******************************************************************
%% **                          DEFAULTS                             **
%% *******************************************************************
%%
%% The following commands set the parameters for some common sources and
%% targets. The definitions of these commands are also useful examples.
%%
%%
%% I. \twouparticle.
%%
%% Source: A portrait document on 8.5x11 inch paper with the standard margins
%% used in the article document style and without marginal notes.
%%
%% Target: A landscape document on the same size paper, with the source
%% pages printed side by side.
%%
%% Definition:
%%
%%    \targetmag{\magstepminus1}
%%    \sourcemag{\magstep0}
%%    \targetpaperwidth{11truein}
%%    \targetpaperheight{8.5truein}
%%    \sourcepaperwidth{8.5in}
%%    \sourcepaperheight{11in}
%%    \targetlayout{sidebyside}
%%
%% If you use narrower side margins than the default ones in the article
%% document style, or if you use marginal notes, then you will need to
%% to reduce the magnication to \magstepminus2 or lower or use
%% \twouplegaltarget, defined below.
%%
%%
%% II. \twouplegaltarget.
%%
%% Source: A portrait document on 8.5x11 inch paper with just about any
%% margins and perhaps with marginal notes.
%%
%% Target: A landscape document on legal size paper (8.5x14 inches),
%% with the source pages printed side by side.
%%
%% Definition: 
%%
%%    \targetmag{\magstepminus1}
%%    \sourcemag{\magstep0}
%%    \targetpaperwidth{14truein}
%%    \targetpaperheight{8.5truein}
%%    \sourcepaperwidth{8.5in}
%%    \sourcepaperheight{11in}
%%    \targetlayout{sidebyside}
%%
%%
%% III. \twouplandscape.
%%
%% Source: A landscape document on 8.5x11 inch paper with just about any
%% margins.
%%
%% Target: A portrait document on the same size paper, with the source pages
%% stacked vertically.
%%
%% Definition:
%%
%%    \targetmag{\magstepminus2}
%%    \sourcemag{\magstep0}
%%    \targetpaperwidth{8.5truein}
%%    \targetpaperheight{11truein}
%%    \sourcepaperwidth{11in}
%%    \sourcepaperheight{8.5in}
%%    \targetlayout{topbottom}
%%
%%
%% *******************************************************************
%% **                      IMPLEMENTATION                           **
%% *******************************************************************
%%
%%
\typeout{Document style option: `2up' \fileversion \space\space <tvz>}
%%
%% Parameter registers:
\newcount\@sourcemag
\newdimen\@targetpaperwidth
\newdimen\@targetpaperheight
\newdimen\@sourcepagewidth
\newdimen\@sourcepageheight
\newif\if@sidebyside
\@sidebysidetrue
%%
%% Registers used by output routing.
\newif\if@firstpage
\@firstpagetrue
\newbox\@leftpage
\newbox\@rightpage
%%
\def\targetmag#1{\mag #1}
\def\sourcemag#1{\@sourcemag #1}
\def\targetpaperwidth#1{\@targetpaperwidth #1}
\def\targetpaperheight#1{\@targetpaperheight #1}
%%
%% \@sourcepagewidth and |\@sourcepageheight should be the unmagnified
%% dimensions of the source page when measured without TeX's 1 inch margins.
\def\sourcepaperwidth#1{%
  \@sourcepagewidth #1
  \advance\@sourcepagewidth by -2in
  \divide\@sourcepagewidth by \@sourcemag
  \multiply\@sourcepagewidth by 1000\relax}
\def\sourcepaperheight#1{%
  \@sourcepageheight #1
  \advance\@sourcepageheight by -2in
  \divide\@sourcepageheight by \@sourcemag
  \multiply\@sourcepageheight by 1000\relax}
\def\targetlayout#1{%
  \def\@tempa{sidebyside}%
  \def\@tempb{topbottom}%
  \def\@tempc{#1}
  \ifx\@tempa\@tempc
    \@sidebysidetrue
  \else
    \ifx\@tempb\@tempc
      \@sidebysidefalse
    \else
      \@latexerr{Valid target layouts are "sidebyside" and "topbottom"}\@eha
    \fi
  \fi}
%%
\def\magstepminus#1{%
  \ifcase#1 \@m\or 833\or 694\or 579\or 482\or 401\fi\relax}
\def\twouparticle{%
  \targetmag{\magstepminus1}%
  \sourcemag{\magstep0}%
  \targetpaperwidth{11truein}%
  \targetpaperheight{8.5truein}%
  \sourcepaperwidth{8.5in}%
  \sourcepaperheight{11in}%
  \targetlayout{sidebyside}}
\def\twouplegaltarget{%
  \targetmag{\magstepminus1}%
  \sourcemag{\magstep0}%
  \targetpaperwidth{14truein}%
  \targetpaperheight{8.5truein}%
  \sourcepaperwidth{8.5in}%
  \sourcepaperheight{11in}%
  \targetlayout{sidebyside}}
\def\twouplandscape{%
  \targetmag{\magstepminus2}%
  \sourcemag{\magstep0}%
  \targetpaperwidth{8.5truein}%
  \targetpaperheight{11truein}%
  \sourcepaperwidth{11in}%
  \sourcepaperheight{8.5in}%
  \targetlayout{topbottom}}
%%
%% LaTeX's output page routine is modified so that it saves each page and
%% prints out every two. Each page is centered in a half-page
\def\@outputpage{%
  \if@firstpage
    \global\@firstpagefalse
    \def\next{%
      \@makepagebox\@leftpage
      \stepcounter{page}}%
    \if@sidebyside
      \if@twoside
        \ifodd\count\z@
          \def\next{%
            \@makeemptypage\@leftpage
            \@outputpage}%
        \fi
      \fi
    \fi
  \else
    \global\@firstpagetrue
    \def\next{%
      \@makepagebox\@rightpage
      \@shiptwouppage
      \stepcounter{page}}
    \if@sidebyside
      \if@twoside
        \ifodd\count\z@
        \else
          \def\next{%
            \@makeemptypage\@rightpage
            \@shiptwouppage
            \@outputpage}%
        \fi
      \fi
    \fi
  \fi
  \next}
%%
%% This is the \shipout routine.
\def\@shiptwouppage{
  \if@sidebyside
    \shipout\vbox{%
      \vskip -1truein
      \hbox{\hskip -1truein\box\@leftpage\box\@rightpage}}
  \else
    \shipout\hbox{%
      \hskip -1truein
      \vbox{\offinterlineskip\vskip -1truein \box\@leftpage\box\@rightpage}}
  \fi}
%%
%% \@makepagebox is just like \@outputpage in \LaTeX's standard output
%% routine, except that it saves the page in a box instead of shipping it out.
\def\@makepagebox#1{%
  \begingroup\catcode`\ =10 
    \let\-\@dischyph \let\'\@acci \let\`\@accii \let\=\@acciii
    \if@specialpage 
      \global\@specialpagefalse\@nameuse{ps@\@specialstyle}%
    \fi
    \if@twoside 
      \ifodd\count\z@
        \let\@thehead\@oddhead \let\@thefoot\@oddfoot
        \let\@themargin\evensidemargin
      \else
        \let\@thehead\@evenhead \let\@thefoot\@evenfoot
        \let\@themargin\oddsidemargin
      \fi
    \else
    \fi
    \setbox#1=\vbox to \@sourcepageheight{%
      \normalsize \baselineskip\z@ \lineskip\z@
      \let\par\@@par
      \vskip \topmargin
      \hbox to \@sourcepagewidth{%
        \hskip \@themargin
        \vbox{%
          \setbox\@tempboxa=\vbox to\headheight{%
            \vfil
            \hbox to\textwidth{%
              \let\label\@gobble \let\index\@gobble \@thehead}}%
          \dp\@tempboxa\z@
          \box\@tempboxa
          \vskip \headsep
          \box\@outputbox
          \baselineskip\footskip
          \hbox to\textwidth{%
            \let\label\@gobble \let\index\@gobble  \@thefoot}}
        \hss}
      \vss}%
    \if@sidebyside
      \global\setbox#1=\vbox to \@targetpaperheight{%
        \vss
        \hbox to .5\@targetpaperwidth{\hss\box#1\hss}
        \vss}
    \else
      \global\setbox#1=\vbox to .5\@targetpaperheight{%
        \vss
        \hbox to \@targetpaperwidth{\hss\box#1\hss}
        \vss}
    \fi
    \global\@colht\textheight
  \endgroup
  \let\firstmark\botmark}
%%
%% This is used to generate an empty page.
\def\@makeemptypage#1{%
  \if@sidebyside
    \global\setbox#1=\vbox to \@targetpaperheight{\vss
      \hbox to .5\@targetpaperwidth{\hss}}
  \else
     \global\setbox#1=\vbox to .5\@targetpaperheight{\vss
       \hbox to .5\@targetpaperwidth{\hss\box#1\hss}}
  \fi}
%%
%% Eject a page, even when there is only one source page on it.
\def\cleartwouppage{%
  \clearpage
  \if@firstpage
  \else
    \twoupemptypage
  \fi}
%%
\def\twoupemptypage{%
  \clearpage
  {\let\@makepagebox\@makeemptypage
  \@outputpage}
  \addtocounter{page}{-1}}
%%
%% This is LaTeX's standard \enddocument, except that we change \clearpage
%% to \cleartwouppage.
\def\enddocument{\@checkend{document}\cleartwouppage\begingroup  
  \if@filesw \immediate\closeout\@mainaux 
  \def\global\@namedef##1##2{}\def\newlabel{\@testdef r}%
  \def\bibcite{\@testdef b}\@tempswafalse \makeatletter\input \jobname.aux
  \if@tempswa \@warning{Label(s) may have changed.  Rerun to get
  cross-references right}\fi\fi\endgroup\deadcycles\z@\@@end}
%%
\endinput