summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/twoup/twoup.dtx
blob: cbbce075a57f00aeef98a4727d6a958c2db7456d (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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
% \iffalse
%<*docdriver>
\documentclass{ltxdoc}[1996/01/11]
\begin{filecontents}{twoup.ins}
% The twoup package, version 1.3
\input docstrip.tex
\preamble

 m This is the twoup package
 o Copyright 2005-07 by Mogens Lemvig Hansen,
 g Please find my e-mail address in the left margin
 e
 n Run twoup.dtx through LaTeX and read the documentation in twoup.dvi
 s
 @ This work may be distributed and/or modified under the
 k conditions of the LaTeX Project Public License, either version 1.3
 a of this license or (at your option) any later version.
 y The latest version of this license is in
 j   http://www.latex-project.org/lppl.txt
 u and version 1.3 or later is part of all distributions of LaTeX
 . version 2005/12/01 or later.
 c
 o This work has the LPPL maintenance status 'maintained'.
 m
   The Current Maintainer of this work is Mogens Lemvig Hansen.

   This work consists of the files twoup.dtx and twoup.ins
   and the derived file twoup.sty.

\endpreamble
% I think that \path:twoup.sty: should go into the directory
% \path:tex/latex/misc:; however, \textsc{DocStrip} will not heed my advise
% unless your configuration file, \path:docstrip.cfg:, allows it to.
\usedir{tex/latex/misc}
\generate{\file{twoup.sty}{\from{twoup.dtx}{package}}}
\endbatchfile
\end{filecontents}
\usepackage{url,randtext}
\InputIfFileExists{../myemail}{}{%
   \def\myemail{See top of .sty file for e-mail address}}
%\discretionaries |~!@$%^&*()_+`=#{"}[]:;'<>,.?\/|
%\CodelineIndex%\EnableCrossrefs
\makeatletter
\newcommand{\nextlinelabel}[2][1]{\@bsphack
   \@tempcnta\c@CodelineNo
   \advance\@tempcnta#1\relax
   \def\@currentlabel{\the\@tempcnta}\label{#2}%
   \@esphack}
\makeatother
\begin{document} \DocInput{twoup.dtx} \end{document}
%</docdriver>
% \fi
% \CheckSum{324}
% \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         \~}
%
% \def\fileversion{1.3} \def\filedate{2007/02/26} \def\docdate{\filedate}
% \title{The \textsf{twoup} Package\thanks{This file describes version
%   \fileversion, \filedate.}}
% \author{\copyright\ Mogens Lemvig Hansen\thanks{%
%    The \textsf{twoup} package is distributed under the \LaTeX\ Project
%    Public License; please see Section~\ref{sec:license}.}\\
%    \myemail}
% \date{\docdate}
% \maketitle
% \begin{abstract}
%    The \textsf{twoup} assists in two-up or booklet printing
%    using the \textsf{2up} or \textsf{booklet} packages
%    or using the psnup program and friends.
% \end{abstract}
%
% \tableofcontents\bigskip
%
% I am familiar with three ways of producing two-up
% documents\footnote{That is, printing two logical pages side by
% side on one side of one sheet of paper.} and
% booklets:\footnote{That is, rearranging the logical pages before
% printing them two-up on both sides of the paper in such a manner
% that the resulting sheets of paper can be folded down the middle
% into a small book.} the \textsf{2up} package, the \textsf{booklet}
% package, and the postscript tool psnup.
% The \textsf{2up} and \textsf{booklet} packages are both available
% from CTAN, and psnup is included with many \TeX\ distributions
% including MiK\TeX. All three will by default
% accomplish this task by scaling the page down.  However, a one-up
% page layout does not necessarily work well when scaled.  The
% \textsf{twoup} package provides a page layout designed for two-up
% printing and sets the relevant \textsf{2up} or \textsf{booklet}
% parameters or gives advise on how to use the postscript tools.
%
% \section{Usage}
% Give the paper size you intend to print on as an option to
% \verb:\documentclass:.\footnote{If you intend to print on your
% default paper size, you do not have to give any paper size
% option.}  The \textsf{twoup} package re-calculates the paper size
% and margins for two-up printing.\footnote{If you print on
% \texttt{a4paper}, \textsf{twoup} calculates the same paper size as
% the \texttt{a5paper} option but with different (smaller) margins.
% You may consider this discrepancy either a bug or a feature.}
% Then choose the method:
%
% \subsection{Plain two-up with the \textsf{2up} package}
% Load the \textsf{2up} package \emph{before} the \textsf{twoup}
% package.
% \begin{quote}
% \verb:\documentclass[a4paper,12pt]{article}:\\
% \verb:\usepackage{2up}:\\
% \verb:\usepackage{twoup}:
% \end{quote}
%
% Unfortunately cross references may not work out under the
% \textsf{2up} package.  The solution is, as explained in the
% \textsf{2up} documentation, to comment out the
% \verb:\usepackage{2up}: line, run your .tex file through \LaTeX\
% until all references work out, then load \textsf{2up} again and run
% your document through \LaTeX\ once (an only once).
%
% \subsection{Booklets with the \textsf{booklet} package}
% Load the \textsf{booklet} package \emph{before} the \textsf{twoup}
% package.
% \begin{quote}
% \verb:\documentclass[letterpaper,12pt]{article}:\\
% \verb:\usepackage[print]{booklet}:\\
% \verb:\usepackage{twoup}:
% \end{quote}
% Without the \verb:print: option, the \textsf{booklet} package does
% nothing.
%
% The \textsf{booklet} package has miraculously solved the
% cross-reference problem of the \textsf{2up} package but does not
% provide a plain two-up option.
%
% \subsection{Plain two-up with the postscript tools}
% Simply load the \textsf{twoup} package.
% \begin{quote}
% \verb:\documentclass[letterpaper,12pt]{article}:\\
% \verb:\usepackage{twoup}:
% \end{quote}
% When you run your .tex file through \LaTeX, the \textsf{twoup}
% package will tell you which options to use with the psnup program;
% look for the psnup command line near the end of the
% transcript.\footnote{Both on screen and in the .log file.}  If you
% give a paper size option, the \textsf{twoup} package will also
% tell you which lines you will have to add to your postscript file
% by hand.
%
% Run the .dvi file through dvips\footnote{The current version of
% the \textsf{twoup} package requires that you use dvips.  If you
% want to use some other .dvi-to-postscript program, please see code
% line~\ref{line:dvips} and the commentary around it.} to make a
% postscript file.
% \begin{quote}
% \verb:dvips: \meta{file}
% \end{quote}
%
% Then run psnup with the options that the \textsf{twoup} package
% gave you above.  Even Win95 allows you to cut-and-paste the
% command line which could look something like this:
% \begin{quote}
% \verb:psnup: \verb:-pletter: \verb:-W396.0pt: \verb:-H612.0pt:
% \verb:-2: \meta{file}\verb:.ps: \meta{twoup}\verb:.ps:
% \end{quote}
%
% The postscript file, \meta{twoup}\verb:.ps:, has by now lost all
% consciousness of which paper size it is to be printed on.  If you
% are about to print on your printer's default paper size, that is
% no problem.  To print on any other paper size you most likely have
% to place a paper size command in \meta{twoup}\verb:.ps:.  With a
% plain text editor add the lines \textsf{twoup} gave you in the
% \LaTeX\ run to \meta{twoup}\verb:.ps:. The lines to add could look
% like this:
% \begin{quote}
% \verb;%%BeginPaperSize: letter;\\
% \verb;letter;\\
% \verb;%%EndPaperSize;
% \end{quote}
% Place the new lines just after the
% \verb:%%EndComments: line near the top of \meta{twoup}\verb:.ps:.
%
% \subsection{Booklets with the postscript tools}
% The \LaTeX\ side of making booklets is much like simple two-up.
% You may want to use the \texttt{twoside} option to
% \verb:\documentclass: to make the inner margins a bit larger etc.
% \begin{quote}
% \verb:\documentclass[a4paper,11pt,twoside]{article}:\\
% \verb:\usepackage{twoup}:
% \end{quote}
% As above, the \textsf{twoup} package will advise you on which
% options to use with the psnup program.  Run your .dvi file through
% dvips:
% \begin{quote}
% \verb:dvips: \meta{file}
% \end{quote}
%
% Now the fun begins:  Before using psnup you must use the psbook
% program to fold your postscript file into a signature:
% \begin{quote}
% \verb:psbook: \meta{file}\verb:.ps: \meta{book}\verb:.ps:
% \end{quote}
% The number of pages in a signature must be divisible by four, so
% psbook may add a few blank pages to the end of your booklet. Run
% the result through psnup with the options the \textsf{twoup}
% package calculated in the \LaTeX\ run. The command line could look
% something like this:\footnote{Under Unix, you can pipe the psbook
% and psnup commands together; Windows, however, does not like long
% command lines.}
% \begin{quote}
% \verb:psnup: \verb:-pa4: \verb:-Pa5:
% \verb:-2: \meta{book}\verb:.ps: \meta{twoup}\verb:.ps:
% \end{quote}
%
% Unless you are about to print on your printer's default paper
% size, add the paper size command to \meta{twoup}\verb:.ps: as
% above.
%
% You can print your postscript file, \meta{twoup}\verb:.ps:, now,
% but if you want to print double sided, you may have to split the
% file in two with the psselect program:
% \begin{quote}
% \verb:psselect: \verb:-o: \meta{twoup}\verb:.ps:
%    \meta{odd}\verb:.ps:\\
% \verb:psselect: \verb:-e:
%    \meta{twoup}\verb:.ps: \meta{even}\verb:.ps:
% \end{quote}
% Then print \meta{odd}\verb:.ps:, turn the paper over, and print
% \meta{even}\verb:.ps:.\footnote{Depending on your printer, you may
% want to use psselect's \texttt{-r} option to print the \meta{even}
% pages in reverse order.}
%
% \subsection{Options}
% By default the \textsf{twoup} package leaves room for running
% headers and footers.  Use the \texttt{noheadfoot},
% \texttt{nofoot}, or \texttt{nohead} option to reclaim that space.
% As a side efect, these options set the page style:
% \texttt{noheadfoot} implies the \texttt{empty} page style,
% \texttt{nofoot} implies the \texttt{headings} page style, and
% \texttt{nohead} implies the \texttt{plain} page style. Moreover,
% the \texttt{nofoot} and \texttt{noheadfoot} options disable the
% \texttt{plain} page style\footnote{By making \texttt{plain}
% synonymous with the \texttt{empty} style.} to prevent the
% \verb:\chapter: command from inserting a
% \verb:\thispagestyle{plain}: command.
%
% The \textsf{twoup} package knows the standard paper size options:
% \texttt{letterpaper}, \texttt{legalpaper},
% \texttt{executivepaper}, \texttt{a4paper}, \texttt{a5paper}, and
% \texttt{b5paper}.  You should use these options as global options
% to \verb:\documentclass:.  If you print two-up on
% \texttt{legalpaper}, the text width is larger than what is
% considered comfortable.  You should use the \texttt{twocolumn}
% option to \verb:\documentclass: or, better, the \textsf{multicol}
% package.
%
% If you use \textsf{twoup} without \textsf{2up} or
% \textsf{booklet}, then the \textsf{twoup} package will insert a
% paper-size \verb:\special: in your .dvi file.  Use the
% \verb:nospecial: option to suppress this.
%
% \subsection{Additional commands}%
% \DescribeMacro{\cleartolastpage}%
% If you are making a booklet, the number of pages must be divisible
% by four; indeed, the \textsf{booklet} package or the psbook
% program will add blank pages as necessary.  If, however, you want
% to print on the last page, the back of your booklet, you can use
% the \verb:\cleartolastpage: command in a \verb:twosided: context
% to (print all pending tables, figures, and footnotes and) insert
% as many blank pages as necessary to reach a page number divisible
% by four. In detail,
% \begin{quote}
% \verb:\cleartolastpage:\oarg{div}\oarg{rem}\\
% \verb:\cleartolastpage*:\oarg{div}\oarg{rem}
% \end{quote}
% both print all pending floats and insert blank pages until the
% page number leaves remainder \meta{rem} when divided by
% \meta{div}.  The default value of \meta{rem} is~$0$, and the
% default value of \meta{div} is~$4$ under the \verb:twosided: class
% option and $2$ otherwise.  The starred version suppresses the
% printing of page numbers on the inserted blank pages.
%
% Thus \verb:\cleartolastpage[1]: is equivalent to \LaTeX's
% \verb:\clearpage: command
% and \verb:\cleartolastpage[2][1]: is equivalent to
% \verb:\cleardoublepage:.
%
% The \verb:\cleartolastpage: command may fail to put you one the
% last page if page~$1$ is not the very first page (maybe because
% you have differently numbered front matter); use the optional
% \meta{rem} argument to overcome this.
%
%
% \section{Installation}
% As you must have figured, you generate the documentation for the
% \textsf{twoup} package by running the file \url:twoup.dtx: through
% \LaTeX---thrice to resolve cross references.
%
% To extract the package itself from the .dtx file, run
% \url:twoup.ins: through \LaTeX:
% \begin{quote}
% \verb:latex twoup.ins:
% \end{quote}
% You now have to decide what to do with several files.
% \begin{itemize}
% \item You may have to move the file \url:twoup.sty: to some
% directory where \LaTeX\ can find it;
% \url:(local)texmf/tex/latex/misc: would be the natural
% choice~\cite{tds}.
%
% \item Move the documentation, \url:twoup.dvi: or \url:twoup.pdf:,
% to \url:(local)texmf/doc/latex/misc:.
%
% \item You may discard the source files, \url:twoup.dtx: and
% \url:twoup.ins:, or store them in
% \url:(local)texmf/source/latex/misc:.
%
% \item Discard all remaining \url:twoup.*: files.
% \end{itemize}
%
%
% \section{Limitations}
% The \textsf{twoup} package is designed for and tested on
% \texttt{letterpaper}, \texttt{legalpaper}, and \texttt{a4paper}.
% Printing two-up on smaller paper is hardly feasible; printing on
% larger paper is beyond the normal desktop printer.
%
% The margins calculated by \textsf{twoup} are too small for
% \verb:\marginpar:s.\footnote{But just large enough for the line
% numbers inserted by the \textsf{lineno} package.}
%
% If you print two-up on \texttt{legalpaper}, \textsf{twoup} leaves
% a text width larger than what is considered comfortable.  You
% should use the \texttt{twocolumn} option to \verb:\documentclass:
% or, better, the \textsf{multicol} package.
%
% The \textsf{twoup} package is not compatible with the
% \textsf{geometry} package.  Both packages re-calculate the margins
% and the disagree on the interpretation of the paper size options.
%
% I know very little about postscript, yet I tell you to go add
% lines to .ps files.  The advise \textsf{twoup} gives has always
% worked for me; if it doesn't work for you, please teach me the
% correct way.
%
% The current implementation of \textsf{twoup} requires dvips
% (unless you use the \textsf{2up} or \textsf{booklet} packages).
% This limitation is easily overcome with your help: please see code
% line~\ref{line:dvips} and the commentary around it.
%
%
% \section{License}\label{sec:license}
% This work may be distributed and/or modified under the
% conditions of the \LaTeX\ Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   \url{http://www.latex-project.org/lppl.txt}
% and version 1.3 or later is part of all distributions of \LaTeX\
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained.'
%
% The Current Maintainer of this work is Mogens Lemvig Hansen.
%
% This work consists of the files \url{twoup.dtx} and \url{twoup.ins}
% and the derived file \url{twoup.sty}.
%
%
% \StopEventually{
%    \nocite{ltclass}
%    \bibliographystyle{is-plain}
%    ^^A\bibliography{tex}
%      \begin{thebibliography}{1}
%
%      \bibitem{ltclass}
%      Leslie Lamport, Frank Mittelbach, and Johannes Braams.
%      \newblock {\em Standard Document Classes for \LaTeX\ version 2e}.
%      \newblock CTAN, 1999/09/10 edition, 1999.
%
%      \bibitem{tds}
%      {TUG Working Group on a {\TeX} Directory Structure (TWG-TDS)}.
%      \newblock {\em A Directory Structure for {\TeX} Files}.
%      \newblock CTAN, version 0.9995, January 26, 1998 edition, 1998.
%
%      \end{thebibliography}
% }
%
% \section{Implementation}
% The \textsf{twoup} package doesn't have to do much---just
% re-calculate the paper size and the margins and put together the
% advise on how to use the psnup program. The \textsf{twoup} package
% does its thing based on the plain \LaTeX\ parameters
% \verb:\paperwidth:, \verb:\paperheight:, \verb:\headheight:,
% \verb:\headsep:, \verb:\footskip:, \verb:\topskip:, and
% \verb:\baselineskip:.
%
% \subsection{Identification}
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{twoup}[2007/02/26 version 1.3]
%    \end{macrocode}
%
% \subsection{Declaration of Options}
% The \texttt{noheadfoot} option sets the relevant lenghts to zero.
% Since there is no room for headers or footers, the only sensible
% page style is \texttt{empty}.  The \verb:\chapter: command issues
% a \verb:\thispagestyle{plain}: command, so re-define the
% \texttt{plain} style to be a synonym for the \texttt{empty}
% style.\footnote{I borrowed the idea of brutally making
% \texttt{plain} a synonym for \texttt{empty} from David Carlisle's
% \textsf{nopageno} package.}
%    \begin{macrocode}
\DeclareOption{noheadfoot}{%
   \setlength{\headheight}{0pt}%
   \setlength{\headsep}{0pt}%
   \setlength{\footskip}{0pt}%
   \let\ps@plain\ps@empty
   \pagestyle{empty}}
%    \end{macrocode}
% With room for a header but without a footer the most sensible page
% style would be \texttt{headings}.  Again the \texttt{plain} page
% style must be disabled.
%    \begin{macrocode}
\DeclareOption{nofoot}{%
   \setlength{\footskip}{0pt}%
   \let\ps@plain\ps@empty
   \pagestyle{headings}}
%    \end{macrocode}
% With room for a footer but no header the most sensible page style
% is \texttt{plain}---so don't change \texttt{plain}.
%    \begin{macrocode}
\DeclareOption{nohead}{%
   \setlength{\headheight}{0pt}%
   \setlength{\headsep}{0pt}%
   \pagestyle{plain}}
%    \end{macrocode}
%
% \begin{macro}{\TwoUp@info}
% \begin{macro}{\TwoUp@paper}
% The paper size options record part of the advise on how to use the
% psnup program in \verb:\TwoUp@info: and part of the advise on how
% to edit the final postscript file in \verb:\TwoUp@paper:.
%    \begin{macrocode}
\DeclareOption{letterpaper}{%
   \def\TwoUp@info{-pletter -W5.5in -H8.5in}%
   \def\TwoUp@paper{letter}}%
\DeclareOption{legalpaper}{%
   \def\TwoUp@info{-plegal -W7in -H8.5in}%
   \def\TwoUp@paper{legal}}%
\DeclareOption{executivepaper}{%
   \def\TwoUp@info{-pexecutive -W5.25in -H7.25in}%
   \def\TwoUp@paper{executive}}%
\DeclareOption{a4paper}{%
   \def\TwoUp@info{-pa4 -Pa5}%
   \def\TwoUp@paper{a4}}%
\DeclareOption{a5paper}{%
   \def\TwoUp@info{-pa5 -W105mm -H148mm}%
   \def\TwoUp@paper{a5}}%
\DeclareOption{b5paper}{%
   \def\TwoUp@info{-pb5 -W125mm -H176mm}%
   \def\TwoUp@paper{b5}}%
%    \end{macrocode}
% \end{macro}\end{macro}
%
% \begin{macro}{\TwoUp@special}
% The \textsf{twoup} package needs to record the (smaller) paper
% size in the postscript file.  That means placing a suitable
% \verb:\special: command in the .dvi file.  Unfortunately,
% ``suitable'' depends on which .dvi-to-postscript program you use,
% so we need an option for each such program.  I have implemented
% the option for dvips but was too lazy to figure out the
% appropriate command for other .dvi-to-postscript
% programs.\nextlinelabel[2]{line:dvips}
%    \begin{macrocode}
\DeclareOption{dvips}{%
   \def\TwoUp@special{%
      \special{papersize=\the\paperwidth,\the\paperheight}}}
%    \end{macrocode}
% If you need to use the \textsf{twoup} package with another
% postscript driver, please let me know so I can incorporate more
% options in future releases of \textsf{twoup}.  While you wait for
% that, use the \texttt{nospecial} option to suppress the
% \verb:\special:.
%    \begin{macrocode}
\DeclareOption{nospecial}{%
   \def\TwoUp@special{\relax}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Execution of Options}
% Default to dvips leaving space for headers and footer as the class
% sees fit.
%    \begin{macrocode}
\ExecuteOptions{dvips}
\ProcessOptions
%    \end{macrocode}
%
% \subsection{Main Code}
% \subsubsection{Paper Size and psnup Advise}
% \begin{macro}{\TwoUp@info}
% Before re-calculating the paper size, we must record part of the
% psnup advise.  If a paper size option did that already, all is
% fine.  Otherwise we must be printing on the default paper size
% which we must then determine.  We will try to recognize the most
% common default paper sizes: a4, letter, and legal.  Since this is
% the default paper size, we may assume that the printer knows how
% to handle it.  We therefore suppress the advise on editing the
% final postscript file by \emph{not} defining \verb:\TwoUp@paper:.
%    \begin{macrocode}
\ifx\TwoUp@info\undefined
   \setlength{\@tempdima}{8.5in}
   \ifdim\paperwidth=\@tempdima
      \setlength{\@tempdima}{11in}
      \ifdim\paperheight=\@tempdima
         \def\TwoUp@info{-pletter -W5.5in -H8.5in}
      \fi
      \setlength{\@tempdima}{14in}
      \ifdim\paperheight=\@tempdima
         \def\TwoUp@info{-plegal -W7in -H8.5in}
      \fi
   \fi
   \setlength{\@tempdima}{210mm}
   \ifdim\paperwidth=\@tempdima
      \setlength{\@tempdima}{297mm}
      \ifdim\paperheight=\@tempdima
         \def\TwoUp@info{-pa4 -Pa5}
      \fi
   \fi
\fi
%    \end{macrocode}
% If \verb:\TwoUp@info: is still undefined, we give up and use the
% \verb:-w: and \verb:-h: options to psnup.\footnote{We could of
% course have used the \texttt{-w} and \texttt{-h} options also for
% a4, letter, and legal sized paper, but the psnup command line
% looks a lot prettier with a \texttt{-pa4}, \texttt{-pletter}, or
% \texttt{-plegal} option.}
%    \begin{macrocode}
\ifx\TwoUp@info\undefined
   \PackageWarningNoLine{twoup}{Unknown paper size.
      You may want to use a \MessageBreak
      paper size option like letterpaper}
%    \end{macrocode}
% \TeX\ displays \verb:\the\paperwidth: as however many \emph{pt},
% by which \TeX\ means traditional points; one inch is $72.27$\,pt.
% However, psnup expects the paper width as so-and-so many
% \emph{pt}, by which psnup means postscript points, the unit \TeX\
% calls \emph{bp}, or big points; one inch is $72$\,bp.  To overcome
% this confusion, we must multiply by $\frac{72}{72.27}$ or
% $0.99627$.
%    \begin{macrocode}
   \setlength{\@tempdima}{0.99627\paperwidth}
%    \end{macrocode}
% The \verb:\@settopoint: command rounds (down) to an integer.
% Rounding causes the psnup command line to be slightly wrong but
% less ugly.
%    \begin{macrocode}
   \@settopoint\@tempdima
%    \end{macrocode}
% Then record the information in \verb:\TwoUp@info:.  The psnup
% syntax for the output paper size is \verb:-w:\meta{width}
% \verb:-h:\meta{height}.
%    \begin{macrocode}
   \edef\TwoUp@info{-w\the\@tempdima}
%    \end{macrocode}
% Record the paper height in the same manner.
%    \begin{macrocode}
   \setlength{\@tempdima}{0.99627\paperheight}
   \@settopoint\@tempdima
   \edef\TwoUp@info{\TwoUp@info\space -h\the\@tempdima}
%    \end{macrocode}
% Then add the input paper size to the list of psnup options. The
% syntax for the input paper size is \verb:-W:\meta{width}
% \verb:-H:\meta{height}. As before, we must correct for the
% confusion between traditional and postscript points.
%    \begin{macrocode}
   \setlength{\@tempdima}{0.5\paperheight}
   \setlength{\@tempdima}{0.99627\@tempdima}
   \@settopoint\@tempdima
   \edef\TwoUp@info{\TwoUp@info\space -W\the\@tempdima}
   \setlength{\@tempdima}{0.99627\paperwidth}
   \@settopoint\@tempdima
   \edef\TwoUp@info{\TwoUp@info\space -H\the\@tempdima}
\fi
%    \end{macrocode}
% \end{macro}
%
% The advise on psnup options is ready; now we must decide whether
% to use it.  But first change the paper size:  swap the width and
% the height; then divide the new width by two.
%    \begin{macrocode}
\setlength{\@tempdima}{\paperwidth}
\setlength{\paperwidth}{0.5\paperheight}
\setlength{\paperheight}{\@tempdima}
%    \end{macrocode}
% If either the \textsf{2up} or \textsf{booklet} package is loaded,
% ignore the psnup advise and issue suitable \verb:\source: and
% \verb:\target: commands---both \textsf{2up} and \textsf{booklet}
% define \verb:\source: and \verb:\target:.
%    \begin{macrocode}
\@ifpackageloaded{2up}{%
   \source{\magstep0}{\paperwidth}{\paperheight}%
   \target{\magstep0}{2\paperwidth}{\paperheight}%
}{%
\@ifpackageloaded{booklet}{%
   \source{\magstep0}{\paperwidth}{\paperheight}%
   \target{\magstep0}{2\paperwidth}{\paperheight}%
}{%
%    \end{macrocode}
% Otherwise we are going the postscript route.  Record the new
% smaller paper size in the postscript file by placing a suitable
% \verb:\special: command in the .dvi file.
%    \begin{macrocode}
   \TwoUp@special
%    \end{macrocode}
% Then have the psnup advise presented at the end of the \LaTeX\
% run. Using \verb:\PackageInfo: would have been natural, but I want
% the advise to appear on the screen (as well as in the .log file);
% also the psnup command line is rather long, so we need \emph{ad
% hoc} formatting.
%    \begin{macrocode}
   \AtEndDocument{\typeout{^^J%
      Package twoup Info: Use psnup with these options:^^J%
      psnup \TwoUp@info\space -2 \jobname.ps twoup.ps^^J}}
%    \end{macrocode}
% If we had an explicit paper size option (indicating that we are to
% print on a paper size other than the default), \verb:\TwoUp@paper:
% is defined and we can give advise on editing the postscript file.
%    \begin{macrocode}
   \ifx\TwoUp@paper\undefined\else
      \AtEndDocument{\typeout{^^J%
         Package twoup Info: You may have to add these
         three lines to your .ps file:^^J%
         \@percentchar\@percentchar BeginPaperSize: \TwoUp@paper^^J%
         \TwoUp@paper^^J%
         \@percentchar\@percentchar EndPaperSize^^J}}
   \fi%
}}%
%    \end{macrocode}
%
% \subsubsection{Text Width and Horizontal Margins}
% The standard \LaTeX\ classes~\cite{ltclass} ensure that the line
% length is not too large for comfortable reading.  For two-up
% printing on \texttt{letterpaper}, \texttt{a4paper}, or smaller,
% that is a non-issue. However, \texttt{legalpaper} does leave room
% for oversized lines.\footnote{Up to 25\% ``too large.''} If I
% leave the line length ``small,'' the layout of the two-up printed
% page looks odd.  I therefore allow the oversized lines.  The user
% should consider using \texttt{twocolumn} mode or---better---the
% \textsf{multicol} package.
%
% I think that a total horizontal margin of one inch looks
% fine.\footnote{Fine enough to just leave room (in \texttt{oneside}
% mode) for the numbers added by the \textsf{lineno} package.}  The
% \verb:\textwidth: is then what is left of the \verb:\paperwidth:.
%    \begin{macrocode}
\setlength{\@tempdima}{1in}
\setlength{\textwidth}{\paperwidth}
\addtolength{\textwidth}{-\@tempdima}
%    \end{macrocode}
% If we are printing in \texttt{twoside} mode, the inner margin
% should be larger than the outer margin.  A ratio of about $1:2$
% looks fine.  The outer margin is then what is left of the total
% horizontal margin.
%    \begin{macrocode}
\if@twoside
   \setlength{\evensidemargin}{0.33\@tempdima}
   \setlength{\oddsidemargin}{\@tempdima}
   \addtolength{\oddsidemargin}{-\evensidemargin}
\else
%    \end{macrocode}
% In \texttt{oneside} mode, simply split the margins even.
%    \begin{macrocode}
   \setlength{\oddsidemargin}{0.5\@tempdima}
   \setlength{\evensidemargin}{\oddsidemargin}
\fi
%    \end{macrocode}
%
% So far we have ignored that the ``real'' left margin is
% \verb:1 inch:${}+{}$\verb:\hoffset:${}+{}$\verb:\oddsidemargin:
% (or \verb:\evensidemargin:).  We must subtract that inch.
%    \begin{macrocode}
\addtolength{\oddsidemargin}{-1in}
\addtolength{\evensidemargin}{-1in}
%    \end{macrocode}
%
% \subsubsection{Text Height and Vertical Margins}
% A top margin of half an inch looks good to me.  As a first
% approximation for the text height, simply subtract all the header
% and footer stuff from the paper height.  (Subtract
% \verb:\topmargin: twice for the sake of the bottom margin.)
%    \begin{macrocode}
\setlength{\topmargin}{0.5in}
\setlength{\textheight}{\paperheight}
\addtolength{\textheight}{-2\topmargin}
\addtolength{\textheight}{-\headheight}
\addtolength{\textheight}{-\headsep}
\addtolength{\textheight}{-\footskip}
%    \end{macrocode}
%
% The text height must then be corrected to fit an integer number of
% lines. The first line has height \verb:\topskip: while all other
% lines have height \verb:\baselineskip:.  Thus subtract
% \verb:\topskip: and divide by \verb:\baselineskip:.
%    \begin{macrocode}
\addtolength{\textheight}{-\topskip}
\divide\textheight\baselineskip
%    \end{macrocode}
% The \verb:\divide: command performs integer division, so
% \verb:\textheight: is now \meta{number of lines}\,sp.  Store the
% result in a counter to get a \emph{bona fide} number.
%    \begin{macrocode}
\@tempcnta\textheight
%    \end{macrocode}
% Now we can calculate the text height: the correct number of
% \verb:\baselineskip:s plus a \verb:\topskip: for the first line.
%    \begin{macrocode}
\setlength{\textheight}{\@tempcnta\baselineskip}
\addtolength{\textheight}{\topskip}
%    \end{macrocode}
%
% Again, the ``real'' top margin is
% \verb:1 inch:${}+{}$\verb:\voffset:${}+{}$\verb:\topmargin:,
% so subtract one inch from \verb:\topmargin:.
%    \begin{macrocode}
\addtolength{\topmargin}{-1in}
%    \end{macrocode}
%
% \begin{macro}{\cleartolastpage}
% The \verb:\cleartolastpage: command clears the page, checks for a
% star, prepares to issue a suitable \verb:\thispagestyle: command,
% and passes control to \verb:\cleartolastp@ge:.
%    \begin{macrocode}
\newcommand{\cleartolastpage}{%
   \clearpage
   \@ifstar
      {\def\TwoUp@blankpagestyle{\thispagestyle{empty}}\cleartolastp@ge}
      {\let\TwoUp@blankpagestyle\relax\cleartolastp@ge}}
%    \end{macrocode}
% The \verb:\cleartolastp@ge: command stores the first optional
% argument, \meta{div}, in the temporary counter \verb:\@tempcnta:
% with a default that depends on the \verb:twoside: class option.
%    \begin{macrocode}
\if@twoside
   \newcommand{\cleartolastp@ge}[1][4]{%
      \@tempcnta#1\relax
      \cleartol@stp@ge}%
\else
   \newcommand{\cleartolastp@ge}[1][2]{%
      \@tempcnta#1\relax
      \cleartol@stp@ge}%
\fi
%    \end{macrocode}
% The \verb:\cleartol@stp@ge: command does the real work: store a
% copy of the page number, \verb:\c@page:, in a temporary counter,
% divide and multiply by \meta{div} to round down to a multiple of
% \meta{div}, and add \meta{rem}.
%    \begin{macrocode}
\newcommand{\cleartol@stp@ge}[1][0]{%
   \@tempcntb\c@page
   \divide\@tempcntb\@tempcnta
   \multiply\@tempcntb\@tempcnta
   \advance\@tempcntb#1\relax
%    \end{macrocode}
% Now \verb:\@tempcntb: leaves remainder \meta{rem} when divided by
% \meta{div}, but it may still be smaller than the page number.  If
% so, add \meta{div} to get the next number that leaves the same
% remainder.
%    \begin{macrocode}
   \ifnum\@tempcntb<\c@page
      \advance\@tempcntb\@tempcnta
   \fi
%    \end{macrocode}
% Now \verb:\@\tempcntb: is the page number we want to reach.
%    \begin{macrocode}
   \loop\ifnum\c@page<\@tempcntb
      \hbox{}\TwoUp@blankpagestyle\newpage
   \repeat
}
%</package>
%    \end{macrocode}
% \end{macro}
% \Finale