Debian Codegraph @

texmf-dist/source/latex/twoup/twoup.dtx

raw
1 % \iffalse
2 %<*docdriver>
3 \documentclass{ltxdoc}[1996/01/11]
4 \begin{filecontents}{twoup.ins}
5 % The twoup package, version 1.3
6 \input docstrip.tex
7 \preamble
8
9 m This is the twoup package
10 o Copyright 2005-07 by Mogens Lemvig Hansen,
11 g Please find my e-mail address in the left margin
12 e
13 n Run twoup.dtx through LaTeX and read the documentation in twoup.dvi
14 s
15 @ This work may be distributed and/or modified under the
16 k conditions of the LaTeX Project Public License, either version 1.3
17 a of this license or (at your option) any later version.
18 y The latest version of this license is in
19 j http://www.latex-project.org/lppl.txt
20 u and version 1.3 or later is part of all distributions of LaTeX
21 . version 2005/12/01 or later.
22 c
23 o This work has the LPPL maintenance status 'maintained'.
24 m
25 The Current Maintainer of this work is Mogens Lemvig Hansen.
26
27 This work consists of the files twoup.dtx and twoup.ins
28 and the derived file twoup.sty.
29
30 \endpreamble
31 % I think that \path:twoup.sty: should go into the directory
32 % \path:tex/latex/misc:; however, \textsc{DocStrip} will not heed my advise
33 % unless your configuration file, \path:docstrip.cfg:, allows it to.
34 \usedir{tex/latex/misc}
35 \generate{\file{twoup.sty}{\from{twoup.dtx}{package}}}
36 \endbatchfile
37 \end{filecontents}
38 \usepackage{url,randtext}
39 \InputIfFileExists{../myemail}{}{%
40 \def\myemail{See top of .sty file for e-mail address}}
41 %\discretionaries |~!@$%^&*()_+`=#{"}[]:;'<>,.?\/|
42 %\CodelineIndex%\EnableCrossrefs
43 \makeatletter
44 \newcommand{\nextlinelabel}[2][1]{\@bsphack
45 \@tempcnta\c@CodelineNo
46 \advance\@tempcnta#1\relax
47 \def\@currentlabel{\the\@tempcnta}\label{#2}%
48 \@esphack}
49 \makeatother
50 \begin{document} \DocInput{twoup.dtx} \end{document}
51 %</docdriver>
52 % \fi
53 % \CheckSum{324}
54 % \CharacterTable
55 % {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
56 % 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
57 % Digits \0\1\2\3\4\5\6\7\8\9
58 % Exclamation \! Double quote \" Hash (number) \#
59 % Dollar \$ Percent \% Ampersand \&
60 % Acute accent \' Left paren \( Right paren \)
61 % Asterisk \* Plus \+ Comma \,
62 % Minus \- Point \. Solidus \/
63 % Colon \: Semicolon \; Less than \<
64 % Equals \= Greater than \> Question mark \?
65 % Commercial at \@ Left bracket \[ Backslash \\
66 % Right bracket \] Circumflex \^ Underscore \_
67 % Grave accent \` Left brace \{ Vertical bar \|
68 % Right brace \} Tilde \~}
69 %
70 % \def\fileversion{1.3} \def\filedate{2007/02/26} \def\docdate{\filedate}
71 % \title{The \textsf{twoup} Package\thanks{This file describes version
72 % \fileversion, \filedate.}}
73 % \author{\copyright\ Mogens Lemvig Hansen\thanks{%
74 % The \textsf{twoup} package is distributed under the \LaTeX\ Project
75 % Public License; please see Section~\ref{sec:license}.}\\
76 % \myemail}
77 % \date{\docdate}
78 % \maketitle
79 % \begin{abstract}
80 % The \textsf{twoup} assists in two-up or booklet printing
81 % using the \textsf{2up} or \textsf{booklet} packages
82 % or using the psnup program and friends.
83 % \end{abstract}
84 %
85 % \tableofcontents\bigskip
86 %
87 % I am familiar with three ways of producing two-up
88 % documents\footnote{That is, printing two logical pages side by
89 % side on one side of one sheet of paper.} and
90 % booklets:\footnote{That is, rearranging the logical pages before
91 % printing them two-up on both sides of the paper in such a manner
92 % that the resulting sheets of paper can be folded down the middle
93 % into a small book.} the \textsf{2up} package, the \textsf{booklet}
94 % package, and the postscript tool psnup.
95 % The \textsf{2up} and \textsf{booklet} packages are both available
96 % from CTAN, and psnup is included with many \TeX\ distributions
97 % including MiK\TeX. All three will by default
98 % accomplish this task by scaling the page down. However, a one-up
99 % page layout does not necessarily work well when scaled. The
100 % \textsf{twoup} package provides a page layout designed for two-up
101 % printing and sets the relevant \textsf{2up} or \textsf{booklet}
102 % parameters or gives advise on how to use the postscript tools.
103 %
104 % \section{Usage}
105 % Give the paper size you intend to print on as an option to
106 % \verb:\documentclass:.\footnote{If you intend to print on your
107 % default paper size, you do not have to give any paper size
108 % option.} The \textsf{twoup} package re-calculates the paper size
109 % and margins for two-up printing.\footnote{If you print on
110 % \texttt{a4paper}, \textsf{twoup} calculates the same paper size as
111 % the \texttt{a5paper} option but with different (smaller) margins.
112 % You may consider this discrepancy either a bug or a feature.}
113 % Then choose the method:
114 %
115 % \subsection{Plain two-up with the \textsf{2up} package}
116 % Load the \textsf{2up} package \emph{before} the \textsf{twoup}
117 % package.
118 % \begin{quote}
119 % \verb:\documentclass[a4paper,12pt]{article}:\\
120 % \verb:\usepackage{2up}:\\
121 % \verb:\usepackage{twoup}:
122 % \end{quote}
123 %
124 % Unfortunately cross references may not work out under the
125 % \textsf{2up} package. The solution is, as explained in the
126 % \textsf{2up} documentation, to comment out the
127 % \verb:\usepackage{2up}: line, run your .tex file through \LaTeX\
128 % until all references work out, then load \textsf{2up} again and run
129 % your document through \LaTeX\ once (an only once).
130 %
131 % \subsection{Booklets with the \textsf{booklet} package}
132 % Load the \textsf{booklet} package \emph{before} the \textsf{twoup}
133 % package.
134 % \begin{quote}
135 % \verb:\documentclass[letterpaper,12pt]{article}:\\
136 % \verb:\usepackage[print]{booklet}:\\
137 % \verb:\usepackage{twoup}:
138 % \end{quote}
139 % Without the \verb:print: option, the \textsf{booklet} package does
140 % nothing.
141 %
142 % The \textsf{booklet} package has miraculously solved the
143 % cross-reference problem of the \textsf{2up} package but does not
144 % provide a plain two-up option.
145 %
146 % \subsection{Plain two-up with the postscript tools}
147 % Simply load the \textsf{twoup} package.
148 % \begin{quote}
149 % \verb:\documentclass[letterpaper,12pt]{article}:\\
150 % \verb:\usepackage{twoup}:
151 % \end{quote}
152 % When you run your .tex file through \LaTeX, the \textsf{twoup}
153 % package will tell you which options to use with the psnup program;
154 % look for the psnup command line near the end of the
155 % transcript.\footnote{Both on screen and in the .log file.} If you
156 % give a paper size option, the \textsf{twoup} package will also
157 % tell you which lines you will have to add to your postscript file
158 % by hand.
159 %
160 % Run the .dvi file through dvips\footnote{The current version of
161 % the \textsf{twoup} package requires that you use dvips. If you
162 % want to use some other .dvi-to-postscript program, please see code
163 % line~\ref{line:dvips} and the commentary around it.} to make a
164 % postscript file.
165 % \begin{quote}
166 % \verb:dvips: \meta{file}
167 % \end{quote}
168 %
169 % Then run psnup with the options that the \textsf{twoup} package
170 % gave you above. Even Win95 allows you to cut-and-paste the
171 % command line which could look something like this:
172 % \begin{quote}
173 % \verb:psnup: \verb:-pletter: \verb:-W396.0pt: \verb:-H612.0pt:
174 % \verb:-2: \meta{file}\verb:.ps: \meta{twoup}\verb:.ps:
175 % \end{quote}
176 %
177 % The postscript file, \meta{twoup}\verb:.ps:, has by now lost all
178 % consciousness of which paper size it is to be printed on. If you
179 % are about to print on your printer's default paper size, that is
180 % no problem. To print on any other paper size you most likely have
181 % to place a paper size command in \meta{twoup}\verb:.ps:. With a
182 % plain text editor add the lines \textsf{twoup} gave you in the
183 % \LaTeX\ run to \meta{twoup}\verb:.ps:. The lines to add could look
184 % like this:
185 % \begin{quote}
186 % \verb;%%BeginPaperSize: letter;\\
187 % \verb;letter;\\
188 % \verb;%%EndPaperSize;
189 % \end{quote}
190 % Place the new lines just after the
191 % \verb:%%EndComments: line near the top of \meta{twoup}\verb:.ps:.
192 %
193 % \subsection{Booklets with the postscript tools}
194 % The \LaTeX\ side of making booklets is much like simple two-up.
195 % You may want to use the \texttt{twoside} option to
196 % \verb:\documentclass: to make the inner margins a bit larger etc.
197 % \begin{quote}
198 % \verb:\documentclass[a4paper,11pt,twoside]{article}:\\
199 % \verb:\usepackage{twoup}:
200 % \end{quote}
201 % As above, the \textsf{twoup} package will advise you on which
202 % options to use with the psnup program. Run your .dvi file through
203 % dvips:
204 % \begin{quote}
205 % \verb:dvips: \meta{file}
206 % \end{quote}
207 %
208 % Now the fun begins: Before using psnup you must use the psbook
209 % program to fold your postscript file into a signature:
210 % \begin{quote}
211 % \verb:psbook: \meta{file}\verb:.ps: \meta{book}\verb:.ps:
212 % \end{quote}
213 % The number of pages in a signature must be divisible by four, so
214 % psbook may add a few blank pages to the end of your booklet. Run
215 % the result through psnup with the options the \textsf{twoup}
216 % package calculated in the \LaTeX\ run. The command line could look
217 % something like this:\footnote{Under Unix, you can pipe the psbook
218 % and psnup commands together; Windows, however, does not like long
219 % command lines.}
220 % \begin{quote}
221 % \verb:psnup: \verb:-pa4: \verb:-Pa5:
222 % \verb:-2: \meta{book}\verb:.ps: \meta{twoup}\verb:.ps:
223 % \end{quote}
224 %
225 % Unless you are about to print on your printer's default paper
226 % size, add the paper size command to \meta{twoup}\verb:.ps: as
227 % above.
228 %
229 % You can print your postscript file, \meta{twoup}\verb:.ps:, now,
230 % but if you want to print double sided, you may have to split the
231 % file in two with the psselect program:
232 % \begin{quote}
233 % \verb:psselect: \verb:-o: \meta{twoup}\verb:.ps:
234 % \meta{odd}\verb:.ps:\\
235 % \verb:psselect: \verb:-e:
236 % \meta{twoup}\verb:.ps: \meta{even}\verb:.ps:
237 % \end{quote}
238 % Then print \meta{odd}\verb:.ps:, turn the paper over, and print
239 % \meta{even}\verb:.ps:.\footnote{Depending on your printer, you may
240 % want to use psselect's \texttt{-r} option to print the \meta{even}
241 % pages in reverse order.}
242 %
243 % \subsection{Options}
244 % By default the \textsf{twoup} package leaves room for running
245 % headers and footers. Use the \texttt{noheadfoot},
246 % \texttt{nofoot}, or \texttt{nohead} option to reclaim that space.
247 % As a side efect, these options set the page style:
248 % \texttt{noheadfoot} implies the \texttt{empty} page style,
249 % \texttt{nofoot} implies the \texttt{headings} page style, and
250 % \texttt{nohead} implies the \texttt{plain} page style. Moreover,
251 % the \texttt{nofoot} and \texttt{noheadfoot} options disable the
252 % \texttt{plain} page style\footnote{By making \texttt{plain}
253 % synonymous with the \texttt{empty} style.} to prevent the
254 % \verb:\chapter: command from inserting a
255 % \verb:\thispagestyle{plain}: command.
256 %
257 % The \textsf{twoup} package knows the standard paper size options:
258 % \texttt{letterpaper}, \texttt{legalpaper},
259 % \texttt{executivepaper}, \texttt{a4paper}, \texttt{a5paper}, and
260 % \texttt{b5paper}. You should use these options as global options
261 % to \verb:\documentclass:. If you print two-up on
262 % \texttt{legalpaper}, the text width is larger than what is
263 % considered comfortable. You should use the \texttt{twocolumn}
264 % option to \verb:\documentclass: or, better, the \textsf{multicol}
265 % package.
266 %
267 % If you use \textsf{twoup} without \textsf{2up} or
268 % \textsf{booklet}, then the \textsf{twoup} package will insert a
269 % paper-size \verb:\special: in your .dvi file. Use the
270 % \verb:nospecial: option to suppress this.
271 %
272 % \subsection{Additional commands}%
273 % \DescribeMacro{\cleartolastpage}%
274 % If you are making a booklet, the number of pages must be divisible
275 % by four; indeed, the \textsf{booklet} package or the psbook
276 % program will add blank pages as necessary. If, however, you want
277 % to print on the last page, the back of your booklet, you can use
278 % the \verb:\cleartolastpage: command in a \verb:twosided: context
279 % to (print all pending tables, figures, and footnotes and) insert
280 % as many blank pages as necessary to reach a page number divisible
281 % by four. In detail,
282 % \begin{quote}
283 % \verb:\cleartolastpage:\oarg{div}\oarg{rem}\\
284 % \verb:\cleartolastpage*:\oarg{div}\oarg{rem}
285 % \end{quote}
286 % both print all pending floats and insert blank pages until the
287 % page number leaves remainder \meta{rem} when divided by
288 % \meta{div}. The default value of \meta{rem} is~$0$, and the
289 % default value of \meta{div} is~$4$ under the \verb:twosided: class
290 % option and $2$ otherwise. The starred version suppresses the
291 % printing of page numbers on the inserted blank pages.
292 %
293 % Thus \verb:\cleartolastpage[1]: is equivalent to \LaTeX's
294 % \verb:\clearpage: command
295 % and \verb:\cleartolastpage[2][1]: is equivalent to
296 % \verb:\cleardoublepage:.
297 %
298 % The \verb:\cleartolastpage: command may fail to put you one the
299 % last page if page~$1$ is not the very first page (maybe because
300 % you have differently numbered front matter); use the optional
301 % \meta{rem} argument to overcome this.
302 %
303 %
304 % \section{Installation}
305 % As you must have figured, you generate the documentation for the
306 % \textsf{twoup} package by running the file \url:twoup.dtx: through
307 % \LaTeX---thrice to resolve cross references.
308 %
309 % To extract the package itself from the .dtx file, run
310 % \url:twoup.ins: through \LaTeX:
311 % \begin{quote}
312 % \verb:latex twoup.ins:
313 % \end{quote}
314 % You now have to decide what to do with several files.
315 % \begin{itemize}
316 % \item You may have to move the file \url:twoup.sty: to some
317 % directory where \LaTeX\ can find it;
318 % \url:(local)texmf/tex/latex/misc: would be the natural
319 % choice~\cite{tds}.
320 %
321 % \item Move the documentation, \url:twoup.dvi: or \url:twoup.pdf:,
322 % to \url:(local)texmf/doc/latex/misc:.
323 %
324 % \item You may discard the source files, \url:twoup.dtx: and
325 % \url:twoup.ins:, or store them in
326 % \url:(local)texmf/source/latex/misc:.
327 %
328 % \item Discard all remaining \url:twoup.*: files.
329 % \end{itemize}
330 %
331 %
332 % \section{Limitations}
333 % The \textsf{twoup} package is designed for and tested on
334 % \texttt{letterpaper}, \texttt{legalpaper}, and \texttt{a4paper}.
335 % Printing two-up on smaller paper is hardly feasible; printing on
336 % larger paper is beyond the normal desktop printer.
337 %
338 % The margins calculated by \textsf{twoup} are too small for
339 % \verb:\marginpar:s.\footnote{But just large enough for the line
340 % numbers inserted by the \textsf{lineno} package.}
341 %
342 % If you print two-up on \texttt{legalpaper}, \textsf{twoup} leaves
343 % a text width larger than what is considered comfortable. You
344 % should use the \texttt{twocolumn} option to \verb:\documentclass:
345 % or, better, the \textsf{multicol} package.
346 %
347 % The \textsf{twoup} package is not compatible with the
348 % \textsf{geometry} package. Both packages re-calculate the margins
349 % and the disagree on the interpretation of the paper size options.
350 %
351 % I know very little about postscript, yet I tell you to go add
352 % lines to .ps files. The advise \textsf{twoup} gives has always
353 % worked for me; if it doesn't work for you, please teach me the
354 % correct way.
355 %
356 % The current implementation of \textsf{twoup} requires dvips
357 % (unless you use the \textsf{2up} or \textsf{booklet} packages).
358 % This limitation is easily overcome with your help: please see code
359 % line~\ref{line:dvips} and the commentary around it.
360 %
361 %
362 % \section{License}\label{sec:license}
363 % This work may be distributed and/or modified under the
364 % conditions of the \LaTeX\ Project Public License, either version 1.3
365 % of this license or (at your option) any later version.
366 % The latest version of this license is in
367 % \url{http://www.latex-project.org/lppl.txt}
368 % and version 1.3 or later is part of all distributions of \LaTeX\
369 % version 2005/12/01 or later.
370 %
371 % This work has the LPPL maintenance status `maintained.'
372 %
373 % The Current Maintainer of this work is Mogens Lemvig Hansen.
374 %
375 % This work consists of the files \url{twoup.dtx} and \url{twoup.ins}
376 % and the derived file \url{twoup.sty}.
377 %
378 %
379 % \StopEventually{
380 % \nocite{ltclass}
381 % \bibliographystyle{is-plain}
382 % ^^A\bibliography{tex}
383 % \begin{thebibliography}{1}
384 %
385 % \bibitem{ltclass}
386 % Leslie Lamport, Frank Mittelbach, and Johannes Braams.
387 % \newblock {\em Standard Document Classes for \LaTeX\ version 2e}.
388 % \newblock CTAN, 1999/09/10 edition, 1999.
389 %
390 % \bibitem{tds}
391 % {TUG Working Group on a {\TeX} Directory Structure (TWG-TDS)}.
392 % \newblock {\em A Directory Structure for {\TeX} Files}.
393 % \newblock CTAN, version 0.9995, January 26, 1998 edition, 1998.
394 %
395 % \end{thebibliography}
396 % }
397 %
398 % \section{Implementation}
399 % The \textsf{twoup} package doesn't have to do much---just
400 % re-calculate the paper size and the margins and put together the
401 % advise on how to use the psnup program. The \textsf{twoup} package
402 % does its thing based on the plain \LaTeX\ parameters
403 % \verb:\paperwidth:, \verb:\paperheight:, \verb:\headheight:,
404 % \verb:\headsep:, \verb:\footskip:, \verb:\topskip:, and
405 % \verb:\baselineskip:.
406 %
407 % \subsection{Identification}
408 % \begin{macrocode}
409 %<*package>
410 \NeedsTeXFormat{LaTeX2e}%
411 \ProvidesPackage{twoup}[2007/02/26 version 1.3]
412 % \end{macrocode}
413 %
414 % \subsection{Declaration of Options}
415 % The \texttt{noheadfoot} option sets the relevant lenghts to zero.
416 % Since there is no room for headers or footers, the only sensible
417 % page style is \texttt{empty}. The \verb:\chapter: command issues
418 % a \verb:\thispagestyle{plain}: command, so re-define the
419 % \texttt{plain} style to be a synonym for the \texttt{empty}
420 % style.\footnote{I borrowed the idea of brutally making
421 % \texttt{plain} a synonym for \texttt{empty} from David Carlisle's
422 % \textsf{nopageno} package.}
423 % \begin{macrocode}
424 \DeclareOption{noheadfoot}{%
425 \setlength{\headheight}{0pt}%
426 \setlength{\headsep}{0pt}%
427 \setlength{\footskip}{0pt}%
428 \let\ps@plain\ps@empty
429 \pagestyle{empty}}
430 % \end{macrocode}
431 % With room for a header but without a footer the most sensible page
432 % style would be \texttt{headings}. Again the \texttt{plain} page
433 % style must be disabled.
434 % \begin{macrocode}
435 \DeclareOption{nofoot}{%
436 \setlength{\footskip}{0pt}%
437 \let\ps@plain\ps@empty
438 \pagestyle{headings}}
439 % \end{macrocode}
440 % With room for a footer but no header the most sensible page style
441 % is \texttt{plain}---so don't change \texttt{plain}.
442 % \begin{macrocode}
443 \DeclareOption{nohead}{%
444 \setlength{\headheight}{0pt}%
445 \setlength{\headsep}{0pt}%
446 \pagestyle{plain}}
447 % \end{macrocode}
448 %
449 % \begin{macro}{\TwoUp@info}
450 % \begin{macro}{\TwoUp@paper}
451 % The paper size options record part of the advise on how to use the
452 % psnup program in \verb:\TwoUp@info: and part of the advise on how
453 % to edit the final postscript file in \verb:\TwoUp@paper:.
454 % \begin{macrocode}
455 \DeclareOption{letterpaper}{%
456 \def\TwoUp@info{-pletter -W5.5in -H8.5in}%
457 \def\TwoUp@paper{letter}}%
458 \DeclareOption{legalpaper}{%
459 \def\TwoUp@info{-plegal -W7in -H8.5in}%
460 \def\TwoUp@paper{legal}}%
461 \DeclareOption{executivepaper}{%
462 \def\TwoUp@info{-pexecutive -W5.25in -H7.25in}%
463 \def\TwoUp@paper{executive}}%
464 \DeclareOption{a4paper}{%
465 \def\TwoUp@info{-pa4 -Pa5}%
466 \def\TwoUp@paper{a4}}%
467 \DeclareOption{a5paper}{%
468 \def\TwoUp@info{-pa5 -W105mm -H148mm}%
469 \def\TwoUp@paper{a5}}%
470 \DeclareOption{b5paper}{%
471 \def\TwoUp@info{-pb5 -W125mm -H176mm}%
472 \def\TwoUp@paper{b5}}%
473 % \end{macrocode}
474 % \end{macro}\end{macro}
475 %
476 % \begin{macro}{\TwoUp@special}
477 % The \textsf{twoup} package needs to record the (smaller) paper
478 % size in the postscript file. That means placing a suitable
479 % \verb:\special: command in the .dvi file. Unfortunately,
480 % ``suitable'' depends on which .dvi-to-postscript program you use,
481 % so we need an option for each such program. I have implemented
482 % the option for dvips but was too lazy to figure out the
483 % appropriate command for other .dvi-to-postscript
484 % programs.\nextlinelabel[2]{line:dvips}
485 % \begin{macrocode}
486 \DeclareOption{dvips}{%
487 \def\TwoUp@special{%
488 \special{papersize=\the\paperwidth,\the\paperheight}}}
489 % \end{macrocode}
490 % If you need to use the \textsf{twoup} package with another
491 % postscript driver, please let me know so I can incorporate more
492 % options in future releases of \textsf{twoup}. While you wait for
493 % that, use the \texttt{nospecial} option to suppress the
494 % \verb:\special:.
495 % \begin{macrocode}
496 \DeclareOption{nospecial}{%
497 \def\TwoUp@special{\relax}}
498 % \end{macrocode}
499 % \end{macro}
500 %
501 % \subsection{Execution of Options}
502 % Default to dvips leaving space for headers and footer as the class
503 % sees fit.
504 % \begin{macrocode}
505 \ExecuteOptions{dvips}
506 \ProcessOptions
507 % \end{macrocode}
508 %
509 % \subsection{Main Code}
510 % \subsubsection{Paper Size and psnup Advise}
511 % \begin{macro}{\TwoUp@info}
512 % Before re-calculating the paper size, we must record part of the
513 % psnup advise. If a paper size option did that already, all is
514 % fine. Otherwise we must be printing on the default paper size
515 % which we must then determine. We will try to recognize the most
516 % common default paper sizes: a4, letter, and legal. Since this is
517 % the default paper size, we may assume that the printer knows how
518 % to handle it. We therefore suppress the advise on editing the
519 % final postscript file by \emph{not} defining \verb:\TwoUp@paper:.
520 % \begin{macrocode}
521 \ifx\TwoUp@info\undefined
522 \setlength{\@tempdima}{8.5in}
523 \ifdim\paperwidth=\@tempdima
524 \setlength{\@tempdima}{11in}
525 \ifdim\paperheight=\@tempdima
526 \def\TwoUp@info{-pletter -W5.5in -H8.5in}
527 \fi
528 \setlength{\@tempdima}{14in}
529 \ifdim\paperheight=\@tempdima
530 \def\TwoUp@info{-plegal -W7in -H8.5in}
531 \fi
532 \fi
533 \setlength{\@tempdima}{210mm}
534 \ifdim\paperwidth=\@tempdima
535 \setlength{\@tempdima}{297mm}
536 \ifdim\paperheight=\@tempdima
537 \def\TwoUp@info{-pa4 -Pa5}
538 \fi
539 \fi
540 \fi
541 % \end{macrocode}
542 % If \verb:\TwoUp@info: is still undefined, we give up and use the
543 % \verb:-w: and \verb:-h: options to psnup.\footnote{We could of
544 % course have used the \texttt{-w} and \texttt{-h} options also for
545 % a4, letter, and legal sized paper, but the psnup command line
546 % looks a lot prettier with a \texttt{-pa4}, \texttt{-pletter}, or
547 % \texttt{-plegal} option.}
548 % \begin{macrocode}
549 \ifx\TwoUp@info\undefined
550 \PackageWarningNoLine{twoup}{Unknown paper size.
551 You may want to use a \MessageBreak
552 paper size option like letterpaper}
553 % \end{macrocode}
554 % \TeX\ displays \verb:\the\paperwidth: as however many \emph{pt},
555 % by which \TeX\ means traditional points; one inch is $72.27$\,pt.
556 % However, psnup expects the paper width as so-and-so many
557 % \emph{pt}, by which psnup means postscript points, the unit \TeX\
558 % calls \emph{bp}, or big points; one inch is $72$\,bp. To overcome
559 % this confusion, we must multiply by $\frac{72}{72.27}$ or
560 % $0.99627$.
561 % \begin{macrocode}
562 \setlength{\@tempdima}{0.99627\paperwidth}
563 % \end{macrocode}
564 % The \verb:\@settopoint: command rounds (down) to an integer.
565 % Rounding causes the psnup command line to be slightly wrong but
566 % less ugly.
567 % \begin{macrocode}
568 \@settopoint\@tempdima
569 % \end{macrocode}
570 % Then record the information in \verb:\TwoUp@info:. The psnup
571 % syntax for the output paper size is \verb:-w:\meta{width}
572 % \verb:-h:\meta{height}.
573 % \begin{macrocode}
574 \edef\TwoUp@info{-w\the\@tempdima}
575 % \end{macrocode}
576 % Record the paper height in the same manner.
577 % \begin{macrocode}
578 \setlength{\@tempdima}{0.99627\paperheight}
579 \@settopoint\@tempdima
580 \edef\TwoUp@info{\TwoUp@info\space -h\the\@tempdima}
581 % \end{macrocode}
582 % Then add the input paper size to the list of psnup options. The
583 % syntax for the input paper size is \verb:-W:\meta{width}
584 % \verb:-H:\meta{height}. As before, we must correct for the
585 % confusion between traditional and postscript points.
586 % \begin{macrocode}
587 \setlength{\@tempdima}{0.5\paperheight}
588 \setlength{\@tempdima}{0.99627\@tempdima}
589 \@settopoint\@tempdima
590 \edef\TwoUp@info{\TwoUp@info\space -W\the\@tempdima}
591 \setlength{\@tempdima}{0.99627\paperwidth}
592 \@settopoint\@tempdima
593 \edef\TwoUp@info{\TwoUp@info\space -H\the\@tempdima}
594 \fi
595 % \end{macrocode}
596 % \end{macro}
597 %
598 % The advise on psnup options is ready; now we must decide whether
599 % to use it. But first change the paper size: swap the width and
600 % the height; then divide the new width by two.
601 % \begin{macrocode}
602 \setlength{\@tempdima}{\paperwidth}
603 \setlength{\paperwidth}{0.5\paperheight}
604 \setlength{\paperheight}{\@tempdima}
605 % \end{macrocode}
606 % If either the \textsf{2up} or \textsf{booklet} package is loaded,
607 % ignore the psnup advise and issue suitable \verb:\source: and
608 % \verb:\target: commands---both \textsf{2up} and \textsf{booklet}
609 % define \verb:\source: and \verb:\target:.
610 % \begin{macrocode}
611 \@ifpackageloaded{2up}{%
612 \source{\magstep0}{\paperwidth}{\paperheight}%
613 \target{\magstep0}{2\paperwidth}{\paperheight}%
614 }{%
615 \@ifpackageloaded{booklet}{%
616 \source{\magstep0}{\paperwidth}{\paperheight}%
617 \target{\magstep0}{2\paperwidth}{\paperheight}%
618 }{%
619 % \end{macrocode}
620 % Otherwise we are going the postscript route. Record the new
621 % smaller paper size in the postscript file by placing a suitable
622 % \verb:\special: command in the .dvi file.
623 % \begin{macrocode}
624 \TwoUp@special
625 % \end{macrocode}
626 % Then have the psnup advise presented at the end of the \LaTeX\
627 % run. Using \verb:\PackageInfo: would have been natural, but I want
628 % the advise to appear on the screen (as well as in the .log file);
629 % also the psnup command line is rather long, so we need \emph{ad
630 % hoc} formatting.
631 % \begin{macrocode}
632 \AtEndDocument{\typeout{^^J%
633 Package twoup Info: Use psnup with these options:^^J%
634 psnup \TwoUp@info\space -2 \jobname.ps twoup.ps^^J}}
635 % \end{macrocode}
636 % If we had an explicit paper size option (indicating that we are to
637 % print on a paper size other than the default), \verb:\TwoUp@paper:
638 % is defined and we can give advise on editing the postscript file.
639 % \begin{macrocode}
640 \ifx\TwoUp@paper\undefined\else
641 \AtEndDocument{\typeout{^^J%
642 Package twoup Info: You may have to add these
643 three lines to your .ps file:^^J%
644 \@percentchar\@percentchar BeginPaperSize: \TwoUp@paper^^J%
645 \TwoUp@paper^^J%
646 \@percentchar\@percentchar EndPaperSize^^J}}
647 \fi%
648 }}%
649 % \end{macrocode}
650 %
651 % \subsubsection{Text Width and Horizontal Margins}
652 % The standard \LaTeX\ classes~\cite{ltclass} ensure that the line
653 % length is not too large for comfortable reading. For two-up
654 % printing on \texttt{letterpaper}, \texttt{a4paper}, or smaller,
655 % that is a non-issue. However, \texttt{legalpaper} does leave room
656 % for oversized lines.\footnote{Up to 25\% ``too large.''} If I
657 % leave the line length ``small,'' the layout of the two-up printed
658 % page looks odd. I therefore allow the oversized lines. The user
659 % should consider using \texttt{twocolumn} mode or---better---the
660 % \textsf{multicol} package.
661 %
662 % I think that a total horizontal margin of one inch looks
663 % fine.\footnote{Fine enough to just leave room (in \texttt{oneside}
664 % mode) for the numbers added by the \textsf{lineno} package.} The
665 % \verb:\textwidth: is then what is left of the \verb:\paperwidth:.
666 % \begin{macrocode}
667 \setlength{\@tempdima}{1in}
668 \setlength{\textwidth}{\paperwidth}
669 \addtolength{\textwidth}{-\@tempdima}
670 % \end{macrocode}
671 % If we are printing in \texttt{twoside} mode, the inner margin
672 % should be larger than the outer margin. A ratio of about $1:2$
673 % looks fine. The outer margin is then what is left of the total
674 % horizontal margin.
675 % \begin{macrocode}
676 \if@twoside
677 \setlength{\evensidemargin}{0.33\@tempdima}
678 \setlength{\oddsidemargin}{\@tempdima}
679 \addtolength{\oddsidemargin}{-\evensidemargin}
680 \else
681 % \end{macrocode}
682 % In \texttt{oneside} mode, simply split the margins even.
683 % \begin{macrocode}
684 \setlength{\oddsidemargin}{0.5\@tempdima}
685 \setlength{\evensidemargin}{\oddsidemargin}
686 \fi
687 % \end{macrocode}
688 %
689 % So far we have ignored that the ``real'' left margin is
690 % \verb:1 inch:${}+{}$\verb:\hoffset:${}+{}$\verb:\oddsidemargin:
691 % (or \verb:\evensidemargin:). We must subtract that inch.
692 % \begin{macrocode}
693 \addtolength{\oddsidemargin}{-1in}
694 \addtolength{\evensidemargin}{-1in}
695 % \end{macrocode}
696 %
697 % \subsubsection{Text Height and Vertical Margins}
698 % A top margin of half an inch looks good to me. As a first
699 % approximation for the text height, simply subtract all the header
700 % and footer stuff from the paper height. (Subtract
701 % \verb:\topmargin: twice for the sake of the bottom margin.)
702 % \begin{macrocode}
703 \setlength{\topmargin}{0.5in}
704 \setlength{\textheight}{\paperheight}
705 \addtolength{\textheight}{-2\topmargin}
706 \addtolength{\textheight}{-\headheight}
707 \addtolength{\textheight}{-\headsep}
708 \addtolength{\textheight}{-\footskip}
709 % \end{macrocode}
710 %
711 % The text height must then be corrected to fit an integer number of
712 % lines. The first line has height \verb:\topskip: while all other
713 % lines have height \verb:\baselineskip:. Thus subtract
714 % \verb:\topskip: and divide by \verb:\baselineskip:.
715 % \begin{macrocode}
716 \addtolength{\textheight}{-\topskip}
717 \divide\textheight\baselineskip
718 % \end{macrocode}
719 % The \verb:\divide: command performs integer division, so
720 % \verb:\textheight: is now \meta{number of lines}\,sp. Store the
721 % result in a counter to get a \emph{bona fide} number.
722 % \begin{macrocode}
723 \@tempcnta\textheight
724 % \end{macrocode}
725 % Now we can calculate the text height: the correct number of
726 % \verb:\baselineskip:s plus a \verb:\topskip: for the first line.
727 % \begin{macrocode}
728 \setlength{\textheight}{\@tempcnta\baselineskip}
729 \addtolength{\textheight}{\topskip}
730 % \end{macrocode}
731 %
732 % Again, the ``real'' top margin is
733 % \verb:1 inch:${}+{}$\verb:\voffset:${}+{}$\verb:\topmargin:,
734 % so subtract one inch from \verb:\topmargin:.
735 % \begin{macrocode}
736 \addtolength{\topmargin}{-1in}
737 % \end{macrocode}
738 %
739 % \begin{macro}{\cleartolastpage}
740 % The \verb:\cleartolastpage: command clears the page, checks for a
741 % star, prepares to issue a suitable \verb:\thispagestyle: command,
742 % and passes control to \verb:\cleartolastp@ge:.
743 % \begin{macrocode}
744 \newcommand{\cleartolastpage}{%
745 \clearpage
746 \@ifstar
747 {\def\TwoUp@blankpagestyle{\thispagestyle{empty}}\cleartolastp@ge}
748 {\let\TwoUp@blankpagestyle\relax\cleartolastp@ge}}
749 % \end{macrocode}
750 % The \verb:\cleartolastp@ge: command stores the first optional
751 % argument, \meta{div}, in the temporary counter \verb:\@tempcnta:
752 % with a default that depends on the \verb:twoside: class option.
753 % \begin{macrocode}
754 \if@twoside
755 \newcommand{\cleartolastp@ge}[1][4]{%
756 \@tempcnta#1\relax
757 \cleartol@stp@ge}%
758 \else
759 \newcommand{\cleartolastp@ge}[1][2]{%
760 \@tempcnta#1\relax
761 \cleartol@stp@ge}%
762 \fi
763 % \end{macrocode}
764 % The \verb:\cleartol@stp@ge: command does the real work: store a
765 % copy of the page number, \verb:\c@page:, in a temporary counter,
766 % divide and multiply by \meta{div} to round down to a multiple of
767 % \meta{div}, and add \meta{rem}.
768 % \begin{macrocode}
769 \newcommand{\cleartol@stp@ge}[1][0]{%
770 \@tempcntb\c@page
771 \divide\@tempcntb\@tempcnta
772 \multiply\@tempcntb\@tempcnta
773 \advance\@tempcntb#1\relax
774 % \end{macrocode}
775 % Now \verb:\@tempcntb: leaves remainder \meta{rem} when divided by
776 % \meta{div}, but it may still be smaller than the page number. If
777 % so, add \meta{div} to get the next number that leaves the same
778 % remainder.
779 % \begin{macrocode}
780 \ifnum\@tempcntb<\c@page
781 \advance\@tempcntb\@tempcnta
782 \fi
783 % \end{macrocode}
784 % Now \verb:\@\tempcntb: is the page number we want to reach.
785 % \begin{macrocode}
786 \loop\ifnum\c@page<\@tempcntb
787 \hbox{}\TwoUp@blankpagestyle\newpage
788 \repeat
789 }
790 %</package>
791 % \end{macrocode}
792 % \end{macro}
793 % \Finale