summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/booklet/booklet.dtx
blob: 04544a4046ee327c872b4016e48bd142c5c1fc38 (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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
% \iffalse meta-comment
% booklet.dtx
% Author: Peter Wilson (Herries Press)
% Maintainer: Will Robertson (will dot robertson at latex-project dot org)
% Copyright 2000--2005 Peter R. Wilson
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any 
% later version: <http://www.latex-project.org/lppl.txt>
%
% This work has the LPPL maintenance status "maintained".
% The Current Maintainer of this work is Will Robertson.
%
% This work consists of the files listed in the README file.
%
% 
%<*driver>
\documentclass[twoside]{ltxdoc}
\usepackage{url}
\usepackage[draft=false,
            plainpages=false,
            pdfpagelabels,
            bookmarksnumbered,
            hyperindex=false
           ]{hyperref}
\providecommand{\phantomsection}{}
\makeatletter
  \@mparswitchfalse
\makeatother
\EnableCrossrefs
\CodelineIndex
%%\OnlyDescription
\renewcommand{\MakeUppercase}[1]{#1}
\pagestyle{headings}
\setcounter{StandardModuleDepth}{1}
\begin{document}
  \DocInput{booklet.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{629}
%
% \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
% \DoNotIndex{\@centercr,\@cite}
% \DoNotIndex{\@dotsep,\@empty,\@float,\@gobble,\@gobbletwo,\@ignoretrue}
% \DoNotIndex{\@input,\@ixpt,\@m}
% \DoNotIndex{\@minus,\@mkboth,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
% \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
% \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
% \DoNotIndex{\advance,\Alph,\alph}
% \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
% \DoNotIndex{\bullet}
% \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
% \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
% \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
% \DoNotIndex{\EnableCrossrefs,\end,\end@dblfloat,\end@float,\endgroup}
% \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fbox}
% \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
% \DoNotIndex{\global,\halign,\hangindent,\hbox,\hfil,\hfill,\hrule}
% \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
% \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
% \DoNotIndex{\input}
% \DoNotIndex{\jobname,\kern,\leavevmode,\let,\leftmark}
% \DoNotIndex{\list,\llap,\long,\m@ne,\m@th,\mark,\markboth,\markright}
% \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
% \DoNotIndex{\NeedsTeXFormat,\newdimen}
% \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
% \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
% \DoNotIndex{\pagestyle,\par,\paragraph,\paragraphmark,\parfillskip}
% \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
% \DoNotIndex{\protect,\ProvidesClass,\raggedbottom,\raggedright}
% \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
% \DoNotIndex{\rightmargin,\rightmark,\rightskip,\rlap,\rmfamily,\roman}
% \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
% \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
% \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
% \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
% \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
% \DoNotIndex{\wd,\xiipt,\year,\z@}
%
% \changes{v0.5}{2001/08/11}{First public release}
% \changes{v0.6}{2001/08/26}{Reduced use of boxes}
% \changes{v0.6a}{2002/10/05}{Improved documentation, no technical changes}
% \changes{v0.6b}{2004/04/16}{Changed license and contact details}
% \changes{v0.7}{2005/03/23}{Improved print setup for memoir}
% \changes{v0.7a}{2005/06/01}{Additional documentation}
% \changes{v0.7b}{2009/09/02}{New maintainer}
%
% \def\dtxfile{booklet.dtx}
% \def\fileversion{v0.5} \def\filedate{2001/08/11}
% \def\fileversion{v0.6} \def\filedate{2001/08/26}
% \def\fileversion{v0.6a} \def\filedate{2002/10/05}
% \def\fileversion{v0.6b} \def\filedate{2004/04/16}
% \def\fileversion{v0.7} \def\filedate{2005/03/23}
% \def\fileversion{v0.7a} \def\filedate{2005/06/01}
% \def\fileversion{v0.7b} \def\filedate{2009/09/02}
% \newcommand*{\Lpack}[1]{\textsf {#1}}           ^^A typeset a package
% \newcommand*{\Lopt}[1]{\textsf {#1}}            ^^A typeset an option
% \newcommand*{\file}[1]{\texttt {#1}}            ^^A typeset a file
% \newcommand*{\Lcount}[1]{\textsl {\small#1}}    ^^A typeset a counter
% \newcommand*{\pstyle}[1]{\textsl {#1}}          ^^A typeset a pagestyle
% \newcommand*{\Lenv}[1]{\texttt {#1}}            ^^A typeset an environment
%
% \title{Printing booklets with LaTeX\thanks{This
%        file (\texttt{\dtxfile}) has version number \fileversion, last revised
%        \filedate.}}
%
% \author{%
% Author: Peter Wilson, Herries Press\\
% Maintainer: Will Robertson\\
% \texttt{will dot robertson at latex-project dot org}
% }
% \date{\filedate}
% \maketitle
% \begin{abstract}
%    The \Lpack{booklet} package provides some aid in printing
% simple booklets or signatures for longer books.
%
% \end{abstract}
% \tableofcontents
%
% 
%
% \section{Introduction}
%
%     In normal usage the \Lpack{booklet} package subverts LaTeX into
% putting pairs of pages onto a single page. For example, the contents
% of pairs of A4 
% portrait pages can be rotated and printed as two A5 portrait 
% pages side by side on an A4 landscape page.
%
%     In 1993 Timothy Van Zandt wrote the \Lpack{2up} generic macros 
% for printing more than one page on a physical sheet~\cite{2UP};
% his original code and documentation is in appendices~\ref{sec:2upcode}
% and~\ref{sec:2updoc}.
% The \Lpack{booklet}
% package is a poorman's version of some of the \Lpack{2up} macros
% specifically for (pdf)LaTeX.
%
%    The \Lpack{2up} and \Lpack{booklet} packages cannot be used
% simultaneously in one document.
%
% This manual is typeset according to the conventions of the
% \LaTeX{} \textsc{docstrip} utility which enables the automatic
% extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
%
%    Section~\ref{sec:usc} describes the usage of the \Lpack{booklet} 
% package and 
% commented source code is in Section~\ref{sec:code}. Timothy Van Zandt's
% original macros and documentation are supplied in the appendices.
%
%
%
% \section{The \Lpack{booklet} package} \label{sec:usc}
%
% The code provided by the \Lpack{booklet} package is meant to help
% with some aspects of booklet printing.
%
%    Basically, the pages of documents processed with the \Lpack{booklet}
% package will be reordered and scaled so that they can be printed as
% four pages per physical sheet of paper, two pages per side of the
% sheet. The default expectation is that the original document is in
% a portrait orientation and the pages are printed rotated onto a landscape
% sheet. Folding the sheet in half will produce a half-sized document, again
% with portrait orientation.
%
%    Professionally printed books have many pages printed per sheet of (large)
% paper, which is then folded and cut where necessary to produce a 
% \emph{signature} of several smaller sheets. Folding a sheet in
% half produces a one sheet \emph{folio} signature with four pages. 
% Folding it in half again and cutting
% along the original fold gives a two sheet \emph{quarto} signature 
% with eight pages. Folding in half again, 
% results in a four sheet \emph{octavo} signature with 16 pages, and so on
% through \emph{16mo}, \emph{32mo}, to \emph{64mo} with six folds and 128 pages. 
% \emph{Octavo} is the most popular of these.
%
%  Other folds can produce other signatures. For example a \emph{sexto},
% obtained by folding in half and then folding in thirds, is a three sheet
% signature with 12 pages.
%
%    The main differences between the \Lpack{2up} macros and the 
% \Lpack{booklet} package are:
% \begin{itemize}
% \item \Lpack{2up} is generic but \Lpack{booklet} can only be used
%       with (pdf)LaTeX.
% \item \Lpack{2up} can be used for more than booklets
% \item \Lpack{booklet} adds the notion of signatures and reduces the need for |\box|es.
% \item \Lpack{booklet} adds means of automatically controlling 
%       portrait/landscape printing.
% \end{itemize}
%
% \subsection{Options}
%
% When the \Lopt{noprint} option is used the package is essentially vacuous.
% That is, it behaves as though it had not been used at all, with the
% exception that LaTeX will not hiccup at any of the package commands that
% may be used in the document; these commands will also do nothing.
%
% The \Lopt{print} option must be used if you want the package to work 
% as advertised. The reasons for the \Lopt{print} and \Lopt{noprint}
% options are explained later in Section~\ref{sec:usage}.
%
%    The \Lpack{booklet} package can also take one option from each of
% two groups.
%
%    The first group of options specifies how many pages there should be
% to a hypothetical signature. The options are: \Lopt{four}, \Lopt{eight},
% \Lopt{sixteen}, and \Lopt{thirtytwo}. TeX has to hold all the pages
% for a signature before it outputs any of them, and TeX is memory limited.
%
%     If you have a duplex printer you can print out the document double-sided
% and then just fold the sheets forming each signature ready for binding.
% If you don't have a duplex printer, then the sheets can be photocopied
% (1-to-2 sided) ready for folding.
%
%    The second group of options are for selecting one of the package's
% predefined layouts. These options include:
% \begin{itemize}
% \item[\Lopt{twouparticle}] --- for portrait pages with wide margins
%     (similar to those in the standard LaTeX \Lpack{article}, \Lpack{book}
%      and \Lpack{report} classes)
%     and no marginal notes, to go on landscape sheets.
% \item[\Lopt{largetypeblock}] --- for portrait pages with a larger
%      (wider and/or longer) typeblock 
%   and/or marginal notes, to go on landscape sheets.
% \item[\Lopt{1to1}] --- for portrait pages where the original is 
%      designed to fit on half-sized paper, to go on landscape sheets.
% \item[\Lopt{landscape}] --- for landscape pages to go onto
%      portrait sheets. Pairs of original landscape pages will be
%      printed at the top and bottom of a portrait page.
%      This option is called automatically if the
%      \Lopt{landscape} option is used for the document class.
%
% \end{itemize}
%
%    The default options are \Lopt{noprint}, \Lopt{twouparticle} and 
% \Lopt{thirtytwo}.
%
% \subsection{Commands}
%
% The \emph{source} is the document as it would
% be normally typeset by LaTeX (i.e., without using the \Lpack{booklet}
% package).
%
% The \emph{target} is the desired document as it should 
% be printed
% using the \Lpack{booklet} package.
%
% \DescribeMacro{\source}
% The command |\source{|\meta{mag}|}{|\meta{width}|}{|\meta{height}|}|
% specifies the source sheets, where
% \meta{width} and \meta{height} are the width and height for the
% pages of the orginal document (the document that LaTeX would process
% without the \Lpack{booklet} package). The \meta{mag} argument is the
% magnification factor. 
%
%    The default definition of |\source| is: \\
% |\source{\magstep0}{\paperwidth}{\paperheight}| \\
% which corresponds to a full size default page.
%
% \DescribeMacro{\target}
% The command |\target{|\meta{mag}|}{|\meta{width}|}{|\meta{height}|}|
% specifies the target sheets, where
% \meta{width} and \meta{height} are the width and height for the
% sheets that will be used for printing with the package. For
% example, |\target{...}{11in}{8.5in}| would be typical for a 
% (portrait letterpaper)
% source being put onto a (landscape) letterpaper target.
%
% \DescribeMacro{\magstepN}
% \DescribeMacro{\magstepminusN}
% The package puts two pages onto a single sheet. It often happens that
% in order to do this the natural size of the text pages has to be changed,
% via the \meta{mag} argument noted above. The macro |\magstepminusN|,
% where $0 \leq N \leq 5$ is a shrinkage factor; similary, |\magstepN|
% specifies a magnification factor. For example, the default |\target|
% is specified as: \\
% |\target{\magstepminus1}{\paperheight}{\paperwidth}| \\
% whereas the target for the \Lopt{largetypeblock} option is: \\
% |\target{\magstepminus2}{\paperheight}{\paperwidth}| \\
% which shrinks the original pages more than the default |\target| does.
%
%    The \Lpack{booklet} package uses the |\source| and |\target| 
% specifications to decide on how to scale and position the orginal
% full size source pages onto half of a target sheet.
%
%    Normally there is no need to change the default |\source| but it
% may be useful sometimes to change the |\target|. For example, if the
% text on source letterpages is very wide it could be useful to print
% on legal paper instead. In this case |\target| can be defined as: \\
% |\target{\magstepminus2}{14in}{8.5in}|
%
% \DescribeMacro{\pagespersignature}
% If none of the signature options are suitable, then 
% |\pagespersignature{|\meta{num}|}| may be used to specify \meta{num}
% pages per signature. For example, if you wanted a \emph{sexto} signature
% then use |\pagespersignature{12}|.
%
% \DescribeMacro{\ifprintoption}
% The command |\ifprintoption| is set TRUE if the \Lopt{print} option 
% is used otherwise it is set FALSE.
%
% \DescribeMacro{\setdvipstargetpages}
% If you are using LaTeX to generate a \file{.dvi} file the
% |\setdvipstargetpages| macro sets up the correct target page sizes 
% in the \file{.dvi} file assuming that subsequent processing will be
% via a program that understands \file{dvips} \cs{special} commands.
% 
% \DescribeMacro{\setpdftargetpages}
% If you are using pdfLaTeX to generate a \file{.pdf} file the
% |\setpdftargetpages| macro sets up the correct target page sizes for
% pdfLaTeX.
%
% \DescribeMacro{\pagesepwidth}
% \DescribeMacro{\pageseplength}
% \DescribeMacro{\pagesepoffset}
%  A line may be drawn between the output text pages. The length of
% the line is |\pageseplength| (default 6.5in), and line starts a
% distance |\pagesepoffset| from the bottom (side) of the printed sheet
% (default 1in). The line thickness is specified by the length
% |\pagesepwidth|, which is initially defined to be 0pt (i.e., the
% line is normally invisible). To see a dividing line use |\setlength|
% to change the value of |\pagesepwidth|; in LaTeX ruled lines normally
% have a thickness of 0.4pt.
%
% \DescribeMacro{\twoupclearpage}
% \DescribeMacro{\twoupemptypage}
% The command |\twoupclearpage| outputs the current target page (like
% LaTeX's |\newpage|). The command |\twoupemptypage| inserts a completely
% empty page into the target.
%
% \DescribeMacro{\ifuselandscape}
% \DescribeMacro{\ifprintoption}
% The command |\ifuselandscape| is set TRUE if the \Lopt{landscape} option 
% is used otherwise it is set FALSE.
%
% \DescribeMacro{\checkforlandscape}
% The macro |\checkforlandscape| evaluates the value of |\ifprintoption|
% and the current value of |\ifuselandscape| and sets |\ifuselandscape| 
% to TRUE if the document
% requires landscape printing (when either both the \Lopt{landscape} and 
% \Lopt{noprint} options are used, or when just the \Lopt{print}
% option is called for), 
% or to FALSE if the document should be printed in the normal portrait 
% orientation (when either both the \Lopt{landscape} and \Lopt{print}
% options are used, or when just the \Lopt{noprint} option is used without
% \Lopt{landscape}). 
%
% Note that as |\checkforlandscape| may change the value of
% |\ifuselandscape|, the command is only guaranteed when |\ifuselandscape|
% accurately indicates the presence or absence of the \Lopt{landscape}
% option.
%
% In version 0.7 of the package the macro \cs{setdvipstargetpages} was
% introduced and the macro \cs{setpdftargetpages} was modified with the
% result that \cs{checkforlandscape} was effectively
% no longer needed. It is left to maintain upward compatibilty for
% older documents.
%
%
% \subsection{Usage} \label{sec:usage}
%
%     You use the \Lpack{booklet} package just like any other package: \\
% |\usepackage[<options>]{booklet}| \\
% but some other things need taking care of as well.
%
%    If you are making any changes to the values of |\paperwidth| or
% |\paperheight|, say through the \Lpack{geometry} package or the
% \Lpack{memoir} class, then the \Lpack{booklet} package must be called
% \emph{after} those changes have been made. In this case you may have
% to specify a different |\source| than usual, but I think that this
% is probably unlikely.
%
%
% \DescribeMacro{\special}
%    Under normal circumstances printing should be done onto landscape
% oriented paper instead of the usual portrait orientation. If you are
% using the \file{dvips} program for transformation from the \file{.dvi}
% to a \file{.ps} file, then you can use the command |\special{landscape}|
% in the preamble so that the output is organised for landscape. Other
% drivers may support similar commands, or command line options for
% accomplishing this.
%
%    For example, it may happen that if you use \file{ghostview} (or
% \file{gsview}) to look at \file{dvips} PostScript output of the final
% printing that the text appears upside down. Putting: \\
% \verb?\special{!TeXDict begin /landplus90{true}store end}? \\
% just before the \verb?\begin{document}? may cure this.
%
%    I use a LaserJet printer with a duplex printing capability (i.e.,
% printing can be done on both sides of a sheet in one pass). When
% printing in duplex mode I also found that it was very convenient
% to change the binding from the long to the short side of the paper;
% the sheets were then all set for folding. Using \file{dvips} and
% the 5SiMx LaserJet I found that the following commands in the
% preamble let me change the printer settings from the document.
% \begin{verbatim}
% \special{!TeXDict begin <</Duplex true>> setpagedevice end} % duplex
% \special{!TeXDict begin <</Tumble true>> setpagedevice end} % short binding
% \end{verbatim}
% How these would fare with another printer or program, I have no idea.
% The CTAN subdirectory \texttt{/dviware/dvipsconfig} contains a
% set of files for performing the above operations, and more, 
% as command line options for \file{dvips}.
%
%    If you can only do simplex printing (one side only), then when
% photocopying from one-sided to two-sided, alternate printed pages
% need to be rotated 180 degrees before being fed into the copier.
%
%    The following physical analogy of how the package works with
% portrait pages may help in achieving results that you want.
%
% \begin{itemize}
% \item Write the original text on portrait oriented transparent 
%       material (e.g., viewfoils) which is the same size as that 
%       specified by the |\source| macro. Mark the centre --- the 
%       point where the diagonals intersect --- of each original page.
%
% \item Take a sheet of paper the same size as that specified by
%       the |\target| macro and in landscape orientation. Mentally
%       divide this in half by a vertical line and then mark the centre
%       points of the two (left and right) halves.
% \item Take an even numbered original sheet, portrait orientaion,
%       and place it on top of the landscape oriented target sheet
%       with its centre point coincident with the left half centre
%       point. Do the same with an odd numbered original sheet except
%       that its centre is coincident with the right half centre point.
% \item Take the assembly to a photocopier and make a copy onto a target
%       sized sheet. This is the final result.
% \end{itemize}
% The analogy for landscape originals is similar with the obvious changes
% in the orientations.
%
%    Not that the analogy does not include any scaling. If the size of 
% the target is relatively small then the texts on the original sheets
% may overlap or extend outside the physical target sheet. If the target
% is relatively large then there may be too much white space around the
% texts. The \meta{mag} arguments to the |\source| and |\target| macros
% are provided to adjust the source/target text sizes. Scaling does
% not affect the positions of the texts.
%
%    If you are planning to produce a booklet in the first place, then
% design the initial page layout as though it would be printed on half-sized
% paper. This will produce a better end result as no scaling will
% be necessary. The \Lopt{1to1} option is provided for just this case.
%
%   If the original pages look too crowded after printing, you can specify
% another |\target| with a larger shrink factor (e.g., |\magstepminus3|
% instead of |\magstepminus2|). Conversely, too much white space can be
% countered by decreasing the shrink factor (e.g., |\magstepminus1|
% instead of |\magstepminus2|).
%
% The following are the default settings of |\source| and |\target| (the
% source and target sheets are the same size) for the different layout 
% options.
% \begin{itemize}
% \item[\Lopt{twouparticle:}] \mbox{} \\
%    |\source{\magstep0}{\paperwidth}{\paperheight}| \\
%    |\target{\magstepminus1}{\paperheight}{\paperwidth}| \\
% \item[\Lopt{largetypeblock:}] \mbox{} \\
%    |\source{\magstep0}{\paperwidth}{\paperheight}| \\
%    |\target{\magstepminus2}{\paperheight}{\paperwidth}| \\
% \item[\Lopt{1to1:}] \mbox{} \\
%    |\source{\magstep0}{\paperwidth}{\paperheight}| \\
%    |\target{\magstep0}{\paperheight}{\paperwidth}| \\
% \end{itemize}
%
%    If the original is not planned to be produced as a booklet, then
% obtaining respectable looking full size and booklet results may
% require some trial and error in determining good values for 
% magnifications and/or target paper sizes. The original page margins
% may also need changing for the booklet output.
%
%    LaTeX is not very happy if it is forced to save some pages instead
% of outputting each one as it is finished. It shows its displeasure
% by messing up any internal references in the document, for example
% a Table of Contents or an Index. To counter this, run LaTeX on the
% document \emph{without} the \Lopt{print} package option
% until all references
% have stabilised. Then put the command |\nofiles| in the preamble, use
% the \Lopt{print} option, 
% and run LaTeX a final time before printing.
% (The |\nofiles| command stops LaTeX from generating new \file{.aux},
% \file{.toc} files, etc., but it will still use any old versions).
%
% The following gives an indication of how the relevant portion of
% a preamble may look.
% \begin{verbatim}
% % possibly change default \paperwidth and/or \paperheight
% % \usepackage[noprint,...]{booklet}         % use this 
% % \usepackage[...]{booklet}                 % or this for initial runs
% % \usepackage[print, ...]{booklet} \nofiles % use this for final run
% % perhaps change \target
% \ifpdf                         % from the ifpdf package
%   \pdfoutput = 1               % generate pdf output
%   \setpdftargetpages           % set output page size
% \else
%   \setdvipstargetpages         % use this for dvi output
% \fi
% ...
% \end{verbatim}
% It is safer to use the package without the \Lopt{print} option for
% the initial runs rather than not using the package at all; doing it
% this way will stop LaTeX from complaining if you happened to have
% used any of the \Lpack{booklet} commands in the document.
%
%    TeX allocates a new box for each page in the first signature and then these
% are reused for each subsequent signature. Large
% signatures may use up all available boxes in which case
% TeX will tell you. It is much more probable, though, that TeX will
% run out of memory before this happens. 
%
%     Here is a real example of one booklet setup for typesetting a 68 page
% book. I used the \Lpack{memoir}
% class but afterwards I'll point out how to do the equivalent with the
% \Lpack{book} class.
% \begin{verbatim}
% \documentclass[letterpaper,11pt]{memoir}
% % typeblock size of 5.5+ by 4 inches
% \settypeblocksize{5.5in}{4in}{*}
% \addtolength{\textheight}{\onelineskip}
% \setlrmargins{2in}{*}{*}
% \setulmargins{2.25in}{*}{*}
% \checkandfixthelayout
% 
% % \usepackage[noprint]{booklet}
% \usepackage[print,1to1]{booklet} \nofiles 
% \pagespersignature{16} % 16 pages per signature
% 
% \ifpdf
%   \setpdftargetpages
% \else
%   \setdvipstargetpages
% \fi
% \ifprintoption  % tweak dvi output only for final printing
%   \special{!TeXDict begin /landplus90{true}store end}
%   \special{!TeXDict begin <</Tumble true>> setpagedevice end}
% \fi
%
% \begin{document}
% \pagestyle{empty}
% % Want a blank sheet before the title page
% \hbox{}\cleardoublepage
% % half-title page here
% \cleardoublepage
% 
% % title page here
% \clearpage
% 
% % copyright page here
% \cleardoublepage
% 
% \pagestyle{plain}
% \pagenumbering{roman}
% \tableofcontents*
% \cleardoublepage
% \pagenumbering{arabic}
% \pagestyle{headings}
% 
% \chapter{First}
% % and so on
% 
% % want some blank endpapers to get enough pages into
% % the last signature for easy binding
% \clearpage
% \hbox{}\clearpage\hbox{}\cleardoublepage
% \end{document}
% \end{verbatim}
%
% Using the \Lpack{book} class just involves changing how the page layout
% is specified:
% \begin{verbatim}
% \documentclass[letterpaper,11pt]{book}
% % typeblock size of 5.5 by 4 inches
% \setlength{\textheight}{419pt} \setlength{\textwidth}{289pt}
% \setlength{\oddsidemargin}{72pt} \setlength{\evensidemargin}{108pt} 
% \setlength{\topmargin}{55.9pt} \setlength{\footskip}{27.5pt} 
% \setlength{\headheight}{14.6pt} \setlength{\headsep}{19.9pt} 
%
% % \usepackage[noprint]{booklet}
% ...
% \end{verbatim}
%
%    If you try and use a non-zero magnification with a document that
% has any `true' lengths, for example the \Lpack{amsbook} class, 
% TeX itself will complain with an error message
% of the form: \\
% |!Incompatible magnification (833);| \\
% |the previous value will be retained|\\
% Try forcing LaTeX to continue and check the output because you might
% be lucky and it looks alright.
%
% \changes{v0.7a}{2005/06/01}{Added Gordo's example}
%    Here is another example from a posting to \texttt{comp.text.tex} by
% Gordo in the thread \textit{booklet problem}, 2005/05/26.
% \begin{verbatim}
% \documentclass[twoside,10pt]{article}
% \setlength{\paperwidth}{5.5in}
% \setlength{\paperheight}{8.5in}
% \setlength{\topmargin}{-0.3in}
% \setlength{\textheight}{6.9in}
% \setlength{\oddsidemargin}{0.0in}
% \setlength{\evensidemargin}{-0.5in}
% \setlength{\textwidth}{4.0in}
% \usepackage{makeidx}
% %\usepackage[noprint,1to1]{booklet} % initial runs for ToC and index
% \usepackage[noprint,1to1]{booklet} \nofiles % final printing run
% \source{\magstep0}{5.5in}{8.5in}
% \target{\magstep0}{11in}{8.5in}
% \setpdftargetpages
% \pagespersignature{120}
% \makeindex
% \begin{document}
% \pagenumbering{roman}
% \begin{titlepage} ... \end{titlepage} % the title
% ...
% \newpage
% \begin{titlepage} \mbox{} \end{titlepage} % back cover
% \end{document}     
% \end{verbatim}
%
%
% \changes{v0.7a}{2005/06/01}{Added example for bookleting the manual}
% As yet another example, you can produce this manual as a booklet. Change
% the first part of this file to read:
% \begin{verbatim}
% \documentclass[twoside]{ltxdoc}
% \usepackage{url}
% \usepackage{ifpdf}
% \addtolength{\evensidemargin}{-0.75in}
% % \usepackage[noprint]{booklet} % initial runs
% \usepackage[print,largetypeblock]{booklet}\nofiles\pagespersignature{48} % final run
% %\usepackage[draft=false,
% %            plainpages=false,
% %            pdfpagelabels,
% %            bookmarksnumbered,
% %            hyperindex=false
% %           ]{hyperref}
% \ifpdf
%   \setpdftargetpages
% \else
%   \setdvipstargetpages
% \fi
% \providecommand{\phantomsection}{}
% \makeatletter
%   \@mparswitchfalse
% \makeatother
% ...
% \end{verbatim}
% The \Lpack{hyperref} package interferes with the \cs{setpdftargetpages}
% macro so it is commented out. The \Lopt{largetypeblock} option is used
% otherwise the marginal notes can fall off the edges of the pages in the
% final printing; the \cs{evensidemargin} is also altered for the same reason.
% The value for \cs{pagespersignature} is to ensure that
% only a single signature is produced (you can decrease this if you are
% willing to bind multiple signatures).
%
%
%    The original source of the \Lpack{2up} package is included at
% the end of this manual. It may provide some more insights into how to
% use the \Lpack{booklet} package. Be careful, though, as the two packages
% differ in some significant details.
%
%
%
% \StopEventually{
% \bibliographystyle{alpha}
% \begin{thebibliography}{GMS94}
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock \emph{The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
% \bibitem[Zan93]{2UP}
% Timothy Van Zandt.
% \newblock \emph{Two-up printing for Generic TeX}.
% \newblock January 1993.
% \newblock (Available from CTAN in \texttt{macros/generic/2up})
% \end{thebibliography}
% }
%
%
% \section{The package code} \label{sec:code}
%
% The package code essentially consists of modifications to the \Lpack{2up}
% macros, which are given in section~\ref{sec:2upcode}. I could not
% have written the \Lpack{booklet} package without Timothy Van Zandt's
% \Lpack{2up} macros.
%
%    As much as possible I have tried to keep to the original
% \Lpack{2up} macro names. However, the \Lpack{2up} and \Lpack{booklet}
% packages cannot be used in the same document.
%
%    The code is actually in two packages, \file{booklet.sty} which 
% provides the commands that 
% the user sees, and \file{bkltprnt.sty} which is used by 
% \file{booklet.sty} to do all the hard work.
%
% \subsection{Preliminaries}
%
%    Announce the name and version of the packages, which require
% \LaTeXe.
%    \begin{macrocode}
%<*usc>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{booklet}[2009/09/02 v0.7b booklet printing]

%</usc>
%<*prnt>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bkltprnt}[2009/09/02 v0.7b support for booklet printing]

%</prnt>
%    \end{macrocode}
%
% \subsection{The main \Lpack{booklet} code}
%
%    The \Lpack{booklet} package provides the user commands. Then, if
% the \Lopt{print} option is used it calls the \Lpack{bkltprnt}
% package to do the work.
%
%    \begin{macrocode}
%<*usc>
%    \end{macrocode}
%
% \begin{macro}{\twoup@end}
%  For the \Lopt{print} and \Lopt{noprint} options.
%    \begin{macrocode}
\newcommand*{\twoup@end}{\endinput}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\pageseplength}
% \begin{macro}{\pagesepwidth}
% \begin{macro}{\pagesepoffset}
% Lengths for the dividing rule.
%    \begin{macrocode}
\newdimen\pageseplength
\newdimen\pagesepwidth
\newdimen\pagesepoffset

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ifsidebyside}
% TRUE if pages are to be placed side-by-side on the sheet. I have changed
% the original |\if@sidebyside| to |\ifsidebyside| so that a user can
% call it easily. I don't
% don't implement the |\if@twosided|.
%    \begin{macrocode}
\newif\ifsidebyside
  \sidebysidetrue

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifuselandscape}
% \begin{macro}{\ifprintoption}
% Booleans for some options and for if the final printing should be landscape.
%    \begin{macrocode}
\newif\ifuselandscape
  \uselandscapefalse
\newif\ifprintoption
  \printoptionfalse

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\c@signature}
% \begin{macro}{\c@sigcount}
% Counters for signature handling.
%    \begin{macrocode}
\newcounter{signature}
\newcounter{sigcount}
  \setcounter{sigcount}{0}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\pagespersignature}
% A user-level command for setting the number of pages wanted
% in a signature. I initialise these to 32.
%    \begin{macrocode}
\newcommand*{\pagespersignature}[1]{\setcounter{signature}{#1}}
  \pagespersignature{32}

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\magstepminus}
% A useful extension of the |\magstep| macro.
%    \begin{macrocode}
\def\magstepminus#1{%
  \ifcase#1 \@m\or 833\or 694\or 579\or 482\or 401\fi\relax}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\target}
% \begin{macro}{\source}
% \begin{macro}{\setpdftargetpages}
% \begin{macro}{\setdvipstargetpages}
% Vacuous versions of the user-level macros.
% \changes{v0.7}{3005/03/23}{Added \cs{setdvipstargetpages}}
%    \begin{macrocode}
\newcommand*{\target}[3]{}
\newcommand*{\source}[3]{}
\newcommand*{\setpdftargetpages}{}
\newcommand*{\setdvipstargetpages}{}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\targettopbottom}
% Vacuous version of the user command.
%    \begin{macrocode}
\newcommand*{\targettopbottom}{}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\twoupemptypage}
% \begin{macro}{\twoupclearpage}
% vacuous versions of the user commands.
%    \begin{macrocode}
\newcommand*{\twoupemptypage}{}
\newcommand*{\twoupclearpage}{}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\checkforlandscape}
% Sets the value of |\ifuselandscape| to 
% (|\ifuselandscape| XOR |\ifprintoption|).
%    \begin{macrocode}
\newcommand*{\checkforlandscape}{%
  \ifx\ifuselandscape\ifprintoption
    \uselandscapefalse\else\uselandscapetrue\fi}

%    \end{macrocode}
% \end{macro}
%
%    Now declare the \Lopt{print}, \Lopt{noprint} and \Lopt{landscape}
% options, 
% prepare to pass any other
% options to \Lpack{bkltprnt}, and execute the options.
%    \begin{macrocode}
\DeclareOption{print}{\printoptiontrue\def\twoup@end{}}
\DeclareOption{noprint}{\printoptionfalse\def\twoup@end{\endinput}}
\DeclareOption{landscape}{\uselandscapetrue}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{bkltprnt}}
\ProcessOptions\relax
\ifuselandscape
  \PassOptionsToPackage{landscape}{bkltprnt}
\fi

%    \end{macrocode}
%
%  Now call |\twoup@end|, which is either |\endinput| or vacuous, after
% which the \Lpack{bkltprnt} package is called (if |\twoup@end| was vacuous).
%    \begin{macrocode}
\twoup@end

\RequirePackage{bkltprnt}

%    \end{macrocode}
%
%
%    The end of this package.
%
%    \begin{macrocode}
%</usc>
%    \end{macrocode}
%
% \subsection{The main \Lpack{bkltprnt} code}
%
%    \begin{macrocode}
%<*prnt>
%    \end{macrocode}
%
% \begin{macro}{\@targetwidth}
% \begin{macro}{\@targetheight}
% \begin{macro}{\@sourcewidth}
% \begin{macro}{\@sourceheight}
% Parameter registers.
%    \begin{macrocode}
\newdimen\@targetwidth
\newdimen\@targetheight
\newdimen\@sourcewidth
\newdimen\@sourceheight

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@leftpage}
% \begin{macro}{\@leftpage}
% \begin{macro}{\@rightpage}
% \begin{macro}{\@physicalpage}
% Registers used by output routine.
%    \begin{macrocode}
\newif\if@leftpage
  \@leftpagetrue
\newbox\@leftpage
\newbox\@rightpage
\newcount\@physicalpage

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% Since pages are both stored and shipped out half as often:
%    \begin{macrocode}
\multiply\maxdeadcycles by 40\relax

%    \end{macrocode}
%
% \begin{macro}{\bookletpage}
% \begin{macro}{\leftpagenumber}
% \begin{macro}{\rightpagenumber}
% Registers used only for booklet layout. These are specified directly
% as this is the only layout.
%    \begin{macrocode}
\newcount\bookletpage
  \bookletpage=0
\newcount\leftpagenumber
\newcount\rightpagenumber

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\twoupp@geboxes}
% I have added this macro so that only the boxes required for a signature
% are created. The original \Lpack{2up} code creates a new box for each output page.
% \changes{v0.6}{2001/08/26}{Added \cs{twoupp@geboxes}}
%    \begin{macrocode}
\newcommand*{\twoupp@geboxes}{%
  \advance\bookletpage\@ne
  \expandafter\newbox\csname bookletbox\the\bookletpage\endcsname
  \ifnum \bookletpage < \c@signature
    \twoupp@geboxes
  \fi}
\AtBeginDocument{\twoupp@geboxes\bookletpage=\z@}

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\target}
% \begin{macro}{\inv@targetmag}
% |\@targetwidth| and |\@targetheight| are set to the \emph{unmagnified} 
% dimensions
% of the target page. |\inv@targetmag| is the inverse of the target
% magnification.
%    \begin{macrocode}
{\catcode`\p=12\catcode`\t=12\gdef\@@inv@@mag#1pt#2{\def#2{#1}}}
\def\target#1#2#3{%
  \mag #1\relax
  \@targetwidth=1000pt
  \divide\@targetwidth by #1\relax
  \expandafter\@@inv@@mag\the\@targetwidth\inv@targetmag
  \@targetwidth=#2\relax
  \@targetwidth=\inv@targetmag\@targetwidth
  \@targetheight=#3\relax
  \@targetheight=\inv@targetmag\@targetheight}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\source}
% Like |\target|, but for the source:
%    \begin{macrocode}
\def\source#1#2#3{%
  \@sourcewidth=1000pt
  \divide\@sourcewidth by #1\relax
  \expandafter\@@inv@@mag\the\@sourcewidth\inv@sourcemag
  \@sourcewidth=#2\relax
  \@sourcewidth=\inv@sourcemag\@sourcewidth
  \@sourceheight=#3\relax
  \@sourceheight=\inv@sourcemag\@sourceheight}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setpdftargetpages}
% This macro specifies the size of the target page for pdfLaTeX.
% It ensures that \Lpack{memoir}'s version (\cs{fixpdflayout}) does nothing.
% \changes{v0.7}{2005/03/23}{Modified \cs{setpdftargetpages} to cater for memoir}
%    \begin{macrocode}
\renewcommand*{\setpdftargetpages}{%
  \ifprintoption
    \setlength{\pdfpageheight}{\@targetheight}%
    \setlength{\pdfpagewidth}{\@targetwidth}%
    \let\fixpdflayout\relax
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setdvipstargetpages}
% This macro specifies the size of the target page fow when dvips is
% used. It ensures that \Lpack{memoir}'s version (\cs{fixdvipslayout}) 
% does nothing.
% \changes{v0.7}{2005/03/23}{Implemented \cs{setdvipstargetpages}}
%    \begin{macrocode}
\renewcommand*{\setdvipstargetpages}{%
  \ifprintoption
    \AtBeginDvi{\special{papersize=\the\@targetwidth,\the\@targetheight}}%
    \let\fixdvipslayout\relax
  \fi}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\targetBooklet}
% \begin{macro}{\ship@@@leftpage}
% \begin{macro}{\ship@@@rightpage}
% I only provide the original \Lpack{2up} Booklet, not booklet. For
% the \Lpack{booklet} package the Booklet code can be processed
% immediately. The code in this chunk is equvalent to the original
% |\target@Booklet|.
%    \begin{macrocode}
\def\targetBooklet{%
  \def\ship@@@leftpage{\save@booklet\@leftpage}%
  \def\ship@@@rightpage{\save@booklet\@rightpage}%
  \@leftpagefalse}
\targetBooklet

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\targettopbottom}
% \begin{macro}{\make@@halfpage}
% \begin{macro}{\make@fullpage}
% I have renamed the original |\target@topbottom| to |\targettopbottom|
%    \begin{macrocode}
\def\targettopbottom{%
  \def\make@@halfpage{\make@@halftopbottom}%
  \def\make@fullpage{\make@fulltopbottom}%
  \sidebysidefalse}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Specify the options. There are new ones for signature sizes, and some
% of the original \Lpack{2up} source/targets are now treated as options.
%    \begin{macrocode}
\DeclareOption{four}{\setcounter{signature}{4}}
\DeclareOption{eight}{\setcounter{signature}{8}}
\DeclareOption{sixteen}{\setcounter{signature}{16}}
\DeclareOption{thirtytwo}{\setcounter{signature}{32}}
\DeclareOption{twouparticle}{\twouparticle}
\DeclareOption{landscape}{\twouplandscape}
\DeclareOption{largetypeblock}{\twoupplain}
\DeclareOption{1to1}{\twouponetoone}

%    \end{macrocode}
%
% \begin{macro}{\shipout}
% TeX's |\shipout| primitive is saved as |\&normal@shipout|, 
% and then |\shipout|
% is defined to save each page to |\@leftpage| or |\@rightpage| 
% and to print out every two. There is no twosided layout in this version.
%    \begin{macrocode}
\expandafter\let\csname &normal@shipout\endcsname\shipout
\def\shipout{%
  \if@leftpage
    \global\@leftpagefalse
    \def\next{\afterassignment\ship@leftpage\global\setbox\@leftpage=}%
  \else
    \global\@leftpagetrue
    \def\next{\afterassignment\ship@rightpage\global\setbox\@rightpage=}%
  \fi
  \next}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ship@leftpage}
% \begin{macro}{\ship@rightpage}
% The job of |\ship@leftpage| and |\ship@rightpage| is to invoke 
% |\ship@@leftpage| or |\ship@@rightpage| at the right time. 
% |\shipout| is followed either:
% \begin{enumerate}
% \item by an |\hbox|, |\vbox| or |\vtop|, in which case 
% |\ship@leftpage| is invoked after the opening |{|; 
% |\@leftpage| is void, and |\ship@leftpage| invokes
% |\ship@@leftpage| after the closing |}|: or
%
% \item by a |\box| or |\copy|, in which case |\ship@leftpage| is invoked after
% the full assignment; |\@leftpage| is not void, and |\ship@leftpage| invokes
% |\ship@@leftpage| immediately.
% \end{enumerate}
%
%    \begin{macrocode}
\def\ship@leftpage{%
  \ifvoid\@leftpage\aftergroup\ship@@leftpage\else\ship@@leftpage\fi}
\def\ship@rightpage{%
  \ifvoid\@rightpage\aftergroup\ship@@rightpage\else\ship@@rightpage\fi}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ship@@leftpage}
% \begin{macro}{\ship@@rightpage}
%     |\ship@@leftpage|/|\ship@@rightpage| take the output box, 
% and first make it
% into a fully-size source page (with |\make@halfpage|) and then this is
% centered horizontally and vertically in half of a target page (with
% |\make@@halfpage|). Then they are shipped individually or together.
%    \begin{macrocode}
\def\ship@@leftpage{\make@halfpage\@leftpage\ship@@@leftpage}
\def\ship@@rightpage{\make@halfpage\@rightpage\ship@@@rightpage}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\make@halfpage}
%    \begin{macrocode}
\def\make@halfpage#1{%
  \dp#1=\z@
  \setbox#1=\vbox to\@sourceheight{%
    \vskip \inv@sourcemag in
    \vskip \voffset
    \hbox to\@sourcewidth{\hskip\inv@sourcemag in\hskip\hoffset\box#1\hss}%
    \vss}%
  \make@@halfpage#1}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\make@@halfsidebyside}
% \begin{macro}{\make@@halfpage}
% The definition of |\make@@halfpage| depends on the target layout.
%    \begin{macrocode}
\def\make@@halfsidebyside#1{%
  \global\setbox#1=\vbox to\@targetheight{\vss
    \hbox to.5\@targetwidth{\hss\box#1\hss}\vss}}
\def\make@@halfpage{\make@@halfsidebyside}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\make@@halftopbottom}
%    \begin{macrocode}
\def\make@@halftopbottom#1{%
  \global\setbox#1=\vbox to.5\@targetheight{\vss
    \hbox to\@targetwidth{\hss\box#1\hss}\vss}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ship@twoup}
% The pages are generaly shipped in pairs:
%    \begin{macrocode}
\def\ship@twoup{%
  \begingroup
    \voffset=-\inv@targetmag in
    \hoffset=\voffset
    \global\advance\@physicalpage by 1
    \count\z@=\@physicalpage
    \csname &normal@shipout\endcsname\make@fullpage
  \endgroup}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\make@fullsidebyside}
% \begin{macro}{\make@fulltopbottom}
%    \begin{macrocode}
\def\make@fullsidebyside{%
  \hbox{\box\@leftpage\pagesep@sidebyside\box\@rightpage}}
\def\make@fulltopbottom{%
  \vbox{\offinterlineskip\box\@leftpage\pagesep@topbottom\box\@rightpage}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\make@fullpage}
% The definition of |\make@fullpage| depends on the layout:
%    \begin{macrocode}
\def\make@fullpage{\make@fullsidebyside}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\pagesep@sidebyside}
% \begin{macro}{\pagesep@topbottom}
% A vertical or horizontal rule can be inserted. These can be redefined
% for other tricks:
%    \begin{macrocode}
\def\pagesep@sidebyside{%
  \begingroup
    \advance\pageseplength by \pagesepoffset
    \pagesepwidth=\inv@targetmag\pagesepwidth
    \kern -.5\pagesepwidth
    \vrule height \inv@targetmag\pageseplength
           depth -\inv@targetmag\pagesepoffset
           width \pagesepwidth
    \kern -.5\pagesepwidth
  \endgroup}
\def\pagesep@topbottom{%
  \begingroup
    \pagesepwidth=\inv@targetmag\pagesepwidth
    \vskip -.5\pagesepwidth
    \moveright\inv@targetmag\pagesepoffset\hbox{%
      \vrule height\pagesepwidth width\inv@targetmag\pageseplength}%
    \vskip -.5\pagesepwidth
  \endgroup}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \changes{v0.7a}{2005/06/01}{Added sewing example}
%    For example it may be helpful to mark the positions of sewing holes
% along the spine of your booklet. For \Lopt{landscape} this can be done 
% by redefining \cs{pagesep@topbottom} and for the more typical portrait 
% style booklet by changing \cs{pagesep@sidebyside}. The general technique
% is to use a zero-sized picture which \LaTeX{} will think takes up no space.
% For instance, for letterpaper (11in by 8.5in) you can do something
% like this in your preamble:
% \begin{verbatim}
% \makeatletter
% \renewcommand*{\pagesep@sidebyside}{%
%   \begingroup
%   \setlength{\unitlength}{1in}%      measurements in inches
%   \begin{picture}(0,0)(0,-8.5)%      zero-sized picture, origin at page top
%     \put(0,-1){\makebox(0,0){.}}%    mark 1in down from top
%     \put(0,-4.25){\makebox(0,0){.}}% mark at page center
%     \put(0,-7.5){\makebox(0,0){.}}%   mark 1in up from bottom
%   \end{picture}%
%   \endgroup}
% \makeatother
% \end{verbatim}
%
% \begin{macro}{\save@booklet}
% With the Booklet layout, the pages are saved rather than
% shipped. I have added the signature code to the original macro. This
% outputs all the pages making up a signature even if there are still more
% to come. The page boxes used in |\save@booklet| are assigned initially
% by |\twoupp@geboxes|.
% \changes{v0.6}{2001/08/26}{Modified \cs{save@booklet}}
%    \begin{macrocode}
\begingroup
\let\newbox\relax
\gdef\save@booklet#1{%
  \begingroup
    \globaldefs=1
    \ifnum\c@sigcount=\z@\bookletpage=0\fi
    \advance\bookletpage by 1
    \addtocounter{sigcount}{1}
%%%%    \expandafter\newbox\csname bookletbox\the\bookletpage\endcsname
    \expandafter\setbox\csname bookletbox\the\bookletpage\endcsname\box#1%
  \endgroup
  \ifnum\c@sigcount=\c@signature     %%% PW
    \twoup@eject%           
    \setcounter{sigcount}{0}%
  \fi}
\endgroup

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\make@bookletpage}
% \begin{macro}{\booklet@loop}
% \begin{macro}{\Booklet@@loop}
% The pages are then printed at the end with the following macros:
%    \begin{macrocode}
\def\make@bookletpage#1{%
  \setbox\ifodd#1\@rightpage\else\@leftpage\fi=%
    \expandafter\box\csname bookletbox\the#1\endcsname}

\def\booklet@loop{%
  \count\z@\rightpagenumber
  \make@bookletpage\leftpagenumber
  \make@bookletpage\rightpagenumber
  \ship@twoup
  \Booklet@@loop
}

\def\Booklet@@loop{%
  \advance\rightpagenumber by 1
  \advance\leftpagenumber by -1
  \ifnum\leftpagenumber<\rightpagenumber\else\expandafter\booklet@loop\fi}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\twoupemptypage}
% This one is easy:
%    \begin{macrocode}
\def\twoupemptypage{\shipout\hbox{}}

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\twoup@eject}
% This clears a whole target page if there is a saved left page. Note that
% this does not invoke the output routine; i.e., it is not like |\clearpage|
% or |\supereject|. See |\twoupclearpage| below. (The \Lpack{booklet}
% package doesn't need |\twoupeject| which is for non-LaTeX systems).
%
% This is the definition of |\twoup@eject| with the Booklet layout.
%    \begin{macrocode}
\def\twoup@eject{
  \leftpagenumber\bookletpage
  \advance\leftpagenumber by 3
  \divide\leftpagenumber by 4
  \multiply\leftpagenumber by 4
  \rightpagenumber=1
  \ifnum\leftpagenumber>\bookletpage
    \setbox\@leftpage\hbox{}%
    \make@@halfpage\@leftpage
    \loop
      \setbox\@rightpage\copy\@leftpage
      \save@booklet\@rightpage
    \ifnum\leftpagenumber>\bookletpage
    \repeat
  \fi
  \booklet@loop}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\twoupclearpage}
% This modification is needed for LaTeX in order to get the last page
% printed out if the final page is a left page (the catcode business is
% because |\enddocument| is |\let| to |\bye| in amstex):
%    \begin{macrocode}
\begingroup
\catcode`\>=9\relax
>>\gdef\twoupclearpage{\clearpage\twoup@eject}
>>\expandafter\@temptokena\expandafter{\enddocument}
>>\xdef\enddocument{\noexpand\twoupclearpage\the\@temptokena}
\endgroup

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\TwoupWrites}
% This is one workaround for the page cross-references problem
%    \begin{macrocode}
\def\TwoupWrites{%
  \let\TwoupSaved@write\write
  \let\TwoupSaved@read\read
  \let\TwoupSaved@openout\openout
  \let\TwoupSaved@closeout\closeout
  \def\write{\TwoupSaved@write-1{}\immediate\TwoupSaved@write}%
  \def\read{\TwoupSaved@write-1{}\immediate\TwoupSaved@read}%
  \def\openout{\TwoupSaved@write-1{}\immediate\TwoupSaved@openout}%
  \def\closeout{\TwoupSaved@write-1{}\immediate\TwoupSaved@closeout}%
  \let\TwoupWrites\relax}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\twouparticle}
% \begin{macro}{\twoupplain}
% \begin{macro}{\twouplandscape}
% \begin{macro}{\twouponetoone}
% The pre-defined layouts. I have taken advantage of LaTeX2e's
% paper size lengths to generalise.
%    \begin{macrocode}
\def\twouparticle{\target{\magstepminus1}{\paperheight}{\paperwidth}}
\def\twoupplain{\target{\magstepminus2}{\paperheight}{\paperwidth}}
\def\twouplandscape{\target{\magstepminus2}{\paperwidth}{\paperheight}%
  \targettopbottom}
\def\twouponetoone{\target{\magstep0}{\paperheight}{\paperwidth}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Set the default for the source.
%    \begin{macrocode}
\source{\magstep0}{\paperwidth}{\paperheight}
%    \end{macrocode}
%
% Set the defaults for the rule.
%    \begin{macrocode}
\pagesepwidth 0pt
\pageseplength 6.5in
\pagesepoffset 1in
%    \end{macrocode}
%
% I also found that |\TwoupWrites| was really not optional.
%    \begin{macrocode}
\TwoupWrites

%    \end{macrocode}
%
% The default options are \Lopt{twouparticle} and \Lopt{thirtytwo} pages
% per signature.
%    \begin{macrocode}
\ExecuteOptions{twouparticle,thirtytwo}
\ProcessOptions

%    \end{macrocode}
%
%
%    The end of this package.
%    \begin{macrocode}
%</prnt>
%    \end{macrocode}
%
%
% \appendix
%
% \section{The code for 2up} \label{sec:2upcode}
%
%    Following is a verbatim copy of Timothy Van Zandt's \Lpack{2up} code.
% I hope that by including this I have partly met his COPYING conditions.
%
% \begin{verbatim}
% 
% %% BEGIN 2up.tex/2up.sty
% %%
% \def\fileversion{1.2}
% \def\filedate{93/01/28}
% %%
% %% COPYRIGHT 1992, 1993 by Timothy Van Zandt, tvz@Princeton.EDU
% %%
% %% DESCRIPTION:
% %%   2up.tex/2up.sty provides two-up printing for Generic TeX (e.g.,
% %%   Plain, LaTeX, AmSTeX and AmS-LaTeX). It produces a standard dvi file,
% %%   and does not involve an additional dvi or PostScript filter. It has a
% %%   flexible interface for specifying paper size and layout.
% %%
% %% INSTALLATION:
% %%   Put this file where your TeX looks for inputs, under the name 2up.tex.
% %%   Name a copy 2up.sty to use as a LaTeX style option, or create a file
% %%   2up.sty with the lines:
% %%     \input 2up.tex
% %%     \endinput
% %%
% %% DOCUMENTATION:
% %%   Input 2up.tex, or include 2up as a LaTeX style option. There is a
% %%   good chance you will get the desired layout. (But you will probably
% %%   need to generate new font bitmaps to get high quality output.) See
% %%   2up.doc, which might be appended to this file, for detailed
% %%   documentation.
% %%
% %% COPYING:
% %%   Copying of part or all of this file is allowed under the following
% %%   conditions only:
% %%   (1) You may freely distribute unchanged copies of the file. Please
% %%       include the documentation when you do so.
% %%   (2) You may modify a renamed copy of the file, but only for personal
% %%       use or use within an organization.
% %%   (3) You may copy fragments from the file, for personal use or for use
% %%       in a macro package for distribution, as long as credit is given
% %%       where credit is due.
% %%
% %%   You are NOT ALLOWED to take money for the distribution or use of
% %%   this file or modified versions or fragments thereof, except for
% %%   a nominal charge for copying etc.
% %%
% %% CODE:
% %
% \csname TwoUpLoaded\endcsname
% \let\TwoUpLoaded\endinput
% %
% \edef\TheAtCode{\the\catcode`\@}
% \catcode`\@=11\relax
% \message{\space\space v\fileversion\space\space \filedate\space\space <tvz>}
% %
% % Parameter registers:
% \newdimen\@targetwidth
% \newdimen\@targetheight
% \newdimen\@sourcewidth
% \newdimen\@sourceheight
% \newdimen\pageseplength
% \newdimen\pagesepwidth
% \newdimen\pagesepoffset
% \newif\if@sidebyside
% \@sidebysidetrue
% \newif\if@twosided
% %
% % Registers used by output routine.
% \newif\if@leftpage
% \@leftpagetrue
% \newbox\@leftpage
% \newbox\@rightpage
% \newcount\@physicalpage
% %
% % Since pages are shipped out half as often:
% \multiply\maxdeadcycles by 2
% %
% % Registers used only for booklet layout:
% \begingroup
%   \let\newcount\relax
%   \gdef\booklet@registers{%
%     \newcount\bookletpage
%     \bookletpage=0
%     \newcount\leftpagenumber
%     \newcount\rightpagenumber
%     \multiply\maxdeadcycles by 20}
% \endgroup
% %
% % A useful extension of the \magstep macro.
% \def\magstepminus#1{%
%   \ifcase#1 \@m\or 833\or 694\or 579\or 482\or 401\fi\relax}
% %
% % \@targetwidth and \@targetheight are set to the *unmagnified* dimensions
% % of the target page. \inv@targetmag is the inverse of the target
% % magnification.
% {\catcode`\p=12\catcode`\t=12\gdef\@@inv@@mag#1pt#2{\def#2{#1}}}
% \def\target#1#2#3{%
%   \mag #1\relax
%   \@targetwidth=1000pt
%   \divide\@targetwidth by #1\relax
%   \expandafter\@@inv@@mag\the\@targetwidth\inv@targetmag
%   \@targetwidth=#2\relax
%   \@targetwidth=\inv@targetmag\@targetwidth
%   \@targetheight=#3\relax
%   \@targetheight=\inv@targetmag\@targetheight}
% %
% % Like \target, but for the source:
% \def\source#1#2#3{%
%   \@sourcewidth=1000pt
%   \divide\@sourcewidth by #1\relax
%   \expandafter\@@inv@@mag\the\@sourcewidth\inv@sourcemag
%   \@sourcewidth=#2\relax
%   \@sourcewidth=\inv@sourcemag\@sourcewidth
%   \@sourceheight=#3\relax
%   \@sourceheight=\inv@sourcemag\@sourceheight}
% %
% % \targetlayout does a loop that reads the comma separated arguments.
% % There can be no extraneous spaces.
% \def\targetlayout#1{\process@targetlayout#1,stop,}
% \def\process@targetlayout#1,{%
%   \expandafter\let\expandafter\next\csname target@#1\endcsname
%   \ifx\next\relax
%     \begingroup
%       \errhelp{Valid target layouts are "topbottom", "twosided",
%         "booklet", "Booklet" and "dvidvi".}%
%       \errmessage{`#1' is invalid 2up target layout - ignored.}%
%     \endgroup
%     \expandafter\process@targetlayout
%   \else
%     \next
%   \fi}
% \def\target@stop{}
% \def\target@booklet{%
%   \booklet@registers
%   \def\ship@@@leftpage{\save@booklet\@leftpage}%
%   \def\ship@@@rightpage{\save@booklet\@rightpage}%
%   \@leftpagefalse
%   \def\twoup@eject{\twoup@eject@booklet}%
%   \expandafter\process@targetlayout}
% \def\target@Booklet{%
%   \def\booklet@@loop{\Booklet@@loop}%
%   \target@booklet}
% \def\target@twosided{%
%   \@twosidedtrue
%   \expandafter\process@targetlayout}
% \def\target@topbottom{%
%   \def\make@@halfpage{\make@@halftopbottom}%
%   \def\make@fullpage{\make@fulltopbottom}%
%   \@sidebysidefalse
%   \expandafter\process@targetlayout}
% \def\target@dvidvi{%
%   \def\ship@@@leftpage{\ship@dvidvi\@leftpage}%
%   \def\ship@@@rightpage{\ship@dvidvi\@rightpage}%
%   \expandafter\process@targetlayout}
% %
% % TeX's \shipout primitive is saved as \&normal@shipout, and then \shipout
% % is defined to save each page to \@leftpage or \@rightpage and to print out
% % every two. With the twosided layout, filler pages are added when needed.
% \expandafter\let\csname &normal@shipout\endcsname\shipout
% \def\shipout{%
%   \if@leftpage
%     \global\@leftpagefalse
%     \def\next{\afterassignment\ship@leftpage\global\setbox\@leftpage=}%
%     \if@twosided
%       \ifodd\count\z@
%         \global\setbox\@leftpage=\hbox{}%
%         \make@@halfpage\@leftpage\ship@@@leftpage
%         \def\next{\shipout}%
%       \fi
%     \fi
%   \else
%     \global\@leftpagetrue
%     \def\next{\afterassignment\ship@rightpage\global\setbox\@rightpage=}%
%     \if@twosided
%       \ifodd\count\z@
%       \else
%         \global\setbox\@rightpage=\hbox{}%
%         \make@@halfpage\@rightpage\ship@@@rightpage
%         \def\next{\shipout}%
%       \fi
%     \fi
%   \fi
%   \next}
% %
% % The job of \ship@leftpage and \ship@rightpage is to invoke \ship@@leftpage
% % or \ship@@rightpage at the right time. \shipout is followed either
% % (i) by an \hbox, \vbox or \vtop, in which case \ship@leftpage is invoked
% % after the opening {. \@leftpage is void, and \ship@leftpage invokes
% % \ship@@leftpage after the closing }, or
% % (ii) by a \box or \copy, in which case \ship@leftpage is invoked after
% % the full assignment. \@leftpage is not voide, and \ship@leftpage invokes
% % \ship@@leftpage immediately.
% \def\ship@leftpage{%
%   \ifvoid\@leftpage\aftergroup\ship@@leftpage\else\ship@@leftpage\fi}
% \def\ship@rightpage{%
%   \ifvoid\@rightpage\aftergroup\ship@@rightpage\else\ship@@rightpage\fi}
% %
% % \ship@@leftpage/\ship@@rightpage take the output box, and first make it
% % into a fully-size source page (with \make@halfpage) and then this is
% % centered horizontally and vertically in half of a target page (with
% % \make@@halfpage). Then they are shipped individually or together.
% \def\ship@@leftpage{\make@halfpage\@leftpage\ship@@@leftpage}
% \def\ship@@rightpage{\make@halfpage\@rightpage\ship@@@rightpage}
% \def\make@halfpage#1{%
%   \dp#1=\z@
%   \setbox#1=\vbox to\@sourceheight{%
%     \vskip \inv@sourcemag in
%     \vskip \voffset
%     \hbox to\@sourcewidth{\hskip\inv@sourcemag in\hskip\hoffset\box#1\hss}%
%     \vss}%
%   \make@@halfpage#1}
% %
% % The definition of \make@@halfpage depends on the target layout.
% \def\make@@halfsidebyside#1{%
%   \global\setbox#1=\vbox to\@targetheight{\vss
%     \hbox to.5\@targetwidth{\hss\box#1\hss}\vss}}
% \def\make@@halftopbottom#1{%
%   \global\setbox#1=\vbox to.5\@targetheight{\vss
%     \hbox to\@targetwidth{\hss\box#1\hss}\vss}}
% \def\make@@halfpage{\make@@halfsidebyside}
% %
% % The pages are generaly shipped in pairs:
% \def\ship@twoup{%
%   \begingroup
%     \voffset=-\inv@targetmag in
%     \hoffset=\voffset
%     \global\advance\@physicalpage by 1
%     \count\z@=\@physicalpage
%     \csname &normal@shipout\endcsname\make@fullpage
%   \endgroup}
% \let\ship@@@leftpage\relax
% \def\ship@@@rightpage{\ship@twoup}
% %
% % The definition of \make@fullpage depends on the layout:
% \def\make@fullsidebyside{%
%   \hbox{\box\@leftpage\pagesep@sidebyside\box\@rightpage}}
% \def\make@fulltopbottom{%
%   \vbox{\offinterlineskip\box\@leftpage\pagesep@topbottom\box\@rightpage}}
% \def\make@fullpage{\make@fullsidebyside}
% %
% % A vertical or horizontal rule can be inserted. These can be redefined
% % for other tricks:
% \def\pagesep@sidebyside{%
%   \begingroup
%     \advance\pageseplength by \pagesepoffset
%     \pagesepwidth=\inv@targetmag\pagesepwidth
%     \kern -.5\pagesepwidth
%     \vrule height \inv@targetmag\pageseplength
%            depth -\inv@targetmag\pagesepoffset
%            width \pagesepwidth
%     \kern -.5\pagesepwidth
%   \endgroup}
% \def\pagesep@topbottom{%
%   \begingroup
%     \pagesepwidth=\inv@targetmag\pagesepwidth
%     \vskip -.5\pagesepwidth
%     \moveright\inv@targetmag\pagesepoffset\hbox{%
%       \vrule height\pagesepwidth width\inv@targetmag\pageseplength}%
%     \vskip -.5\pagesepwidth
%   \endgroup}
% %
% % With the dvidvi layout, the pages are shipped individually:
% \def\ship@dvidvi#1{%
%   \begingroup
%     \voffset=-\inv@targetmag in
%     \hoffset=\voffset
%     \csname &normal@shipout\endcsname\box#1%
%   \endgroup}
% %
% % With the booklet or Booklet layout, the pages are saved rather than
% % shipped.
% \begingroup
% \let\newbox\relax
% \gdef\save@booklet#1{%
%   \begingroup
%     \globaldefs=1
%     \advance\bookletpage by 1
%     \expandafter\newbox\csname bookletbox\the\bookletpage\endcsname
%     \expandafter\setbox\csname bookletbox\the\bookletpage\endcsname\box#1%
%   \endgroup}
% \endgroup
% %
% % The pages are then printed at the end with the following macros:
% \def\make@bookletpage#1{%
%   \setbox\ifodd#1\@rightpage\else\@leftpage\fi=%
%     \expandafter\box\csname bookletbox\the#1\endcsname}
% \def\booklet@loop{%
%   \count\z@\rightpagenumber
%   \make@bookletpage\leftpagenumber
%   \make@bookletpage\rightpagenumber
%   \ship@twoup
%   \booklet@@loop}
% \def\booklet@@loop{%
%   \advance\rightpagenumber by 2
%   \advance\leftpagenumber by -2
%   \ifnum\leftpagenumber<1\else\expandafter\booklet@loop\fi}
% \def\Booklet@@loop{%
%   \advance\rightpagenumber by 1
%   \advance\leftpagenumber by -1
%   \ifnum\leftpagenumber<\rightpagenumber\else\expandafter\booklet@loop\fi}
% %
% % This one is easy:
% \def\twoupemptypage{\shipout\hbox{}}
% %
% % This clears a whole target page if there is a saved left page. Note that
% % this does not invoke the output routine; i.e., it is not like \clearpage
% % or \supereject. See \twoupclearpage and \twoupeject below.
% \def\twoup@eject{%
%   \if@leftpage\else
%     \global\setbox\@rightpage\hbox{}%
%     \make@@halfpage\@rightpage\ship@@@rightpage
%     \global\@leftpagetrue
%   \fi}
% %
% % This is the definition of \twoup@eject with the booklet option:
% \def\twoup@eject@booklet{%
%   \leftpagenumber\bookletpage
%   \advance\leftpagenumber by 3
%   \divide\leftpagenumber by 4
%   \multiply\leftpagenumber by 4
%   \rightpagenumber=1
%   \ifnum\leftpagenumber>\bookletpage
%     \setbox\@leftpage\hbox{}%
%     \make@@halfpage\@leftpage
%     \loop
%       \setbox\@rightpage\copy\@leftpage
%       \save@booklet\@rightpage
%     \ifnum\leftpagenumber>\bookletpage
%     \repeat
%   \fi
%   \booklet@loop}
% %
% % This modification is needed for \LaTeX in order to get the last page
% % printed out if the final page is a left page (the catcode business is
% % because \enddocument is \let to \bye in amstex):
% \begingroup
% \expandafter\ifx\csname @latexerr\endcsname\relax
%   \catcode`\>=14\else\catcode`\>=9\fi\relax
% >>\gdef\twoupclearpage{\clearpage\twoup@eject}
% >>\expandafter\@temptokena\expandafter{\enddocument}
% >>\xdef\enddocument{\noexpand\twoupclearpage\the\@temptokena}
% \endgroup
% %
% % For most other macro packages we could just leave be and all pages would
% % always be printed because of the way the \end primitive works (except that
% % TeX will go bonkers with the booklet layout). However,
% % sometimes a blank filler page would be printed *with* headings. We prefer
% % the filler page to be truly blank. To achieve this,  we hack the definition
% % of \end. This may cause problems with some macros.
% \expandafter\ifx\csname @latexerr\endcsname\relax
%   \let\twoup@@@end\end
%   \def\end{\twoup@eject\twoup@@@end}
%   \def\twoupeject{\par\vfil\supereject\twoup@eject}
% \fi
% %
% % This is one workaround for the page cross-references problem
% \def\TwoupWrites{%
%   \let\TwoupSaved@write\write
%   \let\TwoupSaved@read\read
%   \let\TwoupSaved@openout\openout
%   \let\TwoupSaved@closeout\closeout
%   \def\write{\TwoupSaved@write-1{}\immediate\TwoupSaved@write}%
%   \def\read{\TwoupSaved@write-1{}\immediate\TwoupSaved@read}%
%   \def\openout{\TwoupSaved@write-1{}\immediate\TwoupSaved@openout}%
%   \def\closeout{\TwoupSaved@write-1{}\immediate\TwoupSaved@closeout}%
%   \let\TwoupWrites\relax}
% %
% %  Defaults:
% \def\twouparticle{%
%   \target{\magstepminus1}{11in}{8.5in}%
%   \source{\magstep0}{8.5in}{11in}}
% \def\twoupplain{%
%   \target{\magstepminus2}{11in}{8.5in}%
%   \source{\magstep0}{8.5in}{11in}}
% \def\twouplegaltarget{%
%   \target{\magstepminus1}{14in}{8.5in}%
%   \source{\magstep0}{8.5in}{11in}}%
% \def\twouplandscape{%
%   \target{\magstepminus2}{8.5in}{11in}%
%   \source{\magstep0}{11in}{8.5in}%
%   \targetlayout{topbottom}}
% \expandafter\ifx\csname @latexerr\endcsname\relax
%   \twoupplain\else\twouparticle\fi
% \pagesepwidth 0pt
% \pageseplength 6.5in
% \pagesepoffset 1in
% %
% \expandafter\catcode`\@=\TheAtCode\relax
% \endinput
% %% END 2up.tex/2up.sty
% 
% \end{verbatim}
%
%
% \section{The documentation for 2up} \label{sec:2updoc}
%
%    Following is an almost verbatim copy of the documentation for Timothy
% Van Zandt's \Lpack{2up}. I hope that by including this I have 
% now completely met his COPYING conditions. The only change that
% I have made to the original is replacing every occurrence of `|{verbatim}|'
% by `|{verbtm}|', so LaTeX does not get confused when processing the
% current document.
%
% \begin{verbatim}
% 
% %% BEGIN 2up.doc
% %%
% %% Documentation for 2up.tex/2up.sty.
% %% Run through LaTeX, with or without the NFSS.
% %%
% %% See below if you want to try out two-up printing.
% %%
% %% LaTeX version of this documentation courtesy of
% %%    H. David Todd <hdtodd@mockingbird.wesleyan.edu>
% %%
% %%
% \documentstyle[12pt,twoside]{article}
% 
% \def\FileDate{January 28, 1993}
% \def\FileVersion{1.2}
% 
% %% INSTRUCTIONS FOR TWO-UP PRINTING.
% %% 1. Change \iffalse below to \iftrue.
% %% 2. Uncomment \special{landscape} if using Rokicki's dvips, or otherwise
% %%      remember to print the document out in landscape mode.
% %% 3. Uncomment one of the booklet options, if desired.
% %%
% \iffalse
%   \input 2up.tex
%   \targetlayout{twosided}
%   \TwoupWrites
%   % \special{landscape}     %% This works with Rokicki's dvips
%   % \targetlayout{Booklet}  %% Booklet printing with 2-sided printer/copier.
%   % \targetlayout{booklet}  %% Booklet printing with 1-sided printer/copier.
% \fi
% 
% \makeatletter
% 
% %% PAGE NUMBERING:
% %% Adjust page numbering if using booklet layout option.
% \setcounter{page}{0}
% \def\next{\if@leftpage\else\stepcounter{page}\fi}
% \@ifundefined{target@stop}{}{\next}
% 
% %% CONTENTS:
% \def\tableofcontents{%
%   \par\begin{center}
%   \large\bf Contents
%   \end{center}
%   \begin{quote}\@starttoc{toc}\end{quote}}
% 
% %% PAGE PARAMETERS:
% \setlength{\parindent}{0pt}          % paragraph indent
% \setlength{\parskip}{4pt plus 1pt minus 1pt}
% \setlength{\topmargin}{0pt}
% \setlength{\headheight}{12pt}        % height of running head
% \setlength{\headsep}{30pt}           % distance between header and text
% \setlength{\textheight}{8.2in}        % height of text on page
% 
% %% DATES, VERSIONS AND TITLES:
% \def\@maketitle{%
%  \begin{center}
%    {\Large\bf \@title \par}
%    \vskip 1.2em {\lineskip .5em
%    \begin{tabular}[t]{c}\@author\end{tabular}\par}
%    \vskip .8em {\@date}%
%   \end{center}
%   \par
%   \vskip .5em}
% 
% %% Page Style:
% \pagestyle{myheadings}
% \markboth{Two-Up Style Guide}{Version \FileVersion, \FileDate}
% 
% %% Special list:
% \newcommand{\namelistlabel}[1]{\mbox{\bf #1}\hfil}
% \newenvironment{namelist}[1]%
%   {\begin{list}{}%
%     {\let\makelabel\namelistlabel
%     \settowidth{\labelwidth}{#1}
%     \setlength{\leftmargin}{1.1\labelwidth}}}%
%  {\end{list}}
% 
% %% VERBATIM:
% %%
% \begingroup
%   \catcode`\{=12 \catcode`\}=12
%   \catcode`\(=1 \catcode`\)=2
%   \catcode`\+=0 \catcode`\\=12
%   +gdef+|(\)          % \| = character \
%   +gdef+{({)          % \{ = character {
%   +gdef+}(})          % \} = character }
% +endgroup
% \def\Backslash{\protect\|}
% %%
% %% Define some functional font commands:
% %%
% \def\MainFont{\tt}      % For macro definitions.
% \def\UsageFont{\tt}           % For in-line macro names.
% \def\InlineFont{\tt}          % For other in-line snipets of code.
% \def\MetaFont{\rm\it}            % For meta arguments.
% %%
% %% Short-cuts for font commands:
% %%
% \def\s#1{\string#1}
% \def\t#1{{\InlineFont\string#1}}   % For other in-line code.
% \def\m#1{{\MetaFont #1\/}}         % For just putting things in italics
% \def\M#1{{\InlineFont\{\m{#1}\}}}  % Arg is in italic, enclosed in tt braces.
% \let\N\t                           % For in-line macro names.
% \catcode`\<=13 \def<#1>{\m{#1}}    % <meta>
% \catcode`\"=13\def"{\verb"}        % Short verb
% %%
% %% This is for listing macro definitions in a quote-like environment.
% %%
% \begingroup
%   \catcode`\[=1 \catcode`\]=2
%   \catcode`\{=13 \catcode`\}=12
%   \gdef\@MD[%
%     \catcode`\{=13 \catcode`\}=12
%     \def{##1}[\{[\MetaFont ##1]\}]]
% \endgroup
% \def\MD{%
%   \quote
%   \begingroup
%     \@MD
%     \def\end{\endgroup\end}%
%     \def\\{\@centercr\s}%
%     \MainFont
%     \s}
% \def\endMD{\endquote}
% %%
% 
% %% End preamble.
% \catcode`\@=12
% 
% \begin{document}
% 
% \title{Documentation for 2up.tex:\\
%   Two-up printing for Generic TeX}
% \author{Timothy Van Zandt\thanks{The documentation was put into
%   \LaTeX\ format by David Todd.}\\ tvz@Princeton.EDU}
% \date{Version \FileVersion\\[3pt] \FileDate}
% 
% \maketitle
% \thispagestyle{empty}
% 
%   "2up.tex"/"2up.sty" allows one to print a document two-up, with
% considerable flexibility as to paper size and layout. It produces a standard
% dvi file, and does not involve an additional dvi or PostScript filter. It
% should work with most \TeX\ macro packages.
% 
%   {\bf Usage:} Input "2up.tex", or include "2up" as a LaTeX style option.
% There is a good chance you will get the desired layout. (But you will probably
% need to generate new font bitmaps to get high quality output.) See the rest of
% this documentation for detailed information on controlling 2up.tex.
% 
% \begingroup
% \def\baselinestretch{.8}\large\normalsize
% \tableofcontents
% \endgroup
% \clearpage
% 
% \section{Comparison with other methods}
% 
% There are other tools for two-up printing:
% \begin{description}
% \item[PostScript filters]
% These work well as long as you only use PostScript fonts (as opposed to the
% usual Metafont fonts). Otherwise, the PostScript filter scales bitmapped
% fonts, and the quality is lower than with "2up.tex".
% 
% \item[Rokicki's dvidvi]
% "dvidvi" is a versatil tool that does much more than
% 2up printing. However, if only rearranges the pages, and does not adjust the
% magnification to ensure that the pages fit properly in a two-up format. It
% also adds one more step to the \TeX-dvi-printer cycle. "2up.tex", on the other
% hand, combines the changes to \TeX's magnification and page layout with the
% rearranging of the pages, all with an easy-to-use interface and from within
% your \TeX\ document. (See Section \ref{dvidvi} on using both "2up.tex" and
% "dvidvi" together.)
% \end{description}
% 
% \section{A warning about fonts}
% 
% Two-up printing generally involves reducing a document, and thus using fonts
% sizes that are not typically found on your system. If you are using bitmapped
% fonts (standard for \TeX\ users), and you do not have and cannot generate the
% extra fonts bitmaps, you will find 2up.sty (and any other method of two-up
% printing) to give very poor quality output.
% 
% If you are using a program like Rokicki's "dvips" that can generate extra font
% bitmaps as needed, you will find that it takes a long time to print your 2up
% document the first few times, as "dvips" is busy making the extra fonts. This
% problem will go away. Be thankful you have such an easy way to get extra font
% bitmaps.
% 
% \section{Usage}
% 
% Input "2up.tex". \LaTeX\ users can include "2up" as a style option.
% 
% Then set the target and source layout:
% \begin{MD}
%   \source{mag}{width}{height}\\
%   \target{mag}{width}{height}
% \end{MD}
% 
% \begin{itemize}
% \item 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.
% 
% \item <width> and <height> are the true width and height of the paper,
% when looking at the output right-side-up.
% 
% \item <mag> refers to the source and target magnification. It should be an
% integer, equal to 1000 times the magnification factor. There are also some
% magic magnification numbers:
% \begin{description}
% \item[$\setminus$magstep<n>] for a magnification of 1.2$^n$ (n=0,...,5), or
% 
% \item[$\setminus$magstepminus<n>] for a magnification of 1.2$^{-n}$
% (n=0,...,5).
% \end{description}
% Using these magnification values will make best use of the available fonts on
% your system.
% \end{itemize}
% 
% "2up.tex" takes each source page, and centers in half a target page. To get
% the pages to fit, the magnification of the document typically has to be
% reduced. If you find that the pages are too crowded, try reducing the target
% magnification. If they are too lonely, try increasing the target
% magnification.
% 
% If you want to adjust the positioning of the scaled pages, try changing the
% values of "\hoffset" or "\voffset" with "\advance" or \LaTeX's "\addtolength".
% 
% Don't change the magnification of your document after using the "\target"
% command, as you will override the settings made by 2up.tex.
% 
% You can also specify some options:
% \begin{MD}
%   \targetlayout{options}
% \end{MD}
% where <options> is a comma separated list with no spaces. Valid
% options are:
% \begin{namelist}{topbottomxxx}
% 
% \item [topbottom] The two source pages are printed one on top of the other.
% \item [twosided]  Odd pages are always printed on the right or the bottom.
% \item [booklet]   Pages are printed like a booklet. See Section \ref{booklet}.
% \item [Booklet]   Like "booklet", but for two-sided printers/copiers.
% \item [dvidvi]    For arranging in two-up layout with "dvidvi". See Section
% \ref{dvidvi}.
% 
% \end{namelist}
% 
% The only other changes you might want to make to your document are the
% following:
% \begin{itemize}
% \item You have to see to it that the target output is printed with the
% correct orientation (landscape or portrait). See the documentation for your
% dvi driver for details.
% 
% \item "2up.tex" will inserts a line between pages if you change the following
% dimensions:
% \begin{namelist}{pagesepwidthxxx}
% \item [$\setminus$pagesepwidth]   Thickness of line. (Default 0pt)
% \item [$\setminus$pageseplength]  Length of line. (Default 6.5in)
% \item [$\setminus$pagesepoffset]  Distance from bottom of page to bottom of
% line, or (with "topbottom" layout) from side of page to beginning of line.
% (Default 1in)
% \end{namelist}
% 
% \item You can, but do not need to, use the following commands:
% \begin{namelist}{twoupemptypagexxx}
% 
% \item [$\setminus$twoupemptypage] inserts a completely blank half page
% in the target.
% 
% \item [$\setminus$twoupclearpage] \LaTeX\ users: ejects a complete target
% page.
% 
% \item [$\setminus$twoupeject] Plain \TeX users: ejects a complete target
% page.
% 
% \end{namelist}
% \end{itemize}
% 
% \section{Defaults}
% 
%   The following commands set the parameters for some common sources and
% targets. The definitions of these commands are also useful examples.
% 
%   For A4 paper, just replace "8.5in" and "11in" in the definitions below by
% the width and height of A4 paper.
% 
% \begin{description}
% 
% \item [$\setminus$twouparticle]
% 
% This is the default for \LaTeX.
% \begin{namelist}{Sourcexx}
% 
% \item [Source:] A portrait document on 8.5x11 inch paper with wide margins as
% used in \LaTeX's article style, and without marginal notes.
% 
% \item [Target:] A landscape document on the same size paper, with the source
% pages printed side by side.
% 
% \item [Definition:]\hspace{1pt}
% \begin{verbtm}
% \target{\magstepminus1}{11in}{8.5in}
% \source{\magstep0}{8.5in}{11in}}
% \end{verbtm}
% \end{namelist}
% 
% If you use narrower side margins, or if you use marginal notes, then you
% will need to use "\twoupplain" or \\ "\twouplegaltarget", defined below.
% 
% \item [$\setminus$twoupplain]
% 
% This is the default for non-\LaTeX.
% 
% It is the same as "\twouparticle", but for source documents with narrower
% margins.
% \begin{namelist}{Sourcexxx}
% 
% \item [Definition:]\hspace{1pt}
% \begin{verbtm}
% \target{\magstepminus2}{11in}{8.5in}
% \source{\magstep0}{8.5in}{11in}
% \end{verbtm}
% \end{namelist}
% 
% \item [$\setminus$twouplegaltarget]
% 
% \begin{namelist}{Sourcexxx}
% \item [Source:] A portrait document on 8.5x11 inch paper with just about any
% margins and perhaps with marginal notes.
% 
% \item [Target:] A landscape document on legal size paper (8.5x14 inches),
% with the source pages printed side by side.
% 
% \item [Definition:]\hspace{1pt}
% \begin{verbtm}
% \target{\magstepminus1}{14in}{8.5in}
% \source{\magstep0}{8.5in}{11in}\
% end{verbtm}
% \end{namelist}
% 
% \item [$\setminus$twouplandscape]\hspace{1pt}
% \begin{namelist}{Sourcexxx}
% 
% \item [Source:] A landscape document on 8.5x11 inch paper with just about any
% margins.
% 
% \item [Target:] A portrait document on the same size paper, with the
% source pages stacked vertically.
% 
% \item [Definition:]\hspace{1pt}
% \begin{verbtm}
% \target{\magstepminus2}{8.5in}{11in}
% \source{\magstep0}{11in}{8.5in}
% \targetlayout{topbottom}
% \end{verbtm}
% \end{namelist}
% 
% \end{description}
% 
% 
% \section{True Dimensions}
% 
% \TeX\ lets you use `true' dimensions, as in
% \begin{verbtm}
%     \topmargin 1truein
%     \setlength{\topmargin}{1truein}
% \end{verbtm}
% This sets the length to 1 inch
% as it appears on the page, no matter what the magnification.
% 
% Once you use `true' dimensions, it is impossible to change the
% magnification of your document, and hence it is almost impossible
% to use 2up.tex. You will get an error like:
% \begin{verbtm}
%     ! Incompatible magnification (833);
%       the previous value will be retained (2000).
% \end{verbtm}%
% 
% The use of `true' dimensions might be hiding in macros or style files
% you are using. For example, Plain \TeX's "\magnification" command uses
% true dimensions; use "\mag" instead, and then set "\hsize" and
% "\vsize" appropriately scaled. If you can't find the culprit `true'
% dimension in your document or input files, try putting this on the
% (very) first line of your document:
% \begin{verbtm}
%     \mag 143 \voffset 1truein \mag 1000
% \end{verbtm}
% 
% You will get the error listed above wherever true dimensions are used
% (and in some other places as well).
% 
% 
% \section{Page Cross-References}
% 
%   Page cross-references (e.g., in an index or table of contents) will not be
% accurate with "2up.tex", because finished pages are not immediately shipped
% out. This can also cause problems with some special \LaTeX\ styles that have
% multiple ".aux" files (e.g., for each chapter).
% 
%   To get better, but not perfect, page cross-references, try putting the
% command
% \begin{verbtm}
%     \TwoupWrites
% \end{verbtm}
% at the beginning of your document, after inputting "2up.tex". This is good for
% drafts, and may fix problems with \LaTeX\ styles that have multiple ".aux"
% files. "\TwoupWrites" makes "\write" and "\read" "\immediate", if you know
% what that means. It might cause problems of its own, but try it and see.
% 
%   To get accurate page cross-references:
% \begin{enumerate}
% \item Run the job without "2up.tex", until all cross-references
% are properly resolved. Run any index utility at this point.
% 
% \item Run the job ONE MORE TIME with "2up.tex"; it will use the
% correct cross-references from the previous runs. (In \LaTeX\ documents,
% it is useful at this point to include the "\nofiles" command, so that
% the correct cross-references are preserved.)
% \end{enumerate}
% 
% \section{Booklets\label{booklet}}
% 
% Here are some special considerations for making booklets:
% 
% \begin{itemize}
% 
% \item  Use the "booklet" target layout if your printer or copier cannot print
% two
% sides directly. "2up.tex" prints out the ``tops'' of the pages, and then the
% ``bottoms'', so that you can copy or print on both sides by doing one side,
% flipping the output over, and doing the other side.
% 
% \item Use "Booklet" if your printer or copier can print directly on two sides.
% 
% \item You must have enough memory and box registers to hold all the pages in
% the document. A Big\TeX\ should be able to handle at least a 32-page booklet.
% 
% \item Sometimes booklet printing is part of the design of a document, rather
% than an afterthought. In this case, you should set up the margins for the
% target half-page rather than using "2up.tex" to scale the document. For
% example, if using \LaTeX, 8.5x11 inch paper, \LaTeX's twoside style option,
% and headings, try the following page parameter changes:
% \begin{verbtm}
%     \setlength{\oddsidemargin}{-0.2in}
%     \setlength{\evensidemargin}{-0.5in}
%     \setlength{\textwidth}{4.2in}
%     \setlength{\textheight}{6.5in}
%     \setlength{\topmargin}{-.4in}
% \end{verbtm}
% If you do this, "2up.tex" isn't adjusting margins or scaling the
% document. You coould therefore get by without "2up.tex" by using "dvidvi".
% \end{itemize}
% 
% \section{Using dvidvi\label{dvidvi}}
% 
%   With the "dvidvi" layout option, "2up.tex" takes care of adjusting the
% margins, and you then use "dvidvi" to arrange the pages in a two-up
% format. The advantage is that cross referencing comes out right.
% The disadvantage is that it involves one more step.
% 
% Start by \TeX ing your document with "2up.tex" and the "dvidvi" layout option.
% Then run the dvi file through "dvidvi". Specify the offsets for "dvidvi" at
% the middle of the page. E.g., for
% a side-by-side layout on 8.5x11in paper, use
% \begin{verbtm}
%     dvidvi '2:0,1(5.5in,0in)' foo bar
% \end{verbtm}
% For other paper sizes, replace "5.5in" by half the target paper width. For the
% "topbottom" layout, reverse the dimensions, e.g.,
% (0in,5.5in). For booklet printing, see the
% the documentation for "dvidvi".
% 
% 
% \section{Compatibility\label{compatibility}}
% 
%   These macros should work with most \TeX\ macro packages, except for
% the following possible but unlikely compatibility problems:
% 
% \begin{itemize}
% 
% \item If you use a macro package other than \LaTeX\ that does unusual things
% to end a document and/or that modifies the definition of "\end", you may
% find that the last page is nor printed or that an extra page with headings
% is inserted at the end of the document. This is fixable on a case-by-case
% basis. See the redefinition of "\end" in "2up.tex".
% 
% \item "2up.tex" might not work if you meddle with \TeX's "\shipout" primitive
% after loading "2up.tex".
% 
% \item If the first page of the source document is not on the first two-up
% target
% page (possible, for example, with two-sided printing and the "booklet"
% option, but generally unlikely), "\special"'s that come at the beginning
% of the document also do not get onto the first page of output. This can mess
% up "\special"'s for landscape printing or
% including a PostScript header file. In this case, you have to specify
% these things as command line options when using your dvi driver.
% 
% \end{itemize}
% 
% 
% \section{Changes}
% \begin{namelist}{V0.9xxx}
% \raggedright
% 
% \item [V0.9a] Everything redone. Too many differences to point out.
% 
% \item [V0.9b] Interface redone again. "booklet" option added.
% 
% \item [V0.9c] Pages ship out a little earlier. A few bugs fixed.
% 
%   Parameters "\pageseplength" and "\pagesepthickness" added.
% 
% \item [V0.9d] Fixed bug with "\twoupclearpage" and "\twoupeject".
% 
% \item [V0.9e] Made pages be counted (from dvi driver's viewpoint) by the
% physical page number.
% 
% \item [V0.9f] Parameter "\pagesepoffset" added, and "\pagesepthickness"
% changed to "\pagesepwidth".
% 
% \item [V1.0]  None. Just seemed seemed like it was time to call it 1.0
% 
% \item [V1.1] Added "Booklet" and "dvidvi" target layouts.
% 
%   "\hoffset" and "\voffset" in source document now have expected effect.
% 
% \item[V1.2] Fixed incompatibility problem with AmS-\TeX/AmS-\LaTeX.
% 
%   Added "\TwoupWrites" command.
% 
% \end{namelist}
% \end{document}
% % END 2up.doc
% 
% \end{verbatim}
%
%    I used a slightly modified version of \file{2up.doc} as one of the
% test documents for the \Lpack{booklet} package. First, to get a baseline,
% I followed the instructions in \file{2up.doc} and edited and printed
% it using \Lpack{2up} to get a booklet.
%
%    I then copied \file{2up.doc} to \file{2updoc.tex} and then edited
% the new file so that the first part of the preamble became:
% \begin{verbatim}
% %% BEGIN 2updoc.tex
% %% ....
% \documentclass[12pt,twoside]{article}
% \usepackage[print,four]{booklet}  % change options to suit
% \usepackage{ifpdf}                % from CTAN
%
% \ifpdf
%   \pdfoutput=1
%   \setpdftargetpages
% \else
%   \checkforlandscape
%   \ifuselandscape
%     \special{dvips}
%     \ifprintoption
%       \special{!TeXDict begin <</Duplex true /Tumble true>> setpagedevice end}
%     \fi
%   \fi
% \fi
% 
% \def\FileDate....
% ...
% \iffalse
%   \input 2up.tex
%   ...
%    % \fi and \makeatletter were here
% %% PAGE NUMBERING:
% ...
% \@ifundefined{target@stop}...
% \fi     % this \fi and \makeatletter moved down from before NUMBERING
% \makeatletter
%
% %% CONTENTS     % no changes after this
% ... 
% \end{verbatim}
%
% Processing, printing and folding this to make a booklet enabled me to
% determine if the package effectively produced the same final result
% as \Lpack{2up}. 
% 
%
% \Finale
% \PrintIndex
%
\endinput

%% \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         \~}