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
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
|
% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
%<*readme>
ABOUT
The StatRep package is a LaTeX package that provides two environments and
two tags that work together to display your SAS code and results and to
generate the SAS program that produces those results. The two environments
(Datastep and Sascode) display SAS code. The two tags (Listing and Graphic)
display SAS output.
The generated SAS program includes calls to macros that use the SAS
Output Delivery System (ODS) document to capture the output as external files.
These SAS macros are included in this package (statrep_macros.sas).
The package is available in two locations:
* http://support.sas.com/StatRepPackage
* http://mirror.ctan.org/macros/latex/contrib/statrep/
The distribution(statrep.zip) consists of the following files:
README.txt (this file)
statrep_macros.sas SAS macro file
statrep_tagset.sas SAS tagset and style for LaTeX tabular output
statrepmanual.pdf StatRep Package User's Guide (pdf)
statrepmanual.tex StatRep Package User's Guide (source)
quickstart.tex Example and tutorial LaTeX file
statrep.dtx Package source file
statrep.ins Install file (for MikTeX Users)
INSTALL
Unzip the file statrep.zip to a temporary directory and
perform the following steps:
Step 1: Install the StatRep SAS Macros
Copy the file statrep_macros.sas to a local directory. If you have a
folder where you keep your personal set of macros, copy the file
there. Otherwise, create a directory such as C:\mymacros and copy
the file into that directory.
Step 2: Install the StatRep LaTeX Package
If you are working with the MikTeX distribution on Windows and it is
configured to download and install packages automatically, you can
skip this step. Otherwise, see these instructions for installing
packages for MikTeX:
http://docs.miktex.org/manual/localadditions.html
The following instructions show how to install the StatRep package in the
TeXLive LaTeX distribution for your personal use. If you maintain a
system-wide LaTeX distribution and you want to make StatRep
available to all users, see more detailed information about how
to install LaTeX packages at
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=what-TDS
a)
Determine the location that LaTeX uses to load packages. From a
command-line prompt, give the following command:
kpsewhich -var-value=TEXMFHOME
The command will return the root directory name in which LaTeX can
find your personally installed packages.
b)
Create the directory if it does not exist and create the additional
subdirectories tex/latex/statrep
Your directory tree will have the following structure:
---------------
root directory/ (given by kpsewhich command in 2a)
tex/
latex/
statrep/
d)
Copy the files statrep.dtx, statrepmanual.pdf, and statrepmanual.tex to
the statrep subdirectory. Your directory tree will have the following structure:
---------------
root directory/ (given by kpsewhich command in 2a)
tex/
latex/
statrep/
statrep.dtx
statrepmanual.pdf
statrepmanual.tex
---------------
e)
Change to the statrep directory and give the following command:
pdflatex statrep.dtx
The command creates several files, one of which is the configuration
file, statrep.cfg.
Step 3: Let the StatRep Package Know the Location of the StatRep SAS Macros
Edit the statrep.cfg file generated in Step 2d so that the macro SRmacropath contains
the correct location of the macro file from step 1. For example, if
you copied the statrep_macros.sas file to a directory named 'C:\mymacros',
then you define macro \SRmacropath as follows:
\def\SRmacropath{c:/mymacros/statrep_macros.sas}
Note the use of the forward slash in the definition. Use the forward slash
as the directory name delimiter instead of the backslash, which is a special
character in LaTeX.
EXPLORE
You can now test and experiment with the package. Create a working
directory and copy the file quickstart.tex into it.
To generate the quickstart document:
1) Compile the document with pdfLaTeX. You can use a LaTeX-aware
editor such as TeXworks or use the command-line command 'pdflatex'.
This step generates the SAS program that is needed to produce the results.
2) Execute the SAS program quickstart_SR.sas, which was automatically
created in the preceding step. This step generates the SAS
results that are requested in the quickstart document.
3) Recompile the document with pdfLaTeX. This step compiles the
quickstart document to PDF, this time including the SAS results
that are generated in the preceding step.
You might need to repeat this step so that LaTeX can re-
measure the listing outputs to ensure that they are framed properly.
Notes: You can make changes to the file with a LaTeX-aware editor
or with any plain-text editor such as NotePad or emacs.
You can read the StatRep User's Guide for complete usage details.
It is included in the file statrepmanual.pdf that you copied
in the installation step 2d.
UNINSTALL
To uninstall the package, delete the statrep directory that you created
in the installation step 2d and remove the SAS macro file statrep_macros.sas
that you copied in Installation step 1.
NOTE
StatRep now includes limited support for SAS ODS LaTeX output.
See the StatRep User's Guide for details.
LICENSE
statrep.dtx
statrep_macros.sas
statrep_tagset.sas
statrepmanual.tex
Copyright (c) 2015 SAS Institute Inc.
Permission is granted to copy, distribute, and/or modify this software
under the terms of the LaTeX Project Public License (LPPL), version 1.3.
This software is provided by SAS Institute Inc. as a service to its users.
It is provided 'as is', without warranty of any kind, either expressed or
implied, including, but not limited to, the implied warranties of
merchantibility and fitness for a particular purpose.
See http://www.latex-project.org/lppl.txt for the details of that license.
This work has the LPPL maintenance status 'maintained'.
The Current Maintainer of this work is Tim Arnold (tim dot arnold at sas dot com).
REQUIREMENTS
pdfLaTeX typesetting engine 1.30 or later
LaTeX packages
verbatim, graphicx, xkeyval, calc, ifthen
SAS 9.2 or later
See the StatRep User's Guide, included with this package, for complete details.
This work consists of the files:
README (this file)
statrep_macros.sas
statrep_tagset.sas
statrepmanual.tex
statrepmanual.pdf
quickstart.tex
statrep.dtx
statrep.ins
statrep.pdf
statrep.sty
statrep.cfg
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
----------------------------------------------------------------
StatRep --- A LaTeX package to generate documentation and a SAS program that
generates the SAS results used in the source document.
The package helps to support reproducible research.
E-mail: tim.arnold@sas.com
----------------------------------------------------------------
\endpreamble
\postamble
Copyright (C) 2015 by SAS Institute Inc. <tim.arnold@sas.com>
This work consists of the files
statrep.dtx,
statrep_macros.sas,
statrep_tagset.sas
statrepmanual.tex,
quickstart.tex
and the derived files
statrep.ins, statrep.cfg, statrep.sty, longfigure.sty,
statrep.pdf,
statrep_macros.sas,
statrepmanual.pdf
\endpostamble
\generate{\file{statrep.sty}{\from{statrep.dtx}{statrep,cfg}}}
\generate{\file{statrep.cfg}{\from{statrep.dtx}{cfg}}}
\generate{\file{longfigure.sty}{\from{statrep.dtx}{longfigure}}}
%</install>
%<install>\endbatchfile
%<*internal>
\generate{\file{statrep.ins}{\from{statrep.dtx}{install}}
}
\nopreamble\nopostamble
\generate{\file{README.}{\from{statrep.dtx}{readme}}}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal>
%<*statrep>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{statrep}[2015/09/15 v1.07 The statrep package]
%</statrep>
%<*driver>
\documentclass[11pt]{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{float}
\restylefloat{figure}
\usepackage{tocloft}
\usepackage[lined,boxed,linesnumbered]{algorithm2e}
\usepackage{parskip}
\usepackage{xspace}
\usepackage{framed}
\usepackage{xcolor}
\definecolor{shadecolor}{rgb}{0.8,0.9,1}
\definecolor{lightblue}{rgb}{0.93,0.95,1.0}
\definecolor{darkblue}{rgb}{0,0,0.6}
\usepackage{mathptmx}
\usepackage{upquote}
\usepackage[numbered]{hypdoc}
\usepackage{statrep}
\newcommand*{\Statrep}{\textsf{StatRep}\xspace}
\newcommand*{\Sasoption}{\marginpar{\hfill\emph{SAS option}}}
\DeclareTextFontCommand{\Code}{\ttfamily\bfseries}
\uchyph=0
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{statrep.dtx}
\end{document}
%</driver>
%\fi
%\def\filename{statrep.dtx}
%\def\fileversion{1.07}
%\def\filedate{\today}
%\CheckSum{2172}
%\StopEventually{\PrintChanges\PrintIndex}
%
% \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 \~}
%
%
%\changes{v1.0}{2011/11/15}{Initial version}
%\changes{v1.01}{2012/05/23}{Updated README for MikTeX users}
%\changes{v1.02}{2014/06/16}{Added options for graphtype and odsgraphopts}
%\changes{v1.03}{2014/06/19}{Added support for PDF graphics}
%\changes{v1.04}{2014/09/08}{Fixed ligatures appearing in Listings}
%\changes{v1.05}{2014/10/27}{Added support SAS-generated LaTeX table output}
%\changes{v1.06}{2015/01/15}{Added support for root directory specification}
%\changes{v1.07}{2015/09/15}{Fixed bug with losing margins after an output}
%\GetFileInfo{statrep.sty}
%
%
%\DoNotIndex{\.,\@auxout,\@height,\^,\addcontentsline,\addvspace,\arabic,\bfseries}
%\DoNotIndex{\boolean,\DeclareOptionX,\do,\dospecials,\hskip,\hoffset,\insert,\label}
%\DoNotIndex{\LaTeX,\leftskip,\loop,\ProcessOptionsX,\real,\repeat,\stepcounter}
%\DoNotIndex{\@@Function,\@@endpbox,\@@startpbox,\@Function,\@M,\@Mi,\@acol}
%\DoNotIndex{\%,\@@endpbox,\@@startpbox,\@M,\@Mi,\@acol,\@arraycr}
%\DoNotIndex{\@arrayparboxrestore,\@arstrut,\@arstrutbox,\@cclv,\@classiv}
%\DoNotIndex{\@classz,\@colht,\@colroom,\@depth,\@ehc,\@endpbox,\@finalstrut}
%\DoNotIndex{\@firstofone,\@footnotetext,\@getpen,\@gobble,\@gtempa,\@ifnextchar}
%\DoNotIndex{\@ifstar,\@ifundefined,\@let@token,\@lowpenalty,\@makecol,\@makeother,\@medpenalty}
%\DoNotIndex{\@mkpream,\@mparbottom,\@ne,\@outputpage,\@preamble,\@sharp,\@spaces}
%\DoNotIndex{\@startpbox,\@tabacol,\@tabarray,\@tabclassiv,\@tabclassz,\@tabularcr}
%\DoNotIndex{\@testopt,@twocolumntrue,\@undefined,\@width,\@xargarraycr,\@xdblarg}
%\DoNotIndex{\@yargarraycr,\\,\^,\2,\9,\advance,\aftergroup,\arabic\arrayrulewidth}
%\DoNotIndex{\arraystretch,\begin,\begingroup,\bgroup,\bigskipamount,\bgroup}
%\DoNotIndex{\bigskipamount,\box,\break,\c@footnote,\c@LF@chunks,\c@LFchunksize,\c@page}
%\DoNotIndex{\cloeout,\col@number,\col@sep,\copy,\count@,\cr,\crcr,\csname,\def}
%\DoNotIndex{\define@boolkeys,\define@cmdkeys,\dimen@,\dimen@ii,\doublerulesep}
%\DoNotIndex{\dp,\edef,\egroup,\else,\end,\endcsname,\endgraf,\endgroup,\endinput}
%\DoNotIndex{\endLFfirsthead,\endLFfoot,\endLFhead,\endLFlastfoot,,\equal,\everycr}
%\DoNotIndex{\expandafter,\extrarowheight,\fi,\fill,\footins,\footnotetext,\futurelet}
%\DoNotIndex{\gdef,\global,\halign,\hbadness,\hbox,\hfil,\hfill,\hline,\hrule}
%\DoNotIndex{\hsize,\ht,\if,\if@filesw,\if@twocolumn,\ifcase,\ifdim,\ifhbox,\ifhmode,\iffalse,\ifnum}
%\DoNotIndex{\ifthenelse,\ifvoid,\ifx,\immediate,\isert,\itemsep,\itshape,\kern,\kill}
%\DoNotIndex{\lastbox,\leaders,\let,\LF@@hl,\LF@@hline,\LF@@save@row,\LF@@tabarray}
%\DoNotIndex{\LF@array,\LF@argtabularcr,\LF@bchunk,\LF@blank@row,\LF@build@blank,\LF@cols,\LF@crcr}
%\DoNotIndex{\LF@def@row,\LF@echunk,\LF@end@hd@ft,\LF@end@pen,\LF@endpbox,\LF@entry}
%\DoNotIndex{\LF@entry@chop,\LF@entry@write,\LF@err,\LF@final@warn,\LF@get@widths}
%\DoNotIndex{\LF@kill,\LF@lastfoot,\LF@LL@FM@cr,\LF@max@sel,\LF@mcol,\LF@n@fcols}
%\DoNotIndex{\LF@no@pgbk,\LF@nofcols,\LF@ntabularcr,\LF@old@row,\LF@output,\LF@p@ftn}
%\DoNotIndex{\LF@p@ftntext,\LF@rebox,\LF@rows,\LF@save@row,\LF@sep,\LF@setprevdepth}
%\DoNotIndex{\LF@startpbox,\LF@t@bularcr,\LF@tabularcr,\LF@warn,\LF@xtabularcr}
%\DoNotIndex{\LFchunksize,\LFlistoffalse,\LFlistoftrue,\LFoutfile,\LFpost,\LFpre}
%\DoNotIndex{\LFright,\LF@samefalse,\LF@sametrue,\LFupcase,\lineskip,\m@ne,\m@th}
%\DoNotIndex{\MakeUppercase,\mathchardef,\maxdepth,\maxdimen,\MessageBreak,\multicols}
%\DoNotIndex{\multicolumn,\multispan,\newbox,\newcommand,\newcount,\newcounter,\newdimen}
%\DoNotIndex{\newenvironment,\newif,\newlength,\newpage,\newsavebox,\newskip,\newtoks}
%\DoNotIndex{\newwrite,\noalign,\nobreak,\noexpand,\noindent,\nopagebreak,\number}
%\DoNotIndex{\numberline,\omit,\or,\output,\outputpenalty,\pagebreak,\pagegoal,\pagetotal}
%\DoNotIndex{\par,\parbox,\parsep,\parskip,\partopsep,\penalty,\prevdepth,\protect}
%\DoNotIndex{\ProvidesPackage,\relax,\renewcommand,\romannumeral,\saswfk,\sbox,\savebox}
%\DoNotIndex{\selectfont,\setboolean,\setbox,\setcounter,\setlength,\setlongfigures,\settowidth}
%\DoNotIndex{\sffamily,\space,\strutbox,\tabcolsep,\tabskip,\tabularnewline,\the}
%\DoNotIndex{\thetable,\topsep,\ttfamily,\tw@,\unhbox,\unskip,\unvbox,\vbox,\vfil}
%\DoNotIndex{\vrule,\vsize,\vskip,\vspace,\vsplit,\vfuzz,\vss,\vtop,\wd,\write,\x,\xdef}
%\DoNotIndex{\z@}
%\DoNotIndex{\@empty,\@tempa,\@tempboxa,\@tempdima,\@twocolumntrue,\baselineskip}
%\DoNotIndex{\c@LF@tables,\detokenize,\hss,\LF@c@ption,\LF@capti@n,\LF@firsthead}
%\DoNotIndex{\LF@foot,\LF@head,\LF@hline\LF@make@row,\LF@name,\LF@start,\LFcounter}
%\DoNotIndex{\LFProcessOptions,\RequirePackage,\string,\SR@outkey,\SR@outval,\usebox}
%
%\title{The \textsf{statrep} package\thanks{This document corresponds
%to \textsf{statrep}~\fileversion, last revised \filedate.}}
%\author{Tim Arnold and Warren F. Kuhfeld\\SAS Institute Inc.\\\texttt{tim.arnold@sas.com}\\\texttt{warren.kuhfeld@sas.com}}
%\date{\filedate}
%\maketitle
%\iffalse
%<*statrep>
%\fi
% \tableofcontents\listoffigures
% \section{About This Document}
% This document uses the following aids for presenting information.
% \begin{itemize}
% \item The verbatim font (\Code{example text}) is used for names of variables,
% macros, and environments.
%
% \item Hyperlinks are displayed in \textcolor{red}{red}.
% \item Figures are displayed with a light blue background.
%\item Macro names are given in the margin near where the macro is defined or described.
% \item The index contains terms with pointers to the code lines.
% \end{itemize}
% \section{\Statrep Usage}
% \index{statrep package|usage}
% To use the \Statrep package, add the \cs{usepackage} command to your document preamble after you
% declare the \Code{documentclass}.
%
% Figure \ref{fig:usage} shows an example of using the \Statrep package and
% specifying two of its three options.
% \iffalse
%<*example>
% \fi
%\begin{figure}[H]
%\begin{snugshade}
\begin{verbatim}
\documentclass{book}
\usepackage[figname=output,resetby=chapter]{statrep}
\end{verbatim}
%\end{snugshade}
%\caption{Example of Using the \Statrep Package}\label{fig:usage}
%\end{figure}
% \iffalse
%</example>
% \fi
%
% The \Statrep package supports the following options:
% \begin{itemize}
% \item \Code{generate} specifies whether a SAS program
% is generated at compile time. \index{generate option}
% It can have a value of \Code{true} or \Code{false}; the default is \Code{true}.
%
% \item \Code{figname=} specifies the name of a \LaTeX\ counter
% that is used for numbering outputs\index{figname option}.
% The default is \Code{figure}. If you specify a value for the \Code{figname}
% option for which no counter exists,
% a counter is created.
%
% \item \Code{resetby=} specifies that the counter for output numbering be reset with
% each change in the specified counter value. For example, if \Code{resetby=chapter},
% all output numbering is reset when the chapter value changes. See section
% \ref{longfigure} for details. Also, refer to the \Code{tocloft} package documentation
% for information about how the lists are typeset.\index{list of outputs, creating}%
% \end{itemize}
%
% The options \Code{figname=} and \Code{resetby=} are not used directly by the \Statrep
% package but are passed to the \Code{longfigure} package.
%
% The |longfigure| package is provided with the \Statrep package. It
% supports display and page breaking within a stream of outputs, and it can be
% used independently of the \Statrep package. It supports the options |figname=|
% and |resetby=|. For complete details about the implementation of the |longfigure| package,
% see section \ref{longfigure}.
%
%
% In Figure \ref{fig:usage}, the specified options label the included output as
% appropriately numbered \Code{Output}s and enable a \textit{List of Outputs} to be generated.
% To generate a \textit{List of Outputs}, add the \cs{listofoutput}
% command at the point in your document where you want
% the \textit{List of Outputs} to appear.
% If you specify \Code{figname=display}, add the \cs{listofdisplay} command
% where you want the \textit{List of Displays} to appear.
%
% If you load the \Statrep package with no options,
% the outputs are labeled as figures and you can display the \textit{List of Figures}
% with the command \cs{listoffigures}.
%
% % For more information about how to use the \Statrep package, see the \Statrep User's Guide
% (\texttt{statrepmanual.pdf}) that accompanies the \Statrep distribution.
%
% \section{\Statrep Implementation}
%
% \subsection{Required Packages}
% The \Statrep package requires the following \LaTeX\ packages. Each package is available
% in a relatively recent \TeX{}Live distribution (2005 or later).
%
% \begin{macrocode}
\RequirePackage{verbatim}
\RequirePackage{graphicx}
\RequirePackage{xkeyval}
\RequirePackage{calc}
\RequirePackage{ifthen}
% \end{macrocode}
% \begin{itemize}
% \item The |verbatim| package provides the foundation for the \Statrep package.
% \item The |graphicx| package enables inclusion of images and is used by the \cs{Graphic} tag.
% \item The |xkeyval|, |calc|, and |ifthen| packages provide programming capabilities that are
% used throughout the \Statrep package.
% \end{itemize}
%
% \begin{macrocode}
\newif\ifSR@generate\SR@generatetrue
\DeclareOptionX{generate}[true]{\@nameuse{SR@generate#1}}
\DeclareOptionX{color}[true]{%
\IfFileExists{sas.sty}
{\PassOptionsToPackage{\CurrentOption}{sas}}
{\relax}
}
\DeclareOptionX{figname}{\PassOptionsToPackage{\CurrentOption}{longfigure}}
\DeclareOptionX{resetby}{\PassOptionsToPackage{\CurrentOption}{longfigure}}
\ProcessOptionsX
\IfFileExists{sas.sty}
{\RequirePackage{sas}}
{\relax}
\RequirePackage{longfigure}
% \end{macrocode}
%
% Declare an option for \texttt{color}; Pass the value to the \texttt{sas}
% package if it exists, otherwise do nothing. This option has no effect if
% the ODS Listing destination is used. It applies only to SAS-generated
% LaTeX tabular output.
%
% The file \texttt{sas.sty} is loaded if it exists. The file is created by a SAS ODS
% tagset that is experimental; the tagset generates SAS output as LaTeX tables. More
% information on this experimental support can be found in the User's Guide (appendix).
%
%
% \subsection{Programming Utilities}\label{utilities}
% The programming helpers described in this section are used
% throughout the package:
%
% \begin{macrocode}
\ifSR@generate\def\SR@writepgm{\immediate\write}
\else\let\SR@writepgm\@gobbletwo
\fi
% \end{macrocode}
% \DescribeMacro{\SR@generate}
% \cs{SR@generate} is a Boolean switch that is created and defined to have a
% default value of |true|. The switch is used to provide alternative definitions of
% a utility macro \cs{SR@writepgm}.
% \DescribeMacro{\SR@writepgm}
% If the switch remains true, \cs{SR@writepgm} is defined as
% \cs{immediate}\cs{write};
% otherwise, it is defined to remove its two arguments (\cs{@gobbletwo}).
%
% The effect of these alternative definitions is as follows.
% When you do not override the default (by default, |generate| is true),
% the macro writes to a file stream that represents the generated program file.
% Otherwise, the macro is defined to remove its two arguments (therefore, it is effectively
% a null operation).
%
% The following two commands set the tolerance for bad boxes, orphans, and widows:
% \begin{macrocode}
\newcommand*{\dosloppy}{\setlength{\hfuzz}{\maxdimen}\hbadness\maxdimen}
\newcommand*{\unsloppy}{\setlength{\hfuzz}{0.3pt}\hbadness 1414}
% \end{macrocode}
%
% \DescribeMacro{\dosloppy}
% \DescribeMacro{\unsloppy}
% The |dosloppy| macro is intended to be used when you knowingly violate
% typesetting rules, such as when you must write extremely
% wide outputs. For such situations, set the tolerance
% high with |dosloppy| and set it back to normal with |unsloppy|. These settings
% do not change \LaTeX's line-breaking algorithms or line penalties; they suppress
% the overfull box (\cs{hfuzz}) and underfull box (\cs{hbadness}) warnings in the log.
% The system uses theses commands when it insert outputs.
% See the
% \cs{SR@set@outmargin} macro in section \ref{insert} for
% details.
%
% The following definitions are used to calculate and set the output
% stream of listings or figures. See section \ref{insert} for details.
% \begin{macrocode}
\newlength{\SR@scratchlength}
\newlength{\SR@verbwidth}
\newsavebox{\SR@filebox}
\newcommand*{\SR@firsthead}{}
\newcommand*{\SR@conthead}{}
\newcommand*{\SR@endfoot}{}
% \end{macrocode}
% The following variables aid in constructing the two verbatim environments
% provided in the \Statrep package:
% \begin{macrocode}
\newcounter{SR@currentline}\setcounter{SR@currentline}{0}
\newcounter{SR@displayline}\setcounter{SR@displayline}{0}
\newcounter{SR@programline}\setcounter{SR@programline}{0}
\newcounter{SR@startinglastline}\setcounter{SR@startinglastline}{0}
\newcounter{SR@totallines}\setcounter{SR@totallines}{0}
\newcounter{SR@multifilecount}\setcounter{SR@multifilecount}{0}
\newboolean{SR@multifile}\setboolean{SR@multifile}{false}
% \end{macrocode}
% \begin{itemize}
% \item |SR@currentline| contains the current line number of the
% |verbatim| environment that is being processed.
%
% \item |SR@displayline| contains the number of lines to display.
% The number can be specified as a line command inside a |Sascode| environment.
%
% \item |SR@programline| contains the number of lines to write to the
% generated program.
% The number can be specified as a line command inside a |Sascode| environment.
%
% \item |SR@startinglastline| contains the line number that begins the bottom block
% of an abbreviated displayed |Datastep| environment. This counter is used
% when the |last=| option is specified in the |Datastep| environment.
%
% \item |SR@totallines| contains the total number of lines in the
% |verbatim| environment.
%
% \item |SR@multifilecount| counter is used to step through and insert
% a set of output files that are generated by SAS.
%
%
% \item |SR@multifile| is a Boolean switch that is used in the algorithm that
% inserts the stream of outputs. See section \ref{insert} for complete details.
% \end{itemize}
%
% \begin{macrocode}
\begingroup\catcode`\#=12\gdef\SR@hashchar{#}\endgroup
% \end{macrocode}
% \DescribeMacro{\SR@hashchar}
% The \cs{SR@hashchar} macro is used in writing options that are specified in the
% \cs{Listing} and \cs{Graphic} macros. Options that specify SAS ODS
% object names
% can contain a hash character. In the \LaTeX\ source, the normal
% hash character (|#|) must be escaped (|\#|). When the string is written
% to the generated program, the escaping backslash must be removed.
% The definition resets the category code inside a group so that
% the change will not affect other definitions. Then the \cs{SR@hashchar}
% macro is globally defined as an unescaped hash character.
%
% The \cs{SR@hashchar} macro is used in the \cs{SR@write@outoptions} macro.
% See section \ref{output} for details.
%
% \DescribeMacro{SR@ keys}
% The following |SR@| family of keys is used in the |Datastep| and |Sascode| environments
% and the \cs{Listing} and \cs{Graphic} macros.
% \begin{macrocode}
\define@boolkeys{SR}[SR@]{display,program,continued}[true]{}
\define@cmdkeys{SR}[SR@]{caption,first,last}{}
\define@cmdkeys{SR}[SR@]{fontsize,scale,label}{}
% \end{macrocode}
% The keys are used for two purposes: One set of keys is used by the \Statrep
% package to typeset the environments or outputs that are defined in the package.
% Another set of keys is used to communicate with SAS; the keys are passed through
% directly to the generated program. There is some overlap between the two
% set of keys. For example, the |width| key is used by the \Statrep package
% to typeset the output that is specified in a \cs{Graphic} tag and is used by SAS
% to generate the image.
%
% The following keys are used only by the \Statrep package:
% \index{display option|usage}\index{program option|usage}\index{first option|usage}
% \index{caption option|usage}\index{continued option|usage}\index{last option|usage}
% \index{fontsize option|usage}\index{scale option|usage}
% \begin{itemize}
% \item |display| is a Boolean key that specifies that a |Sascode| or |Datastep| block
% should only be displayed.
% \item |program| is a Boolean key that specifies that a |Sascode| or |Datastep| block
% should only be written to the program file.
%
% \item |continued| is a Boolean key that specifies whether the output is a
% continuation of a preceding output block.
%
% \item |caption=| specifies the caption to use for a |Listing| or |Graphic| output.
%
% \item |first=| specifies the number of top lines to display in a |Datastep| environment.
% \item |last=| specifies the number of bottom lines to display in a |Datastep| environment.
% \item |fontsize=| specifies the \LaTeX\ font size to use in displaying output
% or code environment (for example, |small| or |footnotesize|).
% \item |scale=| specifies a factor by which to scale a |Graphic| image.
% For example, specify |scale=0.5| to scale the image to half its original size,
% or specify |scale=2| to scale it to double its original size.
% \item |label=| is used internally by the \Statrep package to generate a label
% for \cs{Graphic} and \cs{Listing} elements.
% \end{itemize}
%
% The following keys are used both by the \Statrep package and by SAS:
% \index{store option|usage}\index{linesize option|usage}\index{width option|usage}
% \begin{itemize}
% \item |store=| specifies the name of the ODS document store to be created in a
% |Sascode| environment. When this key is specified, the \Statrep package
% writes the appropriate SAS program lines to the generated program. When this
% key is not specified, the \Statrep package assumes that the author has written
% the SAS macro calls into the |Sascode| blocks.
%
% \item |linesize=| specifies the line size that is used to generate and
% typeset |Listing| output. Typical values are |80|, |96|, or |120|.
%
% \item |width=| specifies the width to generate or display |Graphic| output.
%
% \item |dest=| specifies the SAS ODS destination to use for tabular output.
% The possible values are |listing| and |latex|. The |listing| option includes verbatim
% text-based tables from the ODS LISTING destination. The |latex| option includes
% LaTeX tabular environments that use the |sas| package (generated during the SAS run).
% \end{itemize}
% \begin{macrocode}
\define@cmdkeys{SR}[SR@]{store,linesize,width,dest}{}
% \end{macrocode}
% The remaining keys are defined and accepted by the \cs{Listing} and \cs{Graphic}
% macros, but are passed on to the generated SAS program. The following keys are
% used only by SAS:
% \begin{macrocode}
\define@cmdkeys{SR}[SR@]{type,style,dpi}{}
\define@cmdkeys{SR}[SR@]{firstobj,lastobj}{}
\define@cmdkeys{SR}[SR@]{objects,pattern,options}{}
\define@cmdkeys{SR}[SR@]{height,pagesize}{}
% \end{macrocode}
%
% \index{type option|usage}\index{height option|usage}
% \index{objects option|usage}\index{pattern option|usage}\index{style option|usage}
% \index{dpi option|usage}\index{pagesize option|usage}\index{firstobj option|usage}
% \index{lastobj option|usage}
% \begin{itemize}
% \item |style=| specifies the ODS style to use in generating output.
% \item |dpi=| specifies how many dots per inch (DPI) to use in generating a graph.
%
% \item |firstobj=| specifies the first object's name to capture in an output stream.
% \item |lastobj=| specifies the last object's name to capture in an output stream.
% \item |objects=| specifies a space-separated list of object names to capture.
% \item |pattern=| specifies a name-matching pattern to select objects to capture.
%
% \item |options=| specifies other options for generating output.
% \item |height=| specifies the height of a generated graph (for example, |height=5.4in|).
% \item |pagesize=| specifies page size for output.
% \item |type=| specifies the type of output stream to initiate (|graphic| or |listing|).
% If the automatic program generation capability is in effect
% (that is, the |store=| option is specified),
% the \cs{Listing} and \cs{Graphic} tags automatically generate the appropriate
% value for this key.
%
% \end{itemize}
%
% \DescribeMacro{\presetkeys}
% When any environment or command uses the keys, it first calls the following
% |presetkeys| macro, which provides default values for each key:
% \begin{macrocode}
\presetkeys{SR}{%
display = false, program = false, continued = false,
caption = \@empty, first = 0, last = 0,
fontsize = \@empty, scale = \@empty, label = \@empty,
store = \@empty, linesize = \@empty, width = \@empty,
type = \@empty, style = \@empty, dpi = \@empty,
dest = \@empty, firstobj = \@empty, lastobj = \@empty,
objects = \@empty, pattern = \@empty, options = \@empty,
height = \@empty, pagesize = \@empty}{}
% \end{macrocode}
% \subsection{Customizable Settings}
%\iffalse
%</statrep>
%<*cfg>
%\fi
% \index{customizing|usage}
% The definitions in this section can be overridden by settings in the external file
% |statrep.cfg|.\index{statrep.cfg|usage}
%
% \DescribeMacro{\SRmacropath}
% \cs{SRmacropath} specifies the path to the location of the
% SAS macros that are bundled with the \Statrep package. You can define
% the path by using forward slashes (/) instead of backslashes (\textbackslash)
% as the directory
% name delimiter. If you do use backslashes, you
% must insert a backslash character into this argument by using the
% \cs{@backslashchar} command.
% The default value is the current
% directory. That is, the definition for the path to the macro file
% is the filename itself, |statrep_macros.sas|.
% \begin{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Edit this line to point to the location of the StatRep macros.
\def\SRmacropath{statrep_macros.sas}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \end{macrocode}
%% The following statements define line size, page size, graphic resolution,
%% and also specify the default ODS output style:
% \DescribeMacro{\SRlinesize}\DescribeMacro{\SRpagesize}
% \DescribeMacro{\SRdpi}\DescribeMacro{\SRstyle}\DescribeMacro{\SRodsgraphopts}
% \DescribeMacro{\SRlatexstyle}
%\changes{v1.06}{2015/01/15}{Added rootdir for SAS/Studio support.}
% \begin{macrocode}
\def\SRrootdir{.}
\def\SRlinesize{80}
\def\SRpagesize{500}
\def\SRdpi{300}
\def\SRstyle{statistical}
\def\SRlatexstyle{statrep}
\def\SRodsgraphopts{}
% \end{macrocode}
% The following statements define system options used in the generated SAS program%
% \begin{itemize}
% \item \cs{SRlinesize} specifies the default linesize to use for listing output.
% \item \cs{SRpagesize} specifies the default pagesize to use for listing output.
% \item \cs{SRdpi} specifies the default DPI setting to use for GRSEG and ODS graphics.
% \item \cs{SRstyle} specifies the default ODS output style to use for ODS graphics.
% \item \cs{SRlatexstyle} specifies the ODS output style to use for LaTeX tabular output.
% The default is |statrep|, which is provided in the supplmental file
% |statrep_tagset.sas|.
% \end{itemize}
% \begin{macrocode}
\def\SRgraphicdir{\SRrootdir/png}
\def\SRgraphtype{png}
\def\SRlistingdir{\SRrootdir/lst}
\def\SRlatexdir{\SRrootdir/tex}
\def\SRdefaultdests{listing}
% \end{macrocode}
% \DescribeMacro{\SRgraphicdir}\DescribeMacro{\SRgraphtype}\DescribeMacro{\SRlistingdir}
% \DescribeMacro{\SRdefaultdests}\DescribeMacro{\SRlatexdir}
% \begin{itemize}
% \item \cs{SRgraphicdir} specifies the name of the directory that contains the
% graphic output files that are generated by SAS. The default is |png|.
% \item \cs{SRgraphtype} specifies the type of graphics file that SAS will generate.
% The choices are |png| and |pdf|. The default is |png|.
% \item \cs{SRlistingdir} specifies the name of the directory that contains the
% listing (tabular) output files that are generated by SAS. The default is |lst|.
% \item \cs{SRlatexdir} specifies the name of the directory that contains the
% LaTeX (tabular) output files that are generated by SAS. The default is |tex|.
% \item \cs{SRdefaultdests} specifies the ODS destination to use for tabular output.
% The possible values are |listing| and |latex|. The default is |listing|.
% \end{itemize}
%\changes{v1.01}{2012/05/23}{Changed SRsasprogramline to call hostdel SAS macro}
%\changes{v1.06}{2015/01/15}{Changed hostdel macro to cleandir for SAS/Studio support.}
% \begin{macrocode}
\def\SRprogramname{\jobname_SR.sas}
\def\SRpreamblename{\jobname_SR_preamble.sas}
\def\SRmacroinclude{\@percentchar include "\SRmacropath" /nosource;}
\def\SRsasprogramline{%
\@percentchar cleandir(\SRrootdir, tex, tex);^^J%
\@percentchar cleandir(\SRrootdir, png, png);^^J%
\@percentchar cleandir(\SRrootdir, lst, lst);^^J%
}%
% \end{macrocode}
% \DescribeMacro{\SRprogramname}
% \DescribeMacro{\SRmacroinclude}\DescribeMacro{\SRprogramline}
% \begin{itemize}
% \item \cs{SRprogramname} specifies the filename for the generated SAS
% program. The default is \cs{jobname\_SR.sas}, where \cs{jobname} is usually
% the stem name of the \LaTeX\ source file.
% \item \cs{SRmacroinclude} specifies the line used in the generated SAS program to
% include the SAS macros that are bundled with the \Statrep package.
% The default is |%include|~\cs{SRmacropath}~/|nosource;|.
% \item \cs{SRprogramline} specifies the first lines to include in
% the generated SAS program
% after the \cs{SRmacroinclude} line. The following default value calls a SAS
% macro that removes the contents of the listing, tex, and graphic directories.
% The directories are created with
% each SAS run that includes the macros themselves (via x commands).
% \end{itemize}
%
% \begin{macrocode}
\def\SRparindent{3em}
\def\SRintertext{... more data lines ...}
\def\SRtempfilename{sr.tmp}
\def\SRcontinuedname{continued}
\def\SRcaptionfont{\sffamily}
\def\SRcaptioncontinuedfont{\sffamily\itshape}
\def\SRverbfont{\ttfamily\bfseries}
% \end{macrocode}
% \DescribeMacro{\SRparindent}
% \DescribeMacro{\SRintertext}\DescribeMacro{\tempfilename}
% \begin{itemize}
% \item \cs{SRparindent} specifies the amount of space to indent
% |Datastep| and |Sascode| environments.
% The argument is a dimension.
% The default is |3em| and is measured according to the font
% currently in use.
% \item \cs{SRintertext} specifies the text to insert in abbreviated
% |Datastep| environments (that is, |Datastep| environments that specify
% the |first=| option).
% \item \cs{SRtempfilename} specifies the name of a temporary file that is
% used as a scratch file in the current working directory.
% The default is |sr.tmp|.
%
% \DescribeMacro{\SRcontinuedname}\DescribeMacro{\SRcaptionfont}
% \DescribeMacro{\SRcaptioncontinuedfont}\DescribeMacro{\SRverbfont}
% \item \cs{SRcontinuedname} specifies the name that indicates that an output
% block is continued. This helper is used when an output stream breaks across a page.
% The default is |continued|.
% \item \cs{SRcaptionfont} specifies the font to use for the output captions.
% The default is \cs{sffamily} (\textsf{sans serif}).
%
% \item \cs{SRcaptioncontinuedfont} specifies the font to use for the |continued| name
% for outputs that break across pages.
% The default is \cs{sffamily}\cs{itshape} (\textsf{\textit{sans serif, italic}}).
%
% \item \cs{SRverbfont} specifies the font to use for code within |Datastep| and
% |Sascode| blocks. The default is \cs{ttfamily}\cs{bfseries}
% ({\bfseries\texttt{typewriter text, bold}}).
%
% \end{itemize}
%
%\iffalse
%</cfg>
%<*statrep>
%\fi
% If the file |statrep.cfg| exists, the following statements load it so that you can override
% the preceding definitions:
% \begin{macrocode}
\InputIfFileExists{statrep.cfg}
{\PackageInfo{statrep}{Reading custom configuration file statrep.cfg}}
{\PackageInfo{statrep}{No custom configuration file found (statrep.cfg).%
Using defaults.}}
% \end{macrocode}
% Two output streams are created:
% \begin{macrocode}
\newwrite\SR@program@stream
\newwrite\SR@tempfile@stream
% \end{macrocode}
% The stream \cs{SR@program@stream} represents the
% generated SAS program. The stream \cs{SR@tempfile@stream} represents a
% temporary stream and is used to write the SAS program preamble and
% to construct each |Datastep| environment.
%
% The following lines define boilerplate text that is included in the
% preamble SAS file and the capture-program SAS file:
% \begin{macrocode}
\def\SR@preambletext{/*^^J
This file is auto-generated by the statrep package.^^J
Do not edit this file or your changes will be lost.^^J
Edit the LaTeX file instead.^^J
^^J
See the statrep package documentation and the file^^J
statrep.cfg for information on these settings.^^J
*/^^J
^^J
}
% \end{macrocode}
% The following statements open the temporary stream by using the filename
% |\SR@preamblename| and write the default settings into the preamble file.
% The temporary file is then closed.
% \begin{macrocode}
\def\SR@write@preamble{
\immediate\openout\SR@tempfile@stream\SRpreamblename%
\SR@writepgm\SR@tempfile@stream{\SR@preambletext}
\SR@writepgm\SR@tempfile@stream{/* Set and invoke macro variable defaults. */}
\SR@writepgm\SR@tempfile@stream{\@percentchar let rootdir=\SRrootdir;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let defaultstyle=\SRstyle;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let latexstyle=\SRlatexstyle;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let graphtype=\SRgraphtype;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let graphicdir=\SRgraphicdir;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let listingdir=\SRlistingdir;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let latexdir=\SRlatexdir;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let defaultlinesize=\SRlinesize;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let defaultpagesize=\SRpagesize;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let defaultdpi=\SRdpi;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let odsgraphopts=\SRodsgraphopts;}
\SR@writepgm\SR@tempfile@stream{\@percentchar let defaultdests=\SRdefaultdests;}
\SR@writepgm\SR@tempfile@stream{}
\SR@writepgm\SR@tempfile@stream{options nodate nonumber}
\SR@writepgm\SR@tempfile@stream{ls=&defaultlinesize ps=&defaultpagesize}
\SR@writepgm\SR@tempfile@stream{formchar='|----|+|---+=|-/\@backslashchar<>*';}
\SR@writepgm\SR@tempfile@stream{}
\SR@writepgm\SR@tempfile@stream{ods graphics on;}
\SR@writepgm\SR@tempfile@stream{/* Include SAS macro definitions. */}
\SR@writepgm\SR@tempfile@stream{\SRmacroinclude}
\SR@writepgm\SR@tempfile@stream{}
\immediate\closeout\SR@tempfile@stream
% \end{macrocode}
% The following statements begin writing the generated SAS program |\SRprogramname|.
% They open the |\SR@program@stream|, write lines to include the preamble file,
% and do the preliminary work necessary before each run of the capture program.
%
% The preamble is written to a separate file and not directly into the capture
% program so that users who copy and paste code from the \LaTeX\ source to a SAS
% session can include only the preamble in their SAS session.
% \begin{macrocode}
\immediate\openout\SR@program@stream\SRprogramname
\SR@writepgm\SR@program@stream{\SR@preambletext}
\SR@writepgm\SR@program@stream{\@percentchar include "\SRrootdir/\SRpreamblename" /nosource;}
\SR@writepgm\SR@program@stream{/* Remove all output files. */}
\SR@writepgm\SR@program@stream{\SRsasprogramline}
\SR@writepgm\SR@program@stream{}
\SR@writepgm\SR@program@stream{/* Start program with a null title. */}
\SR@writepgm\SR@program@stream{title;}
\SR@writepgm\SR@program@stream{}
}
% \end{macrocode}
% \DescribeMacro{\SR@write@preamble}
% The \cs{SR@write@preamble} macro opens the |\SR@tempfile@stream| stream and
% writes the preamble for the SAS program to be generated. The preamble is constructed
% from the preceding configurable macros (for example, |\SRlinesize|, |\SRdpi|).
% You can modify the preamble in the |statrep.cfg| file.
%
% \begin{macrocode}
\AtBeginDocument{\SR@write@preamble}
\AtEndDocument{\immediate\closeout\SR@program@stream}
% \end{macrocode}
% At the beginning of the document, the \cs{SR@program@stream} stream is
% opened and the program file preamble (that is, the initial definitions
% described previously) is written to the program file.
% At the end of the document, the \cs{SR@programout} stream is closed.
%
% \subsection{Code Environments}
%
% The \Statrep package depends on the |verbatim| package to handle its code environments.
% The |verbatim| package provides programming hooks for redefining commands that are
% used to process
% |verbatim| environments. By redefining some of the commands that are called by the |verbatim|
% package, the \Statrep package can preprocess and postprocess code blocks as needed.
%
% The |verbatim| package defines the following macros as hooks for processing
% |verbatim| environments:
% \begin{itemize}
% \item \cs{verbatim@addtoline} adds its argument to the character buffer.
% \item \cs{verbatim@processline} typesets the characters that accumulate in the buffer.
% \end{itemize}
%
% By redefining these macros, the \Statrep package can control
% the reading, processing, and writing
% of the |verbatim| environment.
% The |Datastep| environment redefines \cs{verbatim@processline} at the beginning
% and the end of the code block.
% The |Sascode| environment redefines \cs{verbatim@addtoline} by inserting several
% line-processing steps before adding characters to the character buffer.
%
% \subsubsection{Datastep Environment}
%
% Three macros are defined to set up the |Datastep| environment:
% \begin{macrocode}
\def\SR@datastep@writefile#1{%
\setcounter{SR@totallines}{0}%
\@bsphack\immediate\openout\SR@tempfile@stream#1%
\let\do\@makeother\dospecials\catcode`\^^M\active%
%
\def\verbatim@processline{%
\addtocounter{SR@totallines}{1}%
\SR@writepgm\SR@tempfile@stream{\the\verbatim@line}%
}%
\verbatim@start%
}
% \end{macrocode}
% \DescribeMacro{\SR@datastep@writefile}
% The |SR@datastep@writefile| macro is used at the beginning of the
% |Datastep| environment. It resets category codes, opens a temporary file, and
% redefines \cs{verbatim@processline}
% to count the lines in the environment and write the code block to a temporary file.
%
% The logic in the \cs{SR@datastep@writefile} macro is taken from an example in the |verbatim|
% package documentation (Sch\"opf, Raichle, and Rowley 2001).
% \begin{macrocode}
\def\SR@enddatastep@writefile{\immediate\closeout\SR@tempfile@stream\@esphack}
% \end{macrocode}
% \DescribeMacro{\SR@enddatastep@writefile}
% The \cs{SR@enddatastep@writefile} macro closes the temporary file.
% \begin{macrocode}
\newcommand{\SR@datastep@writeprogramline}{%
\SR@writepgm\SR@program@stream{\the\verbatim@line}}
% \end{macrocode}
% \DescribeMacro{\SR@datastep@writeprogramline}
%
% The \cs{SR@datastep@writeprogramline} macro writes a line from the code block to the
% generated program. It is used
% when the code block is not specified as display-only.
% The |Datastep| environment begins by redefining the \cs{verbatim@processline} macro
% to write the code block to a temporary file. It also keeps a count of the total number
% of lines in the block.
% It ends by again redefining the \cs{verbatim@processline} macro, this time
% to process lines from the temporary file according to options that are specified in the
% |Datastep| environment.
%
% Figure \ref{dsscheme} shows how a |Datastep| environment is
% processed. The names in \textcolor{darkblue}{blue} represent macros that are called
% by the |verbatim| package, even though the macro contents might have been redefined.
% \index{Datastep schematic|usage}
% \begin{figure}[H]
% \begin{snugshade}
% \begin{picture}(400,170)
% \put(20,100){\texttt{Datastep}}
% \put(55,120){\textit{\textbf{Begin environment}}}
% \put(55,70){\textit{\textbf{End environment}}}
% %
% \put(55,140){\textit{SR@datastep@writefile}}
% \put(55,138){\vector(1,0){90}}
% \put(165,145){\color{darkblue}\textit{verbatim@processline}}
% \put(165,135){\textit{(count lines)}}
% \put(230,138){\vector(1,0){50}}
% \put(285,140){\textit{Temporary file}}
% %
% \put(55,55){\color{darkblue}\textit{verbatim@processline}}
% \put(55,40){\textit{Process option keys for display}}
% \put(55,30){(see \textit{Algorithm \ref{algo1}})}
% \put(55,52){\vector(1,0){210}}
% \put(285,52){\color{darkblue}\textit{verbatiminput}}
% \put(255,40){\textit{(from temporary file)}}
% \end{picture}
% \end{snugshade}
% \caption{Processing Schematic for the \texttt{Datastep} Environment}\label{dsscheme}
% \end{figure}
% \begin{macrocode}
\def\@Datastep[#1]{%
\setkeys{SR}{#1}%
\SR@datastep@writefile{\SRtempfilename}%
}
\newenvironment{Datastep}{%
\catcode`\^^M=\active
\@ifnextchar[{\catcode`\^^M=5\@Datastep}{\catcode`\^^M=5\@Datastep[]}
}
% \end{macrocode}
%
% \begin{environment}{Datastep}
% The beginning of the |Datastep| environment sets the key-value options that are
% specified for the environment and calls the \Statrep macro \cs{SR@datastep@writefile}.
%
% If you specify a |Datastep| environment with no options, and you place a comment
% character at the beginning of the first line
% of the environment, that line is hidden from
% the display. \LaTeX\ looks for the first ``real'' character of the environment and does
% not see the commented line. To account for this possiblity, the \cs{@Datastep}
% command is used internally to begin the real environment. At the initialization
% of the |Datastep| environment, the category code for the end-of-line character
% is changed to \emph{active}. If the environment has options, processing continues
% as normal (\cs{@Datastep} is called directly). If the environment has no options,
% a blank set of brackets is inserted into the stream and the \cs{@Datastep} is
% then called. Thus, if you specify a |Datastep| environment with no options,
% \LaTeX\ knows not to continue looking for the end of the command because the
% empty brackets represent an empty set of options.
% \begin{macrocode}
{%
\SR@enddatastep@writefile\endgraf%
% \end{macrocode}
% The end of the |Datastep| environment performs the following tasks:
% \begin{enumerate}
% \item calls \cs{SR@enddatastep@writefile} to close the temporary file
% \item redefines \cs{verbatim@processline} to handle line processing
% \item includes the temporary file that uses those redefined macros
% \end{enumerate}
% If the block should only be written to the program and not displayed, redefine
% \cs{verbatim@processline} to \cs{SR@datastep@writeprogramline} (defined previously)
% to write
% a line to the generated program file. Then process the temporary file.
% \begin{macrocode}
\ifSR@program\def\verbatim@processline{\SR@datastep@writeprogramline}%
\else%
% \end{macrocode}
% Otherwise, the code block is to be displayed.
% \begin{macrocode}
\ifthenelse{\equal{\SR@fontsize}{\@empty}}%
{\relax}%
{\@nameuse{\SR@fontsize}}%
\setcounter{SR@currentline}{0}%
\setcounter{SR@startinglastline}{\theSR@totallines-\SR@last-1}%
% \end{macrocode}
% Set the font size to be used in the display. Set the |SR@currentline|
% counter to 0. Set |SR@startinglastline| to the total number of lines
% in the environment minus the number of bottom lines to display.
%
% \DescribeMacro{\verbatim@processline}
% Redefine the \cs{verbatim@processline} macro to account for options
% that are specified to the
% environment and read in the temporary file.
% \begin{macrocode}
\def\verbatim@processline{%
% \end{macrocode}
% If the code block is not display-only, write each line to the program file
% by using the \cs{SR@datastep@writeprogramline} macro, defined previously.
% \begin{macrocode}
\ifSR@display\else\SR@datastep@writeprogramline\fi%
% \end{macrocode}
% The remainder of the macro logic is described in Algorithm \ref{algo1} on
% page \pageref{algo1}.
%
% Supporting the |last=| option in the |Datastep| environment is the only
% reason for the complexity of writing to a temporary file and
% retrieving the lines from the file.
% To know how to display the last \emph{n} lines, \Statrep must know the total
% number of lines in the code block.
% So it writes the code block to the temporary file and keeps
% a tally of the number of lines as it writes each line.
%
% A horizontal skip of length \cs{SRparindent} is added
% to the beginning of each \cs{the}\cs{verbatimline} line that is displayed.
%
% A \cs{par} is also appended to each \cs{the}\cs{verbatimline}:
% In a |verbatim| environment,
% \index{verbatim environment|usage} the entire block is typeset as a list of one item,
% and within that item, each line is a paragraph. The following statements append a
% \cs{par} to each
% \cs{the}\cs{verbatimline} to end the paragraph:
% \changes{1.05}{2014/10/15}{Added leavevmode; otherwise, interaction with geometry package}
% \changes{1.05}{2014/10/16}{Added braces around par lines; otherwise, interaction with tocloft package}
% \begin{macrocode}
\ifnum\SR@first>0%
\ifnum\theSR@currentline<\SR@first%
{\leavevmode\hskip\SRparindent\the\verbatim@line\par}%
\else%
\ifnum\theSR@currentline=\SR@first%
{\leavevmode\par\hskip\SRparindent\SRintertext\par}%
\else%
\ifnum\SR@last>0%
\ifnum\theSR@currentline=\theSR@startinglastline{\leavevmode\par}\fi%
\ifnum\theSR@currentline>\theSR@startinglastline%
{\leavevmode\hskip\SRparindent\the\verbatim@line\par}%
\fi%
\fi%
\fi%
\fi%
\else%
{\leavevmode\hskip\SRparindent\the\verbatim@line\par}%
\fi%
\addtocounter{SR@currentline}{1}%
}%
\fi%
% \end{macrocode}
% The following algorithm describes how this redefined version of the
% \cs{verbatim@processline} macro processes each line.
%
% \index{Datastep processing|usage}
% \begin{algorithm}[H]
% \For{each line in block}{
% \uIf{block is not display only}
% {write data line \;}
% \uIf{first=\textsf{n} is specified}
% {
% \uIf{currentline < \textsf{n}}{display line\;}
% \uElseIf{currentline = \textsf{n}}{write the value of \cs{SRintertext}\;}
% \uElseIf{last=\textsf{m} is specified}{
% \uIf{currentline = (totallines - \textsf{m})}{start new line\;}
% \uElseIf{currentline > (totallines - \textsf{m})}{display line\;}
% }
% }
% \uElse{display line\;}
% }
% \caption{\texttt{Datastep} Environment: \cs{verbatim@processline} Macro}\label{algo1}
% \end{algorithm}
%
% When all settings are configured, and when subsidiary macros and the
% \cs{verbatim@processline} macro are redefined,
% the following statement reads in the temporary file that was created at the
% beginning of the |Datastep|
% environment. The file is read by using the |verbatim| package macro
% \cs{verbatiminput}. That macro then calls \cs{verbatim@processline}, which the
% \Statrep package has just redefined.
%
% \begin{macrocode}
\verbatiminput{\SRtempfilename}%
% \end{macrocode}
% The code block has now been displayed and written to the program file as specified
% by the options in the |Datastep| environment. However, there is still
% cleanup left to do.
%
% The following statements determine whether the block was displayed:
% if it was not displayed, they
% retrieve all vertical space that is associated with the environment:
% \begin{macrocode}
\ifSR@program
\setlength{\SR@scratchlength}{-2\topsep-\partopsep-2\parskip-\baselineskip}
\vspace*{\SR@scratchlength}%
\fi%
% \end{macrocode}
% If the block is written to the program file, the following statements output a blank line after
% this |Datastep| environment in the program file:
% \begin{macrocode}
\ifSR@display\else%
\SR@writepgm\SR@program@stream{}%
\fi%
}
% \end{macrocode}
% \end{environment}
%
%
% \subsubsection{Sascode Environment}
% The following macros are defined to set up the |Sascode| environment:
%
% \begin{itemize}
% \item \cs{SR@sascode@addtoline} resets category codes and calls \cs{SR@sascode@filter}.
% \item \cs{SR@sascode@filter} acts as a filter. It processes lines with line commands
% and passes other lines to \cs{SR@sascode@writeline}.
% \item \cs{SR@sascode@writeline} writes the lines into the character buffer that is used
% by the |verbatim| package. It also writes lines to the generated program file.
% \end{itemize}
%
% The |Sascode| environment uses this sequence of macros by
% replacing the |verbatim| package macro \cs{verbatim@addtoline} with the
% \cs{SR@sascode@addtoline} macro.
%
% The following statements start a group to safely change the category
% code for the \% character to
% \emph{other}. Within this group, the \% character can be used in other definitions
% because its category code is no longer the comment category code (normally category
% code 14).
% \index{category codes|usage}
% \begin{macrocode}
\begingroup
\catcode`\%12
% \end{macrocode}
% \DescribeMacro{\SR@sascode@addtoline}
% The following statements call the \cs{SR@sascode@addtoline} macro,
% reset category codes, and call
% \cs{SR@sascode@filter} with two arguments: the original category code of the
% \% character and the verbatim line itself. The original category code for the \%
% character is sent so that it can be returned to its original state after
% \cs{SR@sascode@filter} is called.
% \begin{macrocode}
\gdef\SR@sascode@addtoline{\catcode`\%12
\expandafter\relax
\expandafter\SR@sascode@filter
\expandafter{\number\catcode`\% }}
% \end{macrocode}
% After expansion, the following command is left, where \textit{n} is the original
% category code of the \% character:\\
% |\relax\SR@sascode@filter|~\textit{n}\\
% That is, the macro first
% redefines the category code of the \% character and calls the
% \cs{SR@sascode@filter} macro with the original category code of the
% \% character as its first argument.
%
% \DescribeMacro{\SR@sascode@filter}
% The \cs{SR@sascode@filter} macro does the work of filtering the
% code block for line commands. See Algorithm \ref{algo2} for details.
%
% This macro is the reason \Statrep requires the use of
% pdf\LaTeX: the PDF primitive \cs{pdfmatch} is essential to the macro.
%
% \DescribeMacro{\pdfmatch}
% The \cs{pdfmatch}\marg{pattern}\marg{string}
% command implements pattern matching (using the syntax of
% POSIX regular expressions).
% The first argument is a regular expression pattern and the second
% argument is a string. The command expands
% to --1 if the pattern is invalid, to 0 if no match is found, and to 1 if a match
% is found.
% The primitive was introduced in pdfTEX 1.30.0 (Thanh et al. 2009).
% The result of \cs{pdfmatch} is stored in an array.
%
% \DescribeMacro{\pdflastmatch}
% The \cs{pdflastmatch}\marg{integer}\marg{expandable} returns the
% match that corresponds to \marg{integer} provided by the \cs{pdfmatch}
% command. Entry 0 contains the full match, and further
% entries contain submatches (captured group) that correspond to the subpatterns
% of the match.
%
% The regular expression argument must be escaped for use in \LaTeX.
% For example, consider the task to capture the integer in the following
% expression:\\
% |%* program 4;|\\
% A typical regular expression to capture the integer 4 is defined as follows:\\
% |^%\*\s*program\s*([0-9]+);|
%
% To use the expression in \LaTeX, it must be escaped so that
% the pattern becomes\\
% |^%\string\*\space*program\space*([0-9]+);|
%
% That is, \cs{*} becomes \cs{string}\cs{*} and \cs{s}* becomes \cs{space}*.
%
% The second argument is detokenized so that it represents a string of characters
% for use in the \cs{pdfmatch} macro.
%
% The effect of the \cs{SR@sascode@filter} macro is that every line that
% contains a line command is parsed, the appropriate line counters are
% set, and the line is skipped.
%
% Algorithm \ref{algo2} describes how the \cs{SR@sascode@filter} processes
% each line of the |Sascode| block.
%
% \index{Sascode processing|usage}
% \begin{algorithm}[H]
% \For {each line in block}{
% \eIf{line begins with \texttt{\%*} (column 1)}{
% \uIf{line matches \texttt{\%*} program n\; }{set program counter}
% \uElseIf{line matches \texttt{\%*} display n\; }{set display counter}
% \uElseIf{line matches \texttt{\%*} \; }{write line to program\;}
% \Else{display and write to program (valid SAS macro comment)}
% }
% {pass line onward to \cs{SR@sascode@writeline}\;}
% }
% \caption{\texttt{Sascode} Environment: \texttt{SR@sascode@filter} Macro}\label{algo2}
% \end{algorithm}
% \begin{macrocode}
\gdef\SR@sascode@filter#1#2{
\ifnum\pdfmatch{^%\string\*}
{\detokenize{#2}}=1
\ifnum\pdfmatch{^%\string\*\space*program\space*([0-9]+);}
{\detokenize{#2}}=1
\setcounter{SR@programline}
{\expandafter\strip@prefix\pdflastmatch 1}
\catcode`\%#1\@tempswafalse\verbatim@line{}
\else
\ifnum\pdfmatch{^%\string\*\space*display\space*([0-9]+);}
{\detokenize{#2}}=1
\setcounter{SR@displayline}
{\expandafter\strip@prefix\pdflastmatch 1}
\catcode`\%#1\@tempswafalse\verbatim@line{}
\else
\ifnum\pdfmatch{^%\string\*\space*;(.*)$}
{\detokenize{#2}}=1
\SR@writepgm\SR@program@stream{\expandafter\strip@prefix\pdflastmatch 1}
\catcode`\%#1\@tempswafalse\verbatim@line{}
\else \catcode`\%#1\SR@sascode@writeline{#2}
\fi
\fi
\fi
\else
\catcode`\%#1\SR@sascode@writeline{#2}
\fi
}
\endgroup
% \end{macrocode}
% The \cs{begingroup} that started the definition block for \cs{SR@sascode@addtoline}
% and \cs{SR@sascode@filter} is closed with \cs{endgroup}.
%
% In the \cs{SR@sascode@filter} macro, the Boolean switch
% \cs{tempswa} must be set to false for skipped lines because of how
% the |verbatim| package uses the switch.
% In the
% \cs{verbatim@processline} macro, the switch determines
% whether to insert a line ending. That is, it decides whether
% a new verbatim environment is
% starting (\verb+\@tempswatrue+). This decision determines whether
% to end
% a paragraph. Lines are equivalent to paragraphs inside a verbatim environment.
%
% Because the |Sascode| environment redefines the \cs{verbatim@addtoline} macro
% and not the \cs{verbatim@processline} macro from the |verbatim| package, the
% |Sascode| environment must set the \cs{tempswa} switch so that it is set appropriately
% when the |verbatim| package invokes \cs{verbatim@processline}.
% In this
% way, the
% \cs{tempswafalse} macro ensures that the displayed verbatim environment does
% not have blank lines in places where a line command was used.
%
% The \cs{SR@sascode@filter} macro passes all lines that are not line commands
% to the \cs{SR@sascode@writeline} macro. Lines that begin with the
% special line command, the null SAS macro comment (\%*;), are written directly to
% the generated program file after stripping the macro comment.
%
% The final \textbf{else} statement is executed
% when neither the program counter nor the display counter is set.
%
% \DescribeMacro{\SR@sascode@writeline}
% The \cs{SR@sascode@writeline} macro tests whether line counters are set
% and writes each line to its appropriate destination (the display or the
% generated program file or both). See Algorithm \ref{algo3} for a description
% of the macro's behavior.
%
% Note the use of \cs{SRparindent} to indent the code lines so that the |Sascode|
% environment display matches the |Datastep| environment display.
% \begin{macrocode}
\newcommand{\SR@sascode@writeline}[1]{%
\ifSR@program%
\SR@writepgm\expandafter\SR@program@stream{\detokenize{#1}}%
\@tempswafalse%
\else%
\ifSR@display%
\verbatim@line\expandafter{\the\verbatim@line\hskip\SRparindent#1}%
\else%
\ifnum\theSR@programline>0%
\SR@writepgm\expandafter\SR@program@stream{\detokenize{#1}}%
\addtocounter{SR@programline}{-1}%
\@tempswafalse%
\else%
\ifnum\theSR@displayline>0%
\verbatim@line\expandafter{\the\verbatim@line\hskip\SRparindent#1}%
\addtocounter{SR@displayline}{-1}%
\else%
\SR@writepgm\expandafter\SR@program@stream{\detokenize{#1}}%
\verbatim@line\expandafter{\the\verbatim@line\hskip\SRparindent#1}%
\fi%
\fi%
\fi%
\fi%
}
% \end{macrocode}
% Algorithm \ref{algo3} describes how the \cs{SR@sascode@writeline} macro
% processes each line that is received from the \cs{SR@sascode@filter} macro.
%
% \index{Sascode processing|usage}
% \begin{algorithm}[H]
% \For {each line received}{
% \uIf{program only}{write line to program file}
% \uElseIf{display only}{display line}
% \uElseIf{Program counter set}
% {write line to program file\;
% decrement \cs{SR@program} counter\;}
% \uElseIf{Display counter set}
% {display line\;
% decrement \cs{SR@display} counter\;}
% \Else{write line to program file\;
% display line\;}
% }
% \caption{\texttt{Sascode} Environment: \texttt{SR@sascode@writeline} Macro}\label{algo3}
% \end{algorithm}
%
% Figure \ref{fig:sascode} shows how a |Sascode| environment is
% processed. The names in \textcolor{darkblue}{blue} represent macros that are called
% by the |verbatim| package, even though the macro contents might have been
% redefined.
% \index{Sascode schematic|usage}
% \begin{figure}[H]
% \begin{snugshade}
% \begin{picture}(400,200)
% \put(150,175){\texttt{Sascode}}
% \put(167,170){\vector(0,-1){30}}
% \put(60,130){{\color{darkblue}\texttt{verbatim@addtoline}} => \texttt{SR@sascode@addtoline}}
%
% \put(200,120){\textit{\small initialize catcode}}
% \put(200,110){\textit{\small in order to define}}
% \put(200,100){\textit{\small and call\ldots}}
%
% \put(200, 75){\textit{\small filter lines, }}
% \put(200, 65){\textit{\small process line commands,}}
% \put(200, 55){\textit{\small and call\ldots}}
%
% \put(200, 30){\textit{\small send line into standard}}
% \put(200, 20){\texttt{\small \textcolor{darkblue}{verbatim@line}} \textit{\small buffer}}
% \put(188,125){\vector(0,-1){30}}
% \put(175,85){\texttt{SR@sascode@filter}}
% \put(188,80){\vector(0,-1){30}}
% \put(175,40){\texttt{SR@sascode@writeline}}
%
% \put(80,125){\color{darkblue}\vector(0,-1){90}}
% \put(60,25){\color{darkblue}\texttt{verbatim}}
% \put(85,15){\color{darkblue}\small \textit{typeset standard}}
% \put(85,5){\small\color{darkblue}\texttt{verbatim@line} \textit{\small buffer}}
% %
% \end{picture}
% \end{snugshade}
% \caption{Processing Schematic for the \texttt{Sascode} Environment}\label{fig:sascode}
% \end{figure}
%
% \begin{environment}{Sascode}
% The |Sascode| environment first sets the values for the optional keys.
% If the environment is to be written to the generated program, the appropriate
% keys are processed and passed to the program.
%
% If you do not use the |store=| key, \Statrep assumes that you are writing
% your own SAS macros to output the ODS document and write the outputs. If you do
% use the key, the macros are written automatically.
%
% The central point of the code for processing the |Sascode| environment is to
% redirect the |verbatim| package macro,
% \cs{verbatim@addtoline}, to the \Statrep package macro,\cs{SR@sascode@addtoline}.
% This redirection begins the workflow
% shown in Figure \ref{fig:sascode}. The processing steps are as follows:
% \index{Sascode processing|usage}
% \begin{enumerate}
% \item The |verbatim| package macro calls \cs{verbatim@addtoline}.
% \item The \cs{verbatim@addtoline} macro redirects to \cs{SR@sascode@addtoline}.
% \item The \cs{SR@sascode@addtoline} macro sets category codes and calls \cs{SR@sascode@filter}.
% \item The \cs{SR@sascode@filter} macro processes line commands and
% calls \cs{SR@sascode@writeline}.
% \item The \cs{SR@sascode@writeline} macro
% parses and processes the lines. It writes the appropriate lines to
% the generated program file.
% It also writes the appropriate lines into the \cs{verbatim@line} buffer, which
% is processed by the |verbatim| package macro \cs{verbatim}.
% \end{enumerate}
%
% If you specify a |Sascode| environment with no options, and you place
% a comment character at the beginning of the first line, that line is hidden from
% the display. \LaTeX\ looks for the first ``real'' character of the environment and does
% not see the commented line. To account for this possiblity, the \cs{@Sascode}
% command is used internally to begin the real environment. At the initialization
% of the |Sascode| environment, the category code for the end-of-line character
% is changed to \emph{active}. If the environment has options, processing continues
% as normal (\cs{@Sascode} is called directly). If the environment has no options,
% an empty set of brackets is inserted into the stream and \cs{@Sascode} is
% then called. Thus, if you specify a |Sascode| environment with no options,
% \LaTeX\ knows not to continue looking for the end of the command because the
% empty brackets represent an empty set of options.
% \begin{macrocode}
\def\@Sascode[#1]{%
\setkeys{SR}{#1}%
\ifSR@display\else%
\ifthenelse{\equal{\SR@store}{\@empty}}%
{\relax}%
{\SR@writepgm\SR@program@stream{\@percentchar output(\SR@store)}%
\PackageInfo{statrep}{Processing Sascode block \SR@store}}%
\fi%
\ifthenelse{\equal{\SR@fontsize}{\@empty}}%
{\relax}%
{\@nameuse{\SR@fontsize}}%
\setcounter{SR@programline}{0}%
\setcounter{SR@displayline}{0}%
\let\verbatim@addtoline\SR@sascode@addtoline%
\verbatim}
\newenvironment{Sascode}{%
\catcode`\^^M=\active
\@ifnextchar[{\catcode`\^^M=5\@Sascode}{\catcode`\^^M=5\@Sascode[]}
}
% \end{macrocode}
% The end of the |Sascode| environment performs the last steps that are needed
% and does some cleanup.
% The following statements remove vertical space that is caused by the end
% of the |Sascode| environment and write the |%endoutput| macro
% contents to the generated program file:
% \begin{macrocode}
{\endverbatim%
\setlength{\SR@scratchlength}{-2\topsep-\partopsep-2\parskip}
\vspace*{\SR@scratchlength}%
\ifSR@program\vspace*{-\baselineskip}\fi
%
\ifSR@display\else%
\ifthenelse{\equal{\SR@store}{\@empty}}%
{\relax}%
{\SR@writepgm\SR@program@stream{\@percentchar endoutput(\SR@store)}%
\SR@writepgm\SR@program@stream{}}%
\fi%
}
% \end{macrocode}
% \end{environment}
%
% \subsection{Handling the SAS Output}\label{output}
%
% The \cs{Listing} and \cs{Graphic} tags support options that are used
% in the generated program and in output display.
%
% There are three possible cases for an output request:
% \begin{itemize}
% \item The output is of type |graphic|.
% \item The output is of type |listing| and destination |listing|.
% \item The output is of type |listing| and destination |latex|.
% \end{itemize}
%
% When the |store=| option
% is used in the tags, a line is written to the |%write| macro that passes
% a subset of the options in the tag to the generated program. The tags also insert
% the stream of specified outputs in the displayed document.
%
% Graphical output is inserted as specified in the \cs{Graphic} tag,
% captioned, and centered.
%
% Listing output is inserted in the same way, but the output is framed when
% the destination is |listing|; when the destination is |latex|, the output
% (which is in the form of LaTeX tabular environments) is not framed.
%
% The frame for the |listing| destination
% is created with the help of the |longfigure| package and the
% \cs{hline} command.
% If the ODS destination is LaTeX, the resulting output blocks are put into
% a minipage of \cs{textwidth} width and are not framed.
%
% The following helper macros are used only in writing to the generated program:
% \begin{description}
% \item[\cs{SR@write@outoptions}] is called when the |store=| option is specified in
% the output tag. The command parses the options that are specified in the output tag
% for program-related options
% and writes the appropriate SAS macro to the generated program.
% \item[\cs{SR@set@outoptions}] creates a string of |key=value| pairs that are used
% in the generated SAS macro.
% \item[\cs{SR@final@outoptions}] accumulates each |key=value| pair into one string.
% \item[\cs{SR@outkeyval}] tests each key to determine whether to add the key and
% its value to the final option string.
% \end{description}
%
%
% \DescribeMacro{\SR@write@outoptions}
% If the |store=| option is specified in a \cs{Listing} or \cs{Graphic} tag,
% the \cs{SR@write@outoptions} macro is called.
% Otherwise, nothing is written to the generated
% SAS program.
% For each line that is written, use the macro \cs{SR@hashchar} to write out
% an unescaped hash character (|#|) when an escaped hash
% character (|\#|) is read.\index{hashchar|usage}\index{\#|usage}
% See section \ref{utilities} for information about the \cs{SR@hashchar} macro.
% \begin{macrocode}
\def\SR@write@outoptions{
\SR@set@outoptions
\let\#\SR@hashchar
\SR@writepgm\SR@program@stream{%
\@percentchar write(\SR@label,store=\SR@store \SR@final@outoptions)
}
% \end{macrocode}
%
% After the program line is written, a blank line is output to the program:
% \begin{macrocode}
\SR@writepgm\SR@program@stream{}
}
% \end{macrocode}
% The following statements define the \cs{SR@set@outoptions} macro.
% \DescribeMacro{\SR@set@outoptions}
% This macro
% resets the \cs{SR@final@outoptions}
% definition and calls \cs{SR@outkeyval} for the keys that can be passed
% through to the generated SAS program. This processing is necessary
% so that keys with \cs{@empty} values are not passed to the generated
% program.
% \begin{macrocode}
\newcommand*{\SR@set@outoptions}{%
\global\edef\SR@final@outoptions{}
\SR@outkeyval{height}\SR@outkeyval{objects}\SR@outkeyval{pattern}
\SR@outkeyval{style}\SR@outkeyval{dpi}\SR@outkeyval{options}
\SR@outkeyval{pagesize}\SR@outkeyval{linesize}\SR@outkeyval{width}
\SR@outkeyval{dest}\SR@outkeyval{type}\SR@outkeyval{firstobj}\SR@outkeyval{lastobj}
}
% \end{macrocode}
% Recall that all keys are set to \cs{@empty} with the \cs{presetkeys} macro.
% If the value has not been changed from the default, the following statements
% omit it from
% the \cs{SR@final@outoptions} macro definition.
%
% \DescribeMacro{\SR@outkeyval}
% The \cs{SR@outkeyval} macro expands
% \cs{SR@final@outoptions} to a string of |key=value| pairs.
% With each call to the \cs{SR@outkeyval} macro, the argument is checked
% to determine whether it is empty. If it is not empty, the argument is expanded and
% added to the \cs{SR@final@outoptions} value.
% \begin{macrocode}
\newcommand*{\SR@outkeyval}[1]{%
\def\SR@outkey{#1}
\edef\SR@outval{\csname SR@#1\endcsname}
\ifx\@empty\SR@outval
\else
\edef\SR@final@outoptions{\SR@final@outoptions,\SR@outkey=\SR@outval}
\fi
}
% \end{macrocode}
%
% The following macros are used to display the SAS generated output.
% \begin{description}
% \item[\cs{Listing}] inserts a stream of listing outputs.
% \begin{description}
% \item[\cs{Boxlisting}] boxes a single listing.
% \end{description}
% \item[\cs{Graphic}] inserts a stream of graphical outputs.
% \begin{description}
% \item[\cs{Boxgraphic}] boxes a single graphic.
% \end{description}
% \item[\cs{SR@insert}] begins the output insertion process.
% \begin{description}
% \item[\cs{SR@set@outheadings}] sets the heading for a |longfigure|.
% \item[\cs{SR@set@outmargin}] sets the left margin for centering a |longfigure|.
% \end{description}
% \end{description}
%
% \subsubsection{Note on Widths}
% If the output is a listing and the destination is |listing|, the output
% will be inserted as verbatim type input. The width is calculated by the linesize and
% the output centered by adjusting the \cs{LFleft} margin. The width calculation is
% done once, at the \cs{Listing} command itself.
%
% If the output is a graphic, the output is put into a box at whatever |scale| or
% |width| the user specified. The width of that box is calculated and the
% output centered by adjusting the \cs{LFleft} margin. The width calculation cannot
% be done at the \cs{Graphic} command since the output must be measured first.
% It is in the \cs{Boxgraphic} macro that the calculation takes place, which means it
% happens for each graphic in the output stream. Only the first graphic has an effect;
% it is only the first graphic in the stream that affects the \cs{LFleft} margin.
% This is an inefficiency.
%
% If the output is a listing and the destination is |latex|, the output cannot be
% measured at all. The output is put into a minipage of |textwidth| width and the
% \cs{LFleft} margin is untouched. The user can therefore set \cs{LFleft} before the
% \cs{Listing} tag to shift the output if needed.
%
% \subsubsection{The \cs{Listing} Macro}\label{listing}
%\index{output labels|usage}
% \begin{macro}{\Listing}
% The \cs{Listing} macro sets the options that are specified in the tag and
% automatically creates a label by using
% its \marg{argument}, which serves also as the name of
% the output file (without an extension).
% \begin{macrocode}
\newcommand{\Listing}[2][]{%
\setkeys{SR}{#1,type=listing,label=#2}%
\ifthenelse{\equal{\SR@store}{\@empty}}%
{\relax}%
{\SR@write@outoptions}%
% \end{macrocode}
% The |type=| option is automatically specified as |listing|; this option
% is passed to the generated SAS program.
% If the |store=| option is specified, the \cs{SR@write@outoptions} macro is invoked
% to write the appropriate SAS macro to the generated file.
% \begin{macrocode}
\ifthenelse{\equal{\SR@dest}{\@empty}}%
{\def\SR@dest{\SRdefaultdests}}%
{\relax}%
% \end{macrocode}
% If no value was given for the |dest=| option, set \cs{SR@dest} to the
% default value (specified globally as \cs{SRdest}). Now we are guaranteed
% to have a value for \cs{SR@dest} (used in the \cs{Boxlisting} and
% \cs{SR@insert} macros).
%
% The next block only pertains to the situation where we have a
% verbatim listing output from ODS Listing destination. We need to find
% the width of the output, which is done by calculating the width of a single
% character in the specified font and multiplying that value by the number
% of characters per line (linesize). This line length is saved in the
% value \cs{SR@scratchlength} and used to center the output.
% \begin{macrocode}
\ifthenelse{\equal{\SR@dest}{listing}}%
% The following statements set the font size:
% \begin{macrocode}
{\ifthenelse{\equal{\SR@fontsize}{\@empty}}%
{\def\SR@fontsize{normalsize}}%
{\relax}%
% \end{macrocode}
% The following statements set \cs{SR@scratchlength} to the width of a
% single character (\textasciitilde) by using the
% current font size and the verbatim font:
% \begin{macrocode}
\settowidth{\SR@scratchlength}{\@nameuse\SR@fontsize%
\SRverbfont\selectfont~}%
% \end{macrocode}
%
% The following statements control the line size for ODS Listing output:
% \begin{macrocode}
\ifthenelse{\equal{\SR@linesize}{\@empty}}%
{\def\SR@linesize{\SRlinesize}}{\relax}%
% \end{macrocode}
% The value for the key \cs{SR@linesize} is set to \cs{@empty} with each
% invocation of the \cs{Listing} command. If no value is specified
% for \cs{SR@linesize}, the following statements set it to the specified default
% value for line size \cs{SRlinesize}. This default is set to 80 by the
% \Statrep package; you can set the line size in the |statrep.cfg| file.
%
% The |linesize=| key corresponds to the line size that the SAS program uses to
% generate the tabular output. By default it is set to 80; other typical values
% are 96 and 120.
%
% The following statements set \cs{SR@verbwidth} to the width
% of \cs{SR@linesize} number of columns,
% with each column as wide as \cs{SR@scratchlength}. The result represents the
% width of the contents of a SAS listing output.
%
% \begin{macrocode}
\setlength{\SR@verbwidth}{(\SR@linesize\SR@scratchlength)}%
% \end{macrocode}
% Finally, the following statements
% add 2\cs{tabcolsep} and 2\cs{arrayrulewidth} to that width.
% The result represents the total width of a \cs{Listing} output and
% is used in the \cs{SR@insert} macro to center the output.\footnote{A listing
% output stream gets its width once, at the beginning of the stream. A graphic
% gets the width for each graphic file in its stream. Only the first
% measurement is used to calculate the graphic width
% (that is, only the first graphic file width is used).}
% \begin{macrocode}
\setlength{\SR@scratchlength}{\SR@verbwidth+2\tabcolsep+
2\arrayrulewidth}%
}% end if dest is listing
{\relax}% do nothing if dest is latex.
% \end{macrocode}
% With \cs{SR@verbwidth} calculated, \cs{SR@insert} is called to insert the \cs{Listing}.
% When the Listing is being set, the value for the left margin of the longfigure is
% calculated. After the Listing is finished, reset the value back to its default, 0.
% \begin{macrocode}
\SR@insert{#2}%
\setlength{\LFleft}{0in}%
}
% \end{macrocode}
% \end{macro}
% \subsubsection{The \cs{Graphic} Macro}
% The \cs{Graphic} macro sets the options that are specified in the tag and
% automatically creates a label by using
% its \marg{argument}, which also serves as the name of
% the output file (without an extension).
% \begin{macrocode}
\newcommand{\Graphic}[2][]{%
\setkeys{SR}{#1,type=graphic, label=#2}%
\ifthenelse{\equal{\SR@store}{\@empty}}%
{\relax}%
{\SR@write@outoptions}%
\SR@insert{#2}%
\setlength{\LFleft}{0in}%
}
% \end{macrocode}
% \begin{macro}{\Graphic}
% The |type=| option is automatically specified as |graphic|; this option
% is passed to the generated SAS program.
% If the |store=| option is specified, the \cs{SR@write@outoptions} macro is invoked
% to write the appropriate SAS macro to the generated file.
%
% Finally, \cs{SR@insert} is called to insert the \cs{Graphic}.
% When the Graphic is being set, the value for the left margin of the longfigure is
% calculated. After the Graphic is finished, reset the value back to its default, 0.
% \end{macro}
%
% \subsubsection{The \cs{Boxlisting} Macro}
% If the \cs{SRdest} value has been set for this
% listing, the value for \cs{SR@dest} now contains the value (see the Listing code above).
%
% If the current destination is |listing|, the \cs{Boxlisting} macro
% creates a box that contains the verbatim content
% of an external listing file. Put the content of the specified file
% into a box as verbatim input. If the file doesn't exist, place a marker in the document.
%
% If the current destination is |latex|, the \cs{Boxlisting} macro puts
% the contents of the specified file into a minipage and then into the box.
%
% \begin{macrocode}
\newcommand*{\Boxlisting}[1]{%
\ifthenelse{\equal{\SR@dest}{listing}}%
{\global\def\SR@insertname{lst/#1.lst}%
\IfFileExists{\SR@insertname}%
{%
\savebox{\SR@filebox}{%
\def\verbatim@font{%
\@nameuse{\SR@fontsize}%
\SRverbfont%
\hyphenchar\font\m@ne%
\@noligs%
}%
\parbox{\SR@verbwidth}{%
\vspace*{0.25\baselineskip}%
\noindent\verbatiminput{\SR@insertname}%
\vspace*{0.25\baselineskip}}%
}%
}%
{\savebox{\SR@filebox}{\fbox{Missing File \SR@insertname}}%
\global\def\SR@insertname{\@empty}}%
}%
{\global\def\SR@insertname{tex/#1.tex}%
\IfFileExists{\SR@insertname}%
{%
\savebox{\SR@filebox}{%
\begin{minipage}{\textwidth}%
\vspace{0.25\baselineskip}%
\centering\input{\SR@insertname}%
\vspace{0.25\baselineskip}%
\end{minipage}%
}%
}%
{\savebox{\SR@filebox}{\centering\fbox{Missing File \SR@insertname}}%
\global\def\SR@insertname{\@empty}%
}%
}%
\global\setbox\SR@filebox=\box\SR@filebox%
\PackageInfo{statrep}{Processing output \SR@insertname}%
}
% \end{macrocode}
%
% \begin{macro}{\Boxlisting}
% \changes{1.04}{2014/09/08}{Added noligs to verbatim font definition}
% The \cs{Boxlisting} macro takes a single argument, the \marg{filename}
% of the listing output to be boxed (the filename without the extension).
% If the file exists, the macro places the content of the file
% (using \cs{verbatiminput}) into a box of \cs{SR@verbwidth},
% which is calculated
% as described in section \ref{listing}.
% White space at the top and bottom of the box is
% inserted (0.25\cs{baselineskip}).
%
% The \cs{verbatim@font} is set to the user-defined \cs{SR@fontsize} (from the
% options on the Listing tag) and the \cs{SRverbfont} in the configuration. Furthermore,
% ligatures and the hyphenation character are both turned off. If you omit this
% step, ligatures will appear in the listing output (the case which prompted this
% bug-fix was a dashed line; the emdash ligature was applied to each pair of dashes).
%
% Note that \cs{SR@verbwidth} is the width that is used to create the \cs{parbox}
% that contains the output. \cs{SR@scratchlength} is used to center
% the output in a later step.
% \cs{SR@scratchlength} represents the width of the output plus the surrounding frame.
%
% If the file does not exist, \cs{SR@insertname} is defined to be
% \cs{@empty} and \cs{SR@filebox} is defined to be a box with
% the contents |Missing File|.
% \end{macro}
% \subsubsection{The \cs{Boxgraphic} Macro}
% The \cs{Boxgraphic} macro creates a box that contains the content of an external
% graphic file.
% \begin{macrocode}
\newcommand*{\Boxgraphic}[1]{%
\IfFileExists{png/#1.\SRgraphtype}%
{\global\def\SR@insertname{png/#1.\SRgraphtype}}%
{\global\def\SR@insertname{\@empty}}%
\ifthenelse{\equal{\SR@insertname}{\@empty}}%
{\savebox{\SR@filebox}{\fbox{ Missing File png/#1.\SRgraphtype}}}%
{%
\ifthenelse{\equal{\SR@scale}{\@empty}}%
{\ifthenelse{\equal{\SR@width}{\@empty}}%
{\savebox{\SR@filebox}{\includegraphics{\SR@insertname}}}%
{\savebox{\SR@filebox}{\includegraphics[width=\SR@width]%
{\SR@insertname}}}}%
{\savebox{\SR@filebox}{\includegraphics[scale=\SR@scale]%
{\SR@insertname}}}%
}%
\global\setbox\SR@filebox=\box\SR@filebox%
\PackageInfo{statrep}{Processing graphic \SR@insertname}%
\setlength{\SR@scratchlength}{\wd\SR@filebox+2\tabcolsep}%
}%
% \end{macrocode}
% \begin{macro}{\Boxgraphic}
% The \cs{Boxgraphic} macro takes a single argument, the \marg{filename}
% of the graphic output to be boxed (the filename without the extension).
% \index{png graphics|usage}
% \index{pdf graphics|usage}
%
% The macro first checks whether the file exists.
% If it does, it sets the global variable \cs{SR@insertname} to the full name.
% If the file does not exist,
% \cs{SR@insertname} is defined to be \cs{@empty}.
%
% If the global variable \cs{SR@insertname} is empty,
% then \cs{SR@filebox} is defined to be a framed box with
% the contents |Missing File|.
%
% Otherwise, we use
% the \cs{includegraphics} macro from the |graphicx| package to place
% the image.
%
% If the |width=| or |scale=| option was specified, the option is passed
% to the \cs{includegraphics} macro.
%
% Finally, \cs{SR@scratchlength} is set to the width of the graphic
% (now contained in \cs{SR@filebox}) + 2\cs{tabcolsep}.
% The result represents the total width of a \cs{Graphic} output and
% is used in the \cs{SR@insert} macro to center the output.
% \end{macro}
%
% \subsubsection{The \cs{SR@insert} Macro}\label{insert}
%
% The \cs{SR@insert} macro sets headings and footers for a |longfigure|,
% begins the |longfigure| environment, and calls the appropriate macro to
% display an
% output stream by using \cs{Boxlisting} or \cs{Boxgraphic}.
% The |longfigure| package is described in detail in section \ref{longfigure}.
% \begin{macro}{SR@filebox}
% Two helper macros are necessary to set up for the \cs{SR@insert}
% command:
% \begin{description}
% \item[\cs{SR@set@outheadings}] sets the headings on the output.
% \item[\cs{SR@set@outmargin}] sets the left margin to center the output.
% \end{description}
% \end{macro}
%
% \DescribeMacro{\SR@set@outheadings}
% The \cs{SR@set@outheadings} macro sets the contents of the |longfigure|'s first heading,
% its ``continued'' heading, and the footer. If the content is a \cs{Listing} and the
% destination is |listing|,
% the |longfigure| is framed (the headings and footers include an
% \cs{hline} command).
%
% \begin{macrocode}
\def\SR@set@outheadings{%
% \end{macrocode}
% The following statements define three macros for typing shortcuts:
% \begin{macrocode}
\def\SR@@caption{\caption{\SRcaptionfont\SR@caption}}%
\def\SR@@captioncontinued{\caption{\SRcaptioncontinuedfont\SRcontinuedname}}%
\def\SR@@captionskip{\\*[0.5\baselineskip]}%
% \end{macrocode}
%
% The following statements define a set of \cs{SR@@} macros that are
% used as calculators for the actual macros used
% at the time of typesetting:
% \begin{macrocode}
\ifthenelse{\equal{\SR@dest}{listing}}%
{\def\SR@@firsthead{\hline\endLFfirsthead}%
\def\SR@@conthead{\hline\endLFhead}%
\def\SR@@endfoot{\hline\endLFfoot}}%
%
{\def\SR@@firsthead{\endLFfirsthead}%
\def\SR@@conthead{\endLFhead}%
\def\SR@@endfoot{\endLFfoot}}%
%%%
% \end{macrocode}
% If the \cs{SR@dest} is |listing|, \cs{hline} commands are used for the heading
% and footer of the |longfigure|.
%
% The following statements set initial values for the heading
% and footer based on the preceding definitions:
% \begin{macrocode}
%%%
\renewcommand*{\SR@firsthead}{\SR@@firsthead}%
\renewcommand*{\SR@conthead}{\SR@@conthead}%
\renewcommand*{\SR@endfoot}{\SR@@endfoot}%
% \end{macrocode}
% \begin{macrocode}
\ifthenelse{\equal{\SR@caption}{\@empty}}%
{% CAPTION NOT GIVEN
\addtocounter{\LFcounter}{-1}%
\ifSR@continued%
\renewcommand*{\SR@conthead}{\SR@@captioncontinued%
\SR@@captionskip\SR@@conthead}%
\fi%
}%
% \end{macrocode}
% If a caption has not been specified, the
% first heading is empty. If the |longfigure| is a continuation
% (\cs{SR@continued} is true), the contination heading is set and
% the |longfigure| counter \cs{LFcounter} is decremented.
% Decrementing \cs{LFcounter} anticipates the automatic incrementing of the counter by the
% |longfigure| environment in the |longfigure| package.
% Thus, \textit{continued} |longfigure|s retain the number
% of the preceding |longfigure| environment.
% \begin{macrocode}
{% CAPTION GIVEN
\renewcommand*{\SR@firsthead}{\SR@@caption\label{\SR@label}%
\SR@@captionskip\SR@@firsthead}%
\renewcommand*{\SR@conthead}{\SR@@captioncontinued%
\SR@@captionskip\SR@@conthead}%
}
}
% \end{macrocode}
% If a caption has been specified, both the first heading and the continued
% heading are set appropriately.
%
% \index{output processing|usage}
% \DescribeMacro{\SR@set@outmargin}
% The \cs{SR@set@outmargin} macro sets the |longfigure| parameter |LFleft| based
% on the output dimensions. The output width is set in the
% \cs{Listing} (|listing| destination),
% or \cs{Boxgraphic} macros. The length
% parameter \cs{SR@scratchlength} contains the output width.
% \index{output centering|usage}%
% \begin{macrocode}
\def\SR@set@outmargin{%
\ifdim\SR@scratchlength>\textwidth%
\dosloppy%
\setlength{\LFleft}{(\paperwidth-\SR@scratchlength)/\real{2.0}}%
\addtolength{\LFleft}{-1in}%
\addtolength{\LFleft}{-\hoffset}%
\addtolength{\LFleft}{-\leftskip}%
\ifodd\c@page\addtolength{\LFleft}{-\oddsidemargin}%
\else\addtolength{\LFleft}{-\evensidemargin}%
\fi%
\else%
\setlength{\LFleft}{(\textwidth-\SR@scratchlength)/\real{2.0}}%
\fi%
}
% \end{macrocode}
% If the width of the output is narrower than the text block, it is centered
% with respect to the text block.
% \[
% \mathsf{LFleft} = \frac{\mathtt{textwidth} - \mathtt{outputwidth}}{2}
% \]
% If the width of the output is wider than the textblock, it is centered with
% respect to the page. The position of the left-hand edge of
% the page from the text block is calculated.
% The text block margin is the sum of the following:
% \begin{itemize}
% \item the standard \TeX\ margin (1 inch)
% \item \cs{hoffset}
% \item \cs{leftskip}
% \item the margin specified in the document design
% \end{itemize}
% To move to the left edge of the page, move left
% by the total amount of margin:\\
% 1 inch + \cs{hoffset} + \cs{leftskip} + \textit{document margin}
%
% Therefore, to center with respect to the page, add horizontal space equal to half
% the difference between the paper width and the output width. That is:
% \[
% \mathsf{LFleft} = -(\mathrm{TeX margin}+\mathtt{hoffset} + \mathtt{leftskip} + \mathtt{margin}) +\frac{\mathtt{paperwidth}-\mathtt{outputwidth}}{2}
% \]
% The first term (encompassed in parentheses) moves to the left edge of the page;
% the second and last term adds the
% horizontal space necessary to center the output. For example, using
% |letterpaper|, an output width of 5.75 inches, and a side margin
% of 1.5 inch, and assuming \cs{hoffset} and \cs{leftskip} have their default
% values of zero width,
% the left margin is set as follows:
% \[
% \mathrm{LFleft} = - (1 + 1.5) + \frac{8.5-5.75}{2} = -1.125
% \]
% The \cs{LFleft} margin is set to |-1.125|, which is 1.125 inches to the left of the
% normal text block margin.
%
% For documents with unequal margins on even-numbered and odd-numbered pages,
% take the page number into
% account before subtracting the side margin. The \cs{ifodd} macro, provided
% by the |ifthen| package, checks whether the page number is odd or even.
%
% Note: The \cs{dosloppy} command is used only when the output is wider than
% the text block.\index{dosloppy|usage}
%
% \begin{macro}{\SR@insert}
% The \cs{SR@insert} macro inserts an output stream into the document.
%
% The following statements set the heading for the output and box the
% first output in the stream:
% \begin{macrocode}
\newcommand{\SR@insert}[1]{%
\SR@set@outheadings%
\ifthenelse{\equal{\SR@type}{listing}}{\Boxlisting{#1}}{\Boxgraphic{#1}}%
\ifthenelse{\equal{\SR@dest}{latex}}%
{\relax}%
{\SR@set@outmargin}%
% \end{macrocode}
%
% The width of a \cs{Listing} output is calculated in the \cs{Listing} macro.
% The width of a \cs{Graphic} output is calculated in the \cs{Boxgraphic} macro.
% Therefore, after boxing an output, the \cs{SR@scratchlength} contains the
% width of the output regardless of type. With that information, the margins
% that are required for centering are set. This does not apply to outputs with
% |dest=latex|.
%
% The following statements determine whether an output file exists that matches
% the argument specified in the output tag; and if so, they
% set the Boolean switch |SR@multifile| to |true| and display the resulting
% boxed output:
% \begin{macrocode}
\ifthenelse{\equal{\SR@insertname}{\@empty}}%
{\setboolean{SR@multifile}{false}}%
{\setboolean{SR@multifile}{true}}%
% \end{macrocode}
% \changes{v1.07}{2015/09/15}{encapsulates longfigure with bgroup/egroup}
% The following statements center a listing or a graphic and
% put a vertical line on each side of a listing (|listing| destination).
% No horizontal or vertical lines (no box) are drawn for graphics or
% outputs using the |latex| destination.
% \begin{macrocode}
\ifthenelse{\equal{\SR@dest}{listing}}%
{\bgroup\longfigure{|c|}}{\bgroup\longfigure{c}}%
\SR@firsthead\SR@conthead\SR@endfoot%
\usebox{\SR@filebox}%
% \end{macrocode}
% The following statements begin the input loop, inserting output files that
% match the specified stem pattern until
% there are no matching files:\index{output insertion|usage}
% \begin{macrocode}
\setcounter{SR@multifilecount}{1}%
\whiledo{\boolean{SR@multifile}}{%
\ifthenelse{\equal{\SR@type}{listing}}%
{\Boxlisting{#1\arabic{SR@multifilecount}}}%
{\Boxgraphic{#1\arabic{SR@multifilecount}}}%
\ifthenelse{\equal{\SR@insertname}{\@empty}}%
{\setboolean{SR@multifile}{false}}%
{\\[0.5\baselineskip]\usebox{\SR@filebox}%
\stepcounter{SR@multifilecount}%
\setboolean{SR@multifile}{true}}%
}%
\endlongfigure\egroup%
\unsloppy%
}
% \end{macrocode}
% The logic of the preceding statements is depicted in Algorithm \ref{malgo}.
%
% \begin{algorithm}[H]
% \While{multiple files is True}
% {\eIf{type=listing}{Boxlisting}{Boxgraphic}
% \eIf{file exists}{insert contents, increment counter}{multiple files is False}
% }
% \caption{Input Loop for the Output Stream}\label{malgo}
% \end{algorithm}
%
% When SAS generates a set of files from one ODS selection, it follows a
% pattern. The first file that is generated is identical to the filename. The next
% file that is generated has the same name with a ``1'' appended to it, the next file
% has the same name with a ``2'' appended, and so on.
% The preceding statements input the original file; the following statements test for
% the existence of a file that has a name with the next digit in the
% sequence appended. The \cs{SR@multifilecount} counter contains the
% digit. With each inserted file, the counter is incremented.
%
% When no file matches the pattern (the
% \cs{SR@insertname} macro is \cs{@empty}), the Boolean switch
% \cs{SR@multifile} is set to false and the loop is ended.
%
% The \cs{unsloppy} macro is called when the stream insertion is finished
% to undo the effects of a \cs{dosloppy} command, which is called when
% the width of the output is greater than the width of
% the textblock. Invoking the \cs{unsloppy} macro
% multiple times has the same effect as calling it once; that is, even if
% \cs{dosloppy} is never called, calling \cs{unsloppy} causes no problem.
%
% \end{macro}
%\iffalse
%</statrep>
%\fi
%<*longfigure>
% \section{\textsf{\small longfigure} Usage}
% \label{longfigure}
% \index{longfigure package|usage}
%
% The |longfigure| package uses and relabels components of the
% well-known |longtable| package, written by David Carlisle, to
% provide a table-like environment that can display a stream
% of subfigures as a single figure that can break across pages.
%
% The |longtable| package defines a |longtable| environment,
% which produces tables that can be broken by \TeX's standard page-breaking algorithm.
% Similarly, the |longfigure| package defines a |longfigure| environment, which produces
% figures that can be broken by \TeX's standard page-breaking algorithm.
% The internal structure of a long figure is similar to a long table.
% Rows might contain (for example) tables or graphics. Page breaks
% can occur only between rows.
%
% The |longfigure| package differs from the |longtable| package in the following ways:
% \begin{itemize}
% \item The |longfigure| package supports two additional key-value options:
% \begin{itemize}
% \item The |figname=| option specifies the counter for numbering |longfigure| environments.
% You can specify any string; the default is |figure|.
% When you specify a |figname=| value for which no counter already exists, the
% |longfigure| package loads the |tocloft| package and creates the counter.
% \index{figname option|usage}
%
% \item The |resetby=| option specifies a counter (for example, |resetby=chapter|) such
% that output numbering is reset each time the counter value changes.
% If a counter is specified that does not exist, the |tocloft| package is
% loaded to create the new counter.
% \index{tocloft package|usage}%
% For information about how the lists are typeset,
% \index{list of outputs, creating|usage}%
% see the |tocloft| package documentation.
% \end{itemize}
% \item The counters and macros that start with \cs{LT} in the |longtable| package
% are renamed to start with \cs{LF} in the |longfigure| pacakge to avoid
% namespace conflicts when the two packages are used together.
% The generic macros that are defined in the |longtable| package
% (\cs{endfirsthead}, \cs{endhead}, \cs{endfoot}, and \cs{endlastfoot}) are
% also renamed with \cs{LF} as a prefix in the |longfigure| package.
%
% \item The \cs{LF@name} macro is based on the \cs{fnum@table} macro from
% the |longtable| package. The \cs{LF@name} macro returns the capitalized
% counter name and value. For example, if the counter is |figure| and the
% macro is processing the second |longfigure|, the \cs{LF@name} macro
% would contain the value ``Figure 2.''
%
% \end{itemize}
% You can use the |longfigure| package defaults to produce a \emph{List of Figures}
% by inserting the following tag in your document at the point where you want
% the list to appear:
% \iffalse
%<*example>
% \fi
\begin{verbatim}
\listoffigures
\end{verbatim}
% \iffalse
%</example>
% \fi
%
% The default counter used to display figures is the |figure| counter,
% but you can specify a different counter. For example, if you want your
% figures to be labeled as ``Display,'' specify |figname=display| when you
% load the |longfigure| package; to display a \emph{List of Displays}, insert the following
% command in your document at the point where you want the list to appear:
% \iffalse
%<*example>
% \fi
\begin{verbatim}
\listofdisplay
\end{verbatim}
% \iffalse
%</example>
% \fi
% \textbf{Note:} If you specify a counter that does not exist,
% an auxiliary file with extension |.lft| is created to contain the information
% needed to create the list.
%
% If you want to use more advanced features of the |tocloft| package,
% load it before you load the |longfigure| package so that the |longfigure|
% package sees that the counters specified by the |figname=| and |resetby=|
% options are already defined and does not attempt to create them.
%
%
%\subsection{Example}
% The following lines produce a single figure that contains three images and
% one tabular environment. Each element is a row of the |longfigure| environment.
% Page breaks can occur between rows.
%% \iffalse
%<*example>
% \fi
\begin{verbatim}
\documentclass{book}
\usepackage{graphicx}
\usepackage{longfigure}
\begin{document}
\begin{longfigure}{c}
\caption{My Long Figure}\label{mlfig}\\
\includegraphics[width=3in]{myfig1}\\
\includegraphics[width=3in]{myfig2}\\
\includegraphics[width=3in]{myfig3}\\
\begin{tabular}{ll}
one & two \\
three & four\\
\end{tabular}
\end{longfigure}
\end{document}
\end{verbatim}
% \iffalse
%</example>
% \fi
% In this example, the |{c}| argument in the |\begin{longfigure}| command
% specifies only a single centered column. You can also specify multiple columns and,
% if needed, use the \cs{multicolumn} command for more flexibility.
%
% The following lines display another example that specifies a 'continued' heading
% when the figure breaks over a page. It also displays a double horizontal line at the
% end of the figure.
% \iffalse
%<*example>
% \fi
\begin{verbatim}
\documentclass{book}
\usepackage{graphicx}
\usepackage{longfigure}
\begin{document}
\begin{longfigure}{c}
\caption{My Long Figure}\label{mlfig2}\\
\hline\endLFfirsthead
\caption{continued}\\
\hline\endLFhead
\hline\endLFfoot
\hline\hline\endLFlastfoot
\includegraphics[width=3in]{myfig1}\\
\includegraphics[width=3in]{myfig2}\\
\includegraphics[width=3in]{myfig3}\\
\begin{tabular}{ll}
one & two \\
three & four\\
\end{tabular}
\end{longfigure}
\end{document}
\end{verbatim}
% \iffalse
%</example>
% \fi
% \section{Implementation}
%
% This section describes the implementation of the |longfigure| package.
% The comments describe only the changes from the |longtable| package code.
% For complete details about the logic and usage of the |longtable| environment,
% see Carlisle (2004).
%\iffalse
%<*longfigure>
%\fi
% \begin{macrocode}
\ProvidesPackage{longfigure}[2014/01/06 longfigure]
% \end{macrocode}
% The following statement loads the |xkeyval| package for declaring
% and processing package options:
% \begin{macrocode}
\RequirePackage{xkeyval}
% \end{macrocode}
% The following statement defines a new command, \cs{LFcounter}, to
% contain the string |figure|.
% Later code tests whether a counter with that name exists.
% \begin{macrocode}
\newcommand*{\LFcounter}{figure}
% \end{macrocode}
%
% The following statement defines a new command, \cs{LFreset}, to contain
% the name of the counter within which the |longfigure| number should reset.
% If no value is specified, the long figures are numbered consecutively
% through the document.
% \begin{macrocode}
\newcommand*{\LFreset}{\@empty}
% \end{macrocode}
% \subsection{Options}
% The \cs{LFcounter} and \cs{LFreset} commands support the
% package options |figname=| and |resetby=| as follows:
% \begin{macrocode}
\DeclareOptionX{figname}[figure]{\renewcommand*{\LFcounter}{#1}}
\DeclareOptionX{resetby}{\renewcommand*{\LFreset}{#1}}
% \end{macrocode}
% The following statements further define the options
% that the |longtable| package defines:
% \begin{macrocode}
\DeclareOptionX{set}{}
\DeclareOptionX{final}{}
\DeclareOptionX{errorshow}{\def\LF@warn{\PackageInfo{longfigure}}}
\DeclareOptionX{pausing}{\def\LF@warn#1{\LF@err{#1}{This is not really an error}}}
\ProcessOptionsX
% \end{macrocode}
% The following statements process the options:
% \begin{macrocode}
\def\LFProcessOptions#1{
\@ifundefined{c@#1}{%
\RequirePackage{tocloft}
\def\LFuc##1##2{\MakeUppercase{##1}{##2}}
\expandafter\def\csname list#1name\endcsname{List of \LFuc#1s}
\ifx\@empty\LFreset%
\newlistof{#1}{lft}{\csname list#1name\endcsname}
\else
\newlistof[\LFreset]{#1}{lft}{\csname list#1name\endcsname}
\fi
}{}%
}
\expandafter\LFProcessOptions\expandafter{\LFcounter}
% \end{macrocode}
% If a counter is specified that does not exist, its name (\cs{c@}\textit{countername})
% is undefined and the |longfigure| package loads the |tocloft| package in order to
% use its commands to create the new counters and list.
%
% Thus, the |tocloft| package is required only when a new counter
% is specified,
% \index{tocloft package|usage}%
% and this automatic loading takes place only if the counter that is specified
% in the package options is not defined.
%
% You can load the |tocloft| package before loading the |longfigure| package
% and retain all of the flexibility that the |tocloft| package offers.
% However, you must define the new counters yourself by using the
% \cs{newlistof} command in the |tocloft| package,
% and you must define the new list to use an auxiliary |lft| file where
% its auxiliary information is written.
% \index{tocloft package|usage}%
%
% \subsection{Utilities}
% \DescribeMacro{\strcfstr}
% The following macro, \cs{strcfstr}, checks whether two strings, which are
% provided as arguments, are equal (Wilson, 2001).
% A new boolean \cs{ifLF@same} contains the result of the test.
% \begin{macrocode}
\newif\ifLF@same
\newcommand{\strcfstr}[2]{%
\LF@samefalse
\begingroup\def\2{#2}
\ifx\2#1\endgroup\LF@sametrue
\else\endgroup
\fi
}
% \end{macrocode}
% \DescribeMacro{\LFupcase}
% The following macro, \cs{LFupcase}, uppercases the first letter of
% a string (Lazarides, 2010):
% \begin{macrocode}
\def\LFupcase#1{%
\def\x##1##2{%
\MakeUppercase{##1}{##2}}\x#1%
}
% \end{macrocode}
% The following macro, \cs{LF@name}, creates a string to provide a label and number for
% an output. Analogous to the \cs{fnum@table} macro in the |longtable| package,
% it contains the capitalized version of the counter name and the counter
% number (for example, |Figure~3|).
% \begin{macrocode}
\def\LF@name{\expandafter\LFupcase%
\expandafter{\LFcounter}~%
\expandafter\csname the\LFcounter\endcsname}%
% \end{macrocode}
% The remainder of this package follows the |longtable| package
% almost identically, except that macros, skips, counters, and so on
% use an \cs{LF} prefix instead of the \cs{LT} prefix that the |longtable| package uses.
%
% \begin{macrocode}
\def\LF@err{\PackageError{longfigure}}
\def\LF@warn{\PackageWarning{longfigure}}
\def\LF@final@warn{%
\AtEndDocument{%
\LF@warn{\LFcounter \@width s have changed. Rerun \LaTeX\.\@gobbletwo}}%
\global\let\LF@final@warn\relax}
%
\newskip\LFleft \LFleft=\fill
\newskip\LFright \LFright=\fill
\newskip\LFpre \LFpre=\bigskipamount
\newskip\LFpost \LFpost=\bigskipamount
\newcount\LFchunksize \LFchunksize=20
\let\c@LFchunksize\LFchunksize
\newdimen\LFcapwidth \LFcapwidth=4in
\newbox\LF@head
\newbox\LF@firsthead
\newbox\LF@foot
\newbox\LF@lastfoot
\newcount\LF@cols
\newcount\LF@rows
\newcounter{LF@tables}
\newcounter{LF@chunks}[LF@tables]
%
\newtoks\LF@p@ftn
\mathchardef\LF@end@pen=30000
\def\longfigure{%
\par
\ifx\multicols\@undefined
\else
\ifnum\col@number>\@ne
\@twocolumntrue
\fi
\fi
\if@twocolumn
\LF@err{longfigure not in 1-column mode}\@ehc
\fi
\begingroup
\@ifnextchar[\LF@array{\LF@array[x]}}
\def\LF@array[#1]#2{%
\refstepcounter{\LFcounter}\stepcounter{LF@tables}%
\if l#1%
\LFleft\z@ \LFright\fill
\else\if r#1%
\LFleft\fill \LFright\z@
\else\if c#1%
\LFleft\fill \LFright\fill
\fi\fi\fi
\let\LF@mcol\multicolumn
\let\LF@@tabarray\@tabarray
\let\LF@@hl\hline
\def\@tabarray{%
\let\hline\LF@@hl
\LF@@tabarray}%
\let\\\LF@tabularcr\let\tabularnewline\\%
\def\newpage{\noalign{\break}}%
\def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LF@no@pgbk-}4}%
\def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LF@no@pgbk4}%
\let\hline\LF@hline \let\kill\LF@kill\let\caption\LF@caption
\@tempdima\ht\strutbox
\let\@endpbox\LF@endpbox
\ifx\extrarowheight\@undefined
\let\@acol\@tabacol
\let\@classz\@tabclassz \let\@classiv\@tabclassiv
\def\@startpbox{\vtop\LF@startpbox}%
\let\@@startpbox\@startpbox
\let\@@endpbox\@endpbox
\let\LF@LL@FM@cr\@tabularcr
\else
\advance\@tempdima\extrarowheight
\col@sep\tabcolsep
\let\@startpbox\LF@startpbox\let\LF@LL@FM@cr\@arraycr
\fi
\setbox\@arstrutbox\hbox{\vrule
\@height \arraystretch \@tempdima
\@depth \arraystretch \dp \strutbox
\@width \z@}%
\let\@sharp##\let\protect\relax
\begingroup
\@mkpream{#2}%
\xdef\LF@bchunk{%
\global\advance\c@LF@chunks\@ne
\global\LF@rows\z@\setbox\z@\vbox\bgroup
\LF@setprevdepth
\tabskip\LFleft \noexpand\halign to\hsize\bgroup
\tabskip\z@ \@arstrut \@preamble \tabskip\LFright \cr}%
\endgroup
\expandafter\LF@nofcols\LF@bchunk&\LF@nofcols
\LF@make@row
\m@th\let\par\@empty
\everycr{}\lineskip\z@\baselineskip\z@
\LF@bchunk}
\def\LF@no@pgbk#1[#2]{\penalty #1\@getpen{#2}\ifnum`{=0\fi}}
\def\LF@start{%
\let\LF@start\endgraf
\endgraf\penalty\z@\vskip\LFpre
\dimen@\pagetotal
\advance\dimen@ \ht\ifvoid\LF@firsthead\LF@head\else\LF@firsthead\fi
\advance\dimen@ \dp\ifvoid\LF@firsthead\LF@head\else\LF@firsthead\fi
\advance\dimen@ \ht\LF@foot
\dimen@ii\vfuzz
\vfuzz\maxdimen
\setbox\tw@\copy\z@
\setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
\setbox\tw@\vbox{\unvbox\tw@}%
\vfuzz\dimen@ii
\advance\dimen@ \ht
\ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@\dp
\ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@ -\pagegoal
\ifdim \dimen@>\z@\vfil\break\fi
\global\@colroom\@colht
\ifvoid\LF@foot\else
\advance\vsize-\ht\LF@foot
\global\advance\@colroom-\ht\LF@foot
\dimen@\pagegoal\advance\dimen@-\ht\LF@foot\pagegoal\dimen@
\maxdepth\z@
\fi
\ifvoid\LF@firsthead\copy\LF@head\else\box\LF@firsthead\fi\nobreak
\output{\LF@output}}
\def\endlongfigure{%
\crcr
\noalign{%
\let\LF@entry\LF@entry@chop
\xdef\LF@save@row{\LF@save@row}}%
\LF@echunk
\LF@start
\unvbox\z@
\LF@get@widths
\if@filesw
{\let\LF@entry\LF@entry@write\immediate\write\@auxout{%
\gdef\expandafter\noexpand
\csname LF@\romannumeral\c@LF@tables\endcsname
{\LF@save@row}}}%
\fi
\ifx\LF@save@row\LF@@save@row
\else
\LF@warn{Column \@width s have changed\MessageBreak
in table \thetable}%
\LF@final@warn
\fi
\endgraf\penalty -\LF@end@pen
\endgroup
\global\@mparbottom\z@
\pagegoal\vsize
\endgraf\penalty\z@\addvspace\LFpost
\ifvoid\footins\else\insert\footins{}\fi}
\def\LF@nofcols#1&{%
\futurelet\@let@token\LF@n@fcols}
\def\LF@n@fcols{%
\advance\LF@cols\@ne
\ifx\@let@token\LF@nofcols
\expandafter\@gobble
\else
\expandafter\LF@nofcols
\fi}
\def\LF@tabularcr{%
\relax\iffalse{\fi\ifnum0=`}\fi
\@ifstar
{\def\crcr{\LF@crcr\noalign{\nobreak}}\let\cr\crcr
\LF@t@bularcr}%
{\LF@t@bularcr}}
\let\LF@crcr\crcr
\let\LF@setprevdepth\relax
\def\LF@t@bularcr{%
\global\advance\LF@rows\@ne
\ifnum\LF@rows=\LFchunksize
\gdef\LF@setprevdepth{%
\prevdepth\z@\global
\global\let\LF@setprevdepth\relax}%
\expandafter\LF@xtabularcr
\else
\ifnum0=`{}\fi
\expandafter\LF@LL@FM@cr
\fi}
\def\LF@xtabularcr{%
\@ifnextchar[\LF@argtabularcr\LF@ntabularcr}
\def\LF@ntabularcr{%
\ifnum0=`{}\fi
\LF@echunk
\LF@start
\unvbox\z@
\LF@get@widths
\LF@bchunk}
\def\LF@argtabularcr[#1]{%
\ifnum0=`{}\fi
\ifdim #1>\z@
\unskip\@xargarraycr{#1}%
\else
\@yargarraycr{#1}%
\fi
\LF@echunk
\LF@start
\unvbox\z@
\LF@get@widths
\LF@bchunk}
\def\LF@echunk{%
\crcr\LF@save@row\cr\egroup
\global\setbox\@ne\lastbox
\unskip
\egroup}
\def\LF@entry#1#2{%
\ifhmode\@firstofone{&}\fi\omit
\ifnum#1=\c@LF@chunks
\else
\kern#2\relax
\fi}
\def\LF@entry@chop#1#2{%
\noexpand\LF@entry
{\ifnum#1>\c@LF@chunks
1}{0pt%
\else
#1}{#2%
\fi}}
\def\LF@entry@write{%
\noexpand\LF@entry^^J%
\@spaces}
\def\LF@kill{%
\LF@echunk
\LF@get@widths
\expandafter\LF@rebox\LF@bchunk}
\def\LF@rebox#1\bgroup{%
#1\bgroup
\unvbox\z@
\unskip
\setbox\z@\lastbox}
\def\LF@blank@row{%
\xdef\LF@save@row{\expandafter\LF@build@blank
\romannumeral\number\LF@cols 001 }}
\def\LF@build@blank#1{%
\if#1m%
\noexpand\LF@entry{1}{0pt}%
\expandafter\LF@build@blank
\fi}
\def\LF@make@row{%
\global\expandafter\let\expandafter\LF@save@row
\csname LF@\romannumeral\c@LF@tables\endcsname
\ifx\LF@save@row\relax
\LF@blank@row
\else
{\let\LF@entry\or
\if!%
\ifcase\expandafter\expandafter\expandafter\LF@cols
\expandafter\@gobble\LF@save@row
\or
\else
\relax
\fi
!%
\else
\aftergroup\LF@blank@row
\fi}%
\fi}
\let\setlongfigures\relax
\def\LF@get@widths{%
\setbox\tw@\hbox{%
\unhbox\@ne
\let\LF@old@row\LF@save@row
\global\let\LF@save@row\@empty
\count@\LF@cols
\loop
\unskip
\setbox\tw@\lastbox
\ifhbox\tw@
\LF@def@row
\advance\count@\m@ne
\repeat}%
\ifx\LF@@save@row\@undefined
\let\LF@@save@row\LF@save@row
\fi}
\def\LF@def@row{%
\let\LF@entry\or
\edef\@tempa{%
\ifcase\expandafter\count@\LF@old@row
\else
{1}{0pt}%
\fi}%
\let\LF@entry\relax
\xdef\LF@save@row{%
\LF@entry
\expandafter\LF@max@sel\@tempa
\LF@save@row}}
\def\LF@max@sel#1#2{%
{\ifdim#2=\wd\tw@
#1%
\else
\number\c@LF@chunks
\fi}%
{\the\wd\tw@}}
\def\LF@hline{%
\noalign{\ifnum0=`}\fi
\penalty\@M
\futurelet\@let@token\LF@@hline}
\def\LF@@hline{%
\ifx\@let@token\hline
\global\let\@gtempa\@gobble
\gdef\LF@sep{\penalty-\@medpenalty\vskip\doublerulesep}%
\else
\global\let\@gtempa\@empty
\gdef\LF@sep{\penalty-\@lowpenalty\vskip-\arrayrulewidth}%
\fi
\ifnum0=`{\fi}%
\multispan\LF@cols
\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
\noalign{\LF@sep}%
\multispan\LF@cols
\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
\noalign{\penalty\@M}%
\@gtempa}
% \end{macrocode}
% \subsection{Captioning}
% You can easily change how a long figure is captioned by
% redefining the \cs{LF@makecaption} macro after loading the |longfigure| package.
% The following statements show the default definition of the
% \cs{LF@makecaption}:
%
% \begin{macrocode}
\def\LF@caption{%
\noalign\bgroup
\@ifnextchar[{\egroup\LF@c@ption\@firstofone}\LF@capti@n}
% \end{macrocode}
% The \cs{LF@caption} command begins the process.
% If it includes an optional argument, it calls \cs{LF@c@ption}; otherwise
% it calls \cs{LF@capti@n}, which then calls \cs{LF@c@ption}.
% \begin{macrocode}
\def\LF@c@ption#1[#2]#3{%
\LF@makecaption#1\LF@name{#3}%
\def\@tempa{#2}%
\ifx\@tempa\@empty\else
% \end{macrocode}
% If a list of long figures is requested, the following code uses the
% previously defined \cs{strcfstr} macro and \cs{ifLF@same} boolean
% to determine the name of the counter and set the output file to
% contain the |longfigure| information.
%
% The code writes to one of the following files.
% \begin{itemize}
% \item If the counter is |figure|, write to the |lof| file.
% \item If the counter is |table|, write to the |lot| file.
% \item Otherwise, write to |lft|, a file created here for this purpose.
% \end{itemize}
%
% \begin{macrocode}
{\let\\\space
\strcfstr{\LFcounter}{figure}
\ifLF@same\def\LFoutfile{lof}\else
\strcfstr{\LFcounter}{table}
\ifLF@same\def\LFoutfile{lot}\else
\def\LFoutfile{lft}\fi\fi
\addcontentsline{\LFoutfile}{\LFcounter}
{\expandafter\protect\expandafter\numberline\expandafter%
{\expandafter\csname the\LFcounter\endcsname}{#2}}}%
\fi
}
% \end{macrocode}
% The \cs{LF@c@ption} macro ends the process when it calls the
% \cs{LF@makecaption} macro, which typesets the caption.
% \begin{macrocode}
\def\LF@capti@n{%
\@ifstar
{\egroup\LF@c@ption\@gobble[]}%
{\egroup\@xdblarg{\LF@c@ption\@firstofone}}}
% \end{macrocode}
%
% If you want to redefine how the |longfigure| is captioned,
% you need to override the following macro.
% The first argument is the name of the counter
% (for example, |Figure|), the second argument is the number of the counter, and the
% third argument is the caption itself.
% \begin{macrocode}
\def\LF@makecaption#1#2#3{%
\LF@mcol\LF@cols c{\hbox to\z@{\hss\parbox[t]\LFcapwidth{%
\sbox\@tempboxa{#1{#2: }#3}%
\ifdim\wd\@tempboxa>\hsize
#1{#2: }#3%
\else
\hbox to\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\endgraf\vskip\baselineskip}%
\hss}}}
\def\LF@output{%
\ifnum\outputpenalty <-\@Mi
\ifnum\outputpenalty > -\LF@end@pen
\LF@err{floats and marginpars not allowed in a longfigure}\@ehc
\else
\setbox\z@\vbox{\unvbox\@cclv}%
\ifdim \ht\LF@lastfoot>\ht\LF@foot
\dimen@\pagegoal
\advance\dimen@-\ht\LF@lastfoot
\ifdim\dimen@<\ht\z@
\setbox\@cclv\vbox{\unvbox\z@\copy\LF@foot\vss}%
\@makecol
\@outputpage
\setbox\z@\vbox{\box\LF@head}%
\fi
\fi
\global\@colroom\@colht
\global\vsize\@colht
\vbox
{\unvbox\z@\box\ifvoid\LF@lastfoot\LF@foot\else
\LF@lastfoot\fi}%
\fi
\else
\setbox\@cclv\vbox{\unvbox\@cclv\copy\LF@foot\vss}%
\@makecol
\@outputpage
\global\vsize\@colroom
\copy\LF@head\nobreak
\fi}
\def\LF@end@hd@ft#1{%
\LF@echunk
\ifx\LF@start\endgraf
\LF@err
{Longfigure head or foot not at start of table}%
{Increase LFchunksize}%
\fi
\setbox#1\box\z@
\LF@get@widths
\LF@bchunk}
% \end{macrocode}
% The following four macros do not have an \cs{LT} prefix in the |longtable| package,
% but they must be redefined to have an \cs{LF} prefix in order to avoid a namespace clash;
% \begin{macrocode}
\def\endLFfirsthead{\LF@end@hd@ft\LF@firsthead}
\def\endLFhead{\LF@end@hd@ft\LF@head}
\def\endLFfoot{\LF@end@hd@ft\LF@foot}
\def\endLFlastfoot{\LF@end@hd@ft\LF@lastfoot}
%
\def\LF@startpbox#1{%
\bgroup
\let\@footnotetext\LF@p@ftntext
\setlength\hsize{#1}%
\@arrayparboxrestore
\vrule \@height \ht\@arstrutbox \@width \z@}
\def\LF@endpbox{%
\@finalstrut\@arstrutbox
\egroup
\the\LF@p@ftn
\global\LF@p@ftn{}%
\hfil}
\def\LF@p@ftntext#1{%
\edef\@tempa{\the\LF@p@ftn\noexpand\footnotetext[\the\c@footnote]}%
\global\LF@p@ftn\expandafter{\@tempa{#1}}}%
% \end{macrocode}
% \subsection{References}
%
% Carlisle, D. 2004.
% \emph{The longtable Package}.
% Included in the ``Comprehensive \TeX\ Archive Network.'' \url{http://ctan.org}.
%
% Lazarides, Y. 2010.
% \TeX stackexchange, online forum. \url{http://tex.stackexchange.com/questions/7992}.
%
% Sch\"opf, R, B. Raichle, and C. Rowley. 2001.
% \emph{A New Implementation of \LaTeX's \texttt{verbatim} and \texttt{verbatim*} Environments}.
% Originally appeared in TUGboat 1990, 11(2), 284--296.
%
% Thanh, H., S. Rahtz, H. Hagen, and H. Henkel. 2009.
% ``The pdf\TeX\ User's Manual,'' Revision 655, corresponding to pdf\TeX\ 1.40.11.
% \url{www.tug.org/applications/pdftex}.
%
% Wilson, P. 2001.
% \emph{Glisterings}. In TUGboat 22(4), 339--340.
%
%
% \iffalse
%</longfigure>
% \fi
%\Finale
%\endinput
|