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
|
% \iffalse meta-comment
%
% Copyright (C) 2006, 2007 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any later
% version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% This Current Maintainer of this work is Heiko Oberdiek.
%
% This work consists of the main source file embedfile.dtx
% and the derived files
% embedfile.sty, embedfile.pdf, embedfile.ins, embedfile.drv,
% dtx-attach.sty, embedfile-example-plain.tex,
% embedfile-example-collection.tex, embedfile-test1.tex,
% embedfile-test2.tex, embedfile-test3.tex.
%
% Distribution:
% CTAN:macros/latex/contrib/oberdiek/embedfile.dtx
% CTAN:macros/latex/contrib/oberdiek/embedfile.pdf
%
% Unpacking:
% (a) If embedfile.ins is present:
% tex embedfile.ins
% (b) Without embedfile.ins:
% tex embedfile.dtx
% (c) If you insist on using LaTeX
% latex \let\install=y\input{embedfile.dtx}
% (quote the arguments according to the demands of your shell)
%
% Documentation:
% (a) If embedfile.drv is present:
% latex embedfile.drv
% (b) Without embedfile.drv:
% latex embedfile.dtx; ...
% The class ltxdoc loads the configuration file ltxdoc.cfg
% if available. Here you can specify further options, e.g.
% use A4 as paper format:
% \PassOptionsToClass{a4paper}{article}
%
% Programm calls to get the documentation (example):
% pdflatex embedfile.dtx
% makeindex -s gind.ist embedfile.idx
% pdflatex embedfile.dtx
% makeindex -s gind.ist embedfile.idx
% pdflatex embedfile.dtx
%
% Installation:
% TDS:tex/latex/oberdiek/embedfile.sty
% TDS:tex/latex/oberdiek/dtx-attach.sty
% TDS:doc/latex/oberdiek/embedfile.pdf
% TDS:doc/latex/oberdiek/embedfile-example-plain.tex
% TDS:doc/latex/oberdiek/embedfile-example-collection.tex
% TDS:doc/latex/oberdiek/test/embedfile-test1.tex
% TDS:doc/latex/oberdiek/test/embedfile-test2.tex
% TDS:doc/latex/oberdiek/test/embedfile-test3.tex
% TDS:source/latex/oberdiek/embedfile.dtx
%
%<*ignore>
\begingroup
\def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
\ifx\csname processbatchFile\endcsname\relax\else1\fi
\ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* Package: embedfile 2007/10/28 v2.0 embed files into PDF (HO)}
\Msg{************************************************************************}
\keepsilent
\askforoverwritefalse
\preamble
This is a generated file.
Copyright (C) 2006, 2007 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3 of this license or (at your option) any later
version. The latest version of this license is in
http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
This work has the LPPL maintenance status "maintained".
This Current Maintainer of this work is Heiko Oberdiek.
This work consists of the main source file embedfile.dtx
and the derived files
embedfile.sty, embedfile.pdf, embedfile.ins, embedfile.drv,
dtx-attach.sty, embedfile-example-plain.tex,
embedfile-example-collection.tex, embedfile-test1.tex,
embedfile-test2.tex, embedfile-test3.tex.
\endpreamble
\generate{%
\file{embedfile.ins}{\from{embedfile.dtx}{install}}%
\file{embedfile.drv}{\from{embedfile.dtx}{driver}}%
\usedir{tex/latex/oberdiek}%
\file{embedfile.sty}{\from{embedfile.dtx}{package}}%
\file{dtx-attach.sty}{\from{embedfile.dtx}{dtxattach}}%
\usedir{doc/latex/oberdiek}%
\file{embedfile-example-plain.tex}{\from{embedfile.dtx}{exampleplain}}%
\file{embedfile-example-collection.tex}{\from{embedfile.dtx}{examplecollection}}%
\usedir{doc/latex/oberdiek/test}%
\file{embedfile-test1.tex}{\from{embedfile.dtx}{test1}}%
\file{embedfile-test2.tex}{\from{embedfile.dtx}{test2}}%
\file{embedfile-test3.tex}{\from{embedfile.dtx}{test3}}%
}
\obeyspaces
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* files into a directory searched by TeX:}
\Msg{*}
\Msg{* embedfile.sty, dtx-attach.sty}
\Msg{*}
\Msg{* To produce the documentation run the file `embedfile.drv'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}
\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{embedfile.drv}%
[2007/10/28 v2.0 embed files into PDF (HO)]%
\documentclass{ltxdoc}
\usepackage{holtxdoc}[2007/10/21]
\begin{document}
\DocInput{embedfile.dtx}%
\end{document}
%</driver>
% \fi
%
% \CheckSum{1223}
%
% \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 \~}
%
% \GetFileInfo{embedfile.drv}
%
% \title{The \xpackage{embedfile} package}
% \date{2007/10/28 v2.0}
% \author{Heiko Oberdiek\\\xemail{oberdiek@uni-freiburg.de}}
%
% \maketitle
%
% \begin{abstract}
% This package embeds files to a PDF document.
% Currently the only supported driver is \pdfTeX\ $>=$ 1.30 in PDF mode.
% \end{abstract}
%
% \tableofcontents
%
% \section{Documentation}
%
% \subsection{Introduction}
%
% The PDF format (\cite{pdfspec}) allows the inclusion of files
% inside the PDF document. The included files can be bound to an
% annotation on a page. Or they can be recorded in a sorted
% list of embedded files. The packages \xpackage{attachfile}
% or \xpackage{attachfile2} follow the first approach, this
% package uses the latter method.
%
% \subsubsection{Future development}
%
% My dream is a large package that merges the features of
% all these packages meantioned before:
% \begin{itemize}
% \item Files can be attached to a page.
% \item Files can be attached to the document.
% \item An easy user interface for simple, common tasks and
% beginners.
% \item An interface for the advanced users that want to setup
% every detail.
% \item Support of many drivers (pdftex, dvips, dvipdfm, \dots).
% \item \dots
% \end{itemize}
% However, I have not managed to take the time for this project.
% Instead:
% \begin{itemize}
% \item First I experimented with package \xpackage{attachfile},
% adding driver support, fixing bugs, \dots. The result is
% currently named as \xpackage{attachfile2}. It uses an external
% script to get file properties (size, date, checksum, \dots).
% \item In order to avoid an external program for getting basic
% file properties I provided a patch ``EscapeAndOther'' for
% pdfTeX that was accepted for version 1.30.
% \item This package closes a gap left by the packages for attaching
% files and allows the embedding of files to the document.
% Also it makes use of the new primitives of \pdfTeX.
% \end{itemize}
%
% \subsection{User interface}
%
% This package \xpackage{embedfile} can be used with both
% \LaTeX\ and \plainTeX. See \autoref{sec:plain} that
% explains the use with \plainTeX\ by an example.
% In \LaTeX\ the package is loaded as usually. There are no options.
% \begin{quote}
% \verb|\usepackage{embedfile}|
% \end{quote}
%
% \begin{declcs}{embedfile}
% |[|\meta{options}|]| \M{file}
% \end{declcs}
% The macro \cs{embedfile} includes file \meta{file} and
% attaches it to the PDF document. At the end of the document
% the sorted list of embedded files are written. Thus you can
% safely use \cs{embedfile} before \verb|\end{document}|.
% Embedding files using \cs{AtEndDocument} will only work,
% if \cs{AtEndDocument} is called before loading the package
% \xpackage{embedfile}.
%
% The \meta{options} are give as key value pairs. The following
% keys are supported:
% \begin{description}
% \item[\xoption{filespec}]
% This allows to override the file name
% that appears in the PDF file. If you are using other than
% simple file names (8bit, path separators, \dots), look into
% the PDF specification (\cite{pdfspec}).
% There are rules how these file names
% must be written/encoded.
% \item[\xoption{filesystem}]
% This sets the entry \verb|/FS| in
% the file specification dictionary, see PDF specification
% (\cite{pdfspec}).
% Example: \verb|filesystem=URL|.
% \item[\xoption{mimetype}]
% This sets the mime type (\cite{mime}) of the file,
% see \autoref{sec:plain} for examples and \cite{types}
% for a list of officially registered types.
% \item[\xoption{desc}]
% The description for the file.
% \item[\xoption{stringmethod}]
% The package must convert the values of the keys \xoption{filespec}
% and \xoption{desc} into a PDF string. If \xpackage{hyperref}
% is found, then its \cs{pdfstringdef} will be used, otherwise
% \pdfTeX's \cs{pdfescapestring} is used. Value \verb|psd|
% forces the use of \cs{pdfstringdef}, value \verb|escape|
% the use of \cs{pdfescapestring}.
% \item[\xoption{\meta{key}.value}] Sets the value of a collection
% item property, see section \ref{sec:collection}.
% \item[\xoption{\meta{key}.prefix}]
% Sets the prefix of a collection item property,
% see section \ref{sec:collection}.
% \end{description}
%
% \begin{declcs}{embedfilefinish}
% \end{declcs}
% The list of all embedded files must be added as data structure
% in the PDF file. In case of \LaTeX\ this is automatically done.
% The package uses \cs{AtEndDocument}. Then the list of all
% files should be known. However, \plainTeX\ does not know
% about \cs{AtEndDocument}. Thus the user must call
% \cs{embedfilefinish} at the end of the document
% after the last file is embedded.
%
% \begin{declcs}{embedfilesetup} \M{options}
% \end{declcs}
% Options for \cs{embedfile} and collection support
% can be set in \cs{embedfilesetup}.
%
% \subsection{Collection support (PDF 1.7)}
% \label{sec:collection}
%
% Since PDF 1.7 the embedded files can form a \emph{collection}
% (sometimes referred as \emph{package}), the main document
% is called \emph{cover sheet}. See PDF specification
% 8.2.4 ``Collections'' and 3.10.5 ``Collection items'' \cite{pdfspec}.
%
% Usually Acrobat Reader 7 or 8 shows the
% embedded files in a table at the bottom with the following columns:
% \begin{quote}
% \begin{tabular}{@{}l|l|l|l@{}}
% Name & Description & Modified & Size\\
% \hline
% \dots & \dots & \dots & \dots\\
% \end{tabular}
% \end{quote}
% If the files form a collection, then they are displayed
% in a table left or top (depending on option \xoption{view},
% see \cs{embedfilesetup}).
%
% Collection support is enabled automatically, if
% it is used.
%
% \begin{declcs}{embedfilesetup} \M{options}
% \end{declcs}
% The following options are supported in addition
% to options for \cs{embedfile}:
% \begin{description}
% \item[\xoption{view}]
% If the PDF file contains a collection, then Acrobat Reader 8
% shows a line at the top below the menu bar and the toolbar.
% It shows the current selected file, icons for changing the
% view mode, an options menu.
% The initial mode how the collection is presented is
% set by this option \xoption{view}.
% The following modes/values are supported, the default is |details|:
% \begin{description}
% \item[\texttt{details}] The full collection table is displayed
% at the top below the collection bar.
% \item[\texttt{tile}] The files of the collection are shown
% in tile mode on the left.
% \item[\texttt{hidden}] The collection table is not shown.
% \end{description}
% \item[\xoption{initialfile}]
% Selects the file that is initially presented. Especially
% useful for an embedded PDF file that is then shown instead
% of the cover document.
% \end{description}
%
% \begin{declcs}{embedfilefield} \M{key} \M{options}
% \end{declcs}
% Macro \cs{embedfilefield} defines a column/field in the collection table.
% The name of the field is \meta{key}.
% \begin{description}
% \item[\xoption{type}]
% sets the type of the field. The supported values are:
% \begin{description}
% \item[\texttt{text}] A text field. Its value is set in
% \cs{embedfile} by option \xoption{\meta{key}.value}.
% \item[\texttt{date}] A date field. Its value is set in
% \cs{embedfile} by option \xoption{\meta{key}.value}.
% A special format is required, see ``3.8.3 Dates'' \cite{pdfspec}.
% \item[\texttt{number}] A field with an integer or float number.
% Its value is set in \cs{embedfile} by option
% \xoption{\meta{key}.value}.
% \item[\texttt{file}] The file name of the embedded file.
% \item[\texttt{desc}] The description text of the embedded file. It is
% set in \cs{embedfile} by option \xoption{desc}.
% \item[\texttt{moddate}] The modification date of the embedded file.
% \item[\texttt{size}] The size of the embedded file.
% \end{description}
% All types allow the use of a prefix that is disregarded by
% sorting. The prefix for this field is set in \cs{embedfile} by
% option \xoption{\meta{key}.prefix}.
% \item[\xoption{title}] sets the column title.
% \item[\xoption{visible}] controls whether the column is presented:
% \begin{description}
% \item[\texttt{true}] shows the column.
% \item[\texttt{false}] hides the column.
% \end{description}
% Default: \texttt{true}
% \item[\xoption{edit}]
% Allows the editing of field values. Does not seem to have an
% effect for Acrobat Reader.
% \begin{description}
% \item[\texttt{true}] enables the feature, if available (depends
% on the PDF viewer).
% \item[\texttt{false}] disables the feature.
% \end{description}
% Default: \texttt{false}
% \end{description}
% The order of \cs{embedfilefield} statements defines the order
% of the columns.
%
% \begin{declcs}{embedfilesort} \M{key-sort-list}
% \end{declcs}
% The sort order of the embedded files are controlled by
% macro \cs{embedfilesort}. \meta{key-sort-list} defines
% the sort order. The key is a field name defined by \cs{embedfilefield}.
% Its value is either \texttt{ascending} or \texttt{descending}.
% The default is \texttt{ascending}.
%
% \subsection{Examples}
% \label{sec:examples}
%
% \subsubsection{\plainTeX}
% \label{sec:plain}
%
% The package can be used with \plainTeX. It can be used
% with or without help from \xfile{miniltx.tex}.
%
% If additionally package \xpackage{keyval} (\xpackage{graphicx})
% is needed, load it first. Then package \xpackage{embedfile} avoids
% a duplicate loading of package \xpackage{keyval}.
%
% Because \plainTeX\ does not provide a hook at end of the document,
% you have to call \cs{embedfilefinish} manually at the end
% after the last embedded file.
% \begin{macrocode}
%<*exampleplain>
% Load packages
\input miniltx
% \def\Gin@driver{pdftex.def}
% \input graphicx.sty
\input embedfile.sty
\resetatcatcode
% default setting
\embedfilesetup{
mimetype=text/plain
}
% Embed files
\embedfile[
filespec=example.tex,
desc={Source code (plain-TeX) of this example}
]{embedfile-example-plain.tex}
\embedfile[
desc={Source of package `embedfile'}
]{embedfile.dtx}
\embedfile[
mimetype=application/pdf,
desc={Documentation of package `embedfile'}
]{embedfile.pdf}
% Some text
This example document contains three embedded files.
% End of document
\embedfilefinish % don't forget
\bye
%</exampleplain>
% \end{macrocode}
%
% \subsubsection{Collection example}
%
% \begin{macrocode}
%<*examplecollection>
\NeedsTeXFormat{LaTeX2e}
\documentclass{article}
\usepackage[bookmarks=false]{hyperref}
% provides \pdfstringdef that is then used by `title' and
% other keys.
\usepackage{embedfile}[2007/10/28]
\embedfilesetup{
view=details,
initialfile=embedfile.pdf
}
\embedfilefield{file}{
type=file,
title={File name}
}
\embedfilefield{description}{
type=desc,
title={Description}
}
\embedfilefield{date}{
type=moddate,
title={Date}
}
\embedfilefield{size}{
type=size,
title={Size}
}
\embedfilefield{type}{
type=text,
title={Type},
visible=false
}
\embedfilesort{
type,
date=descending
}
\begin{document}
An example for embedded files as collection.
You need Acrobat Reader 8 or higher.
\embedfile[
desc={Source file of package `embedfile'},
description.prefix={Package: },
type.value={DTX}
]{embedfile.dtx}
\embedfile[
desc={Documentation of package `embedfile'},
description.prefix={Package: },
type.value={PDF}
]{embedfile.pdf}
\embedfile[
desc={The source for this example},
description.prefix={Example: },
type.value={TEX}
]{\jobname.tex}
\end{document}
%
%</examplecollection>
% \end{macrocode}
%
% \subsection{Package \xpackage{dtx-attach}}
%
% Package \xpackage{dtx-attach} is just a small application of
% package \xpackage{embedfile}. I am using it for the CTAN
% documentation of my packages in \CTAN{macros/latex/contrib/oberdiek/}.
% It also serves as small example for the use of the package with \LaTeX.
%
% \begin{macrocode}
%<*dtxattach>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dtx-attach}
[2007/10/28 v2.0 Embed \string\jobname.dtx (HO)]%
\RequirePackage{embedfile}[2007/10/28]
\embedfile[%
stringmethod=escape,%
mimetype=plain/text,%
desc={LaTeX docstrip source archive for package `\jobname'}%
]{\jobname.dtx}
%</dtxattach>
% \end{macrocode}
%
% \StopEventually{
% }
%
% \section{Implementation}
%
% \begin{macrocode}
%<*package>
% \end{macrocode}
%
% \subsection{Reload check and package identification}
% Reload check, especially if the package is not used with \LaTeX.
% \begin{macrocode}
\begingroup
\catcode44 12 % ,
\catcode45 12 % -
\catcode46 12 % .
\catcode58 12 % :
\catcode64 11 % @
\expandafter\let\expandafter\x\csname ver@embedfile.sty\endcsname
\ifcase 0%
\ifx\x\relax % plain
\else
\ifx\x\empty % LaTeX
\else
1%
\fi
\fi
\else
\expandafter\ifx\csname PackageInfo\endcsname\relax
\def\x#1#2{%
\immediate\write-1{Package #1 Info: #2.}%
}%
\else
\def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
\fi
\x{embedfile}{The package is already loaded}%
\endgroup
\expandafter\endinput
\fi
\endgroup
% \end{macrocode}
% Package identification:
% \begin{macrocode}
\begingroup
\catcode40 12 % (
\catcode41 12 % )
\catcode44 12 % ,
\catcode45 12 % -
\catcode46 12 % .
\catcode47 12 % /
\catcode58 12 % :
\catcode64 11 % @
\expandafter\ifx\csname ProvidesPackage\endcsname\relax
\def\x#1#2#3[#4]{\endgroup
\immediate\write-1{Package: #3 #4}%
\xdef#1{#4}%
}%
\else
\def\x#1#2[#3]{\endgroup
#2[{#3}]%
\ifx#1\relax
\xdef#1{#3}%
\fi
}%
\fi
\expandafter\x\csname ver@embedfile.sty\endcsname
\ProvidesPackage{embedfile}%
[2007/10/28 v2.0 embed files into PDF (HO)]
% \end{macrocode}
%
% \subsection{Catcodes}
%
% \begin{macrocode}
\expandafter\edef\csname EmFi@AtEnd\endcsname{%
\catcode64 \the\catcode64\relax
}
\catcode64 11 % @
\def\TMP@EnsureCode#1#2{%
\edef\EmFi@AtEnd{%
\EmFi@AtEnd
\catcode#1 \the\catcode#1\relax
}%
\catcode#1 #2\relax
}
\TMP@EnsureCode{39}{12}% '
\TMP@EnsureCode{40}{12}% (
\TMP@EnsureCode{41}{12}% )
\TMP@EnsureCode{44}{12}% ,
\TMP@EnsureCode{46}{12}% .
\TMP@EnsureCode{47}{12}% /
\TMP@EnsureCode{58}{12}% :
\TMP@EnsureCode{60}{12}% <
\TMP@EnsureCode{61}{12}% =
\TMP@EnsureCode{62}{12}% >
\TMP@EnsureCode{91}{12}% [
\TMP@EnsureCode{93}{12}% ]
\TMP@EnsureCode{96}{12}% `
% \end{macrocode}
%
% \subsection{Tools}
%
% \begin{macro}{\EmFi@RequirePackage}
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname RequirePackage\endcsname\relax
\def\EmFi@RequirePackage#1[#2]{%
\input #1.sty\relax
}%
\else
\let\EmFi@RequirePackage\RequirePackage
\fi
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\EmFi@Error}
% \begin{macrocode}
\EmFi@RequirePackage{infwarerr}[2007/09/09]%
\def\EmFi@Error{%
\@PackageError{embedfile}%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Check for recent \pdfTeX\ in PDF mode}
%
% Load package \xpackage{ifpdf} and check mode.
% \begin{macrocode}
\EmFi@RequirePackage{ifpdf}[2007/09/09]
\ifpdf
\else
\EmFi@Error{%
Missing pdfTeX in PDF mode%
}{%
Currently other drivers are not supported. %
Package loading is aborted.%
}%
\EmFi@AtEnd
\expandafter\endinput
\fi
% \end{macrocode}
% Check version.
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pdffilesize\endcsname\relax
\EmFi@Error{%
Unsupported pdfTeX version%
}{%
At least version 1.30 is necessary. Package loading is aborted.%
}%
\EmFi@AtEnd
\expandafter\endinput
\fi
% \end{macrocode}
%
% \subsection{Strings}
%
% Minimal version of package \xpackage{pdfescape} is 2007/08/27 v1.5
% because of \cs{EdefSanitize}.
% \begin{macrocode}
\EmFi@RequirePackage{pdfescape}[2007/10/27]
% \end{macrocode}
%
% \begin{macrocode}
\def\EmFi@temp#1{%
\expandafter\EdefSanitize\csname EmFi@S@#1\endcsname{#1}%
}
% \end{macrocode}
% \begin{macro}{\EmFi@details}
% \begin{macrocode}
\EmFi@temp{details}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@tile}
% \begin{macrocode}
\EmFi@temp{tile}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@hidden}
% \begin{macrocode}
\EmFi@temp{hidden}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@text}
% \begin{macrocode}
\EmFi@temp{text}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@date}
% \begin{macrocode}
\EmFi@temp{date}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@number}
% \begin{macrocode}
\EmFi@temp{number}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@file}
% \begin{macrocode}
\EmFi@temp{file}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@desc}
% \begin{macrocode}
\EmFi@temp{desc}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@moddate}
% \begin{macrocode}
\EmFi@temp{moddate}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@creationdate}
% \begin{macrocode}
\EmFi@temp{creationdate}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@size}
% \begin{macrocode}
\EmFi@temp{size}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@ascending}
% \begin{macrocode}
\EmFi@temp{ascending}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@descending}
% \begin{macrocode}
\EmFi@temp{descending}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@true}
% \begin{macrocode}
\EmFi@temp{true}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@S@false}
% \begin{macrocode}
\EmFi@temp{false}
% \end{macrocode}
% \end{macro}
%
% \subsection{Switches}
%
% \begin{macro}{\ifEmFi@collection}
% \begin{macrocode}
\newif\ifEmFi@collection
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@initialfile}
% \begin{macrocode}
\newif\ifEmFi@initialfile
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@sort}
% \begin{macrocode}
\newif\ifEmFi@sort
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@visible}
% \begin{macrocode}
\newif\ifEmFi@visible
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@edit}
% \begin{macrocode}
\newif\ifEmFi@edit
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@item}
% \begin{macrocode}
\newif\ifEmFi@item
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@finished}
% \begin{macrocode}
\newif\ifEmFi@finished
% \end{macrocode}
% \end{macro}
%
% \subsection{Key value definitions}
%
% \begin{macrocode}
\expandafter\ifx\csname define@key\endcsname\relax
\chardef\EmFi@plain=\z@
\def\EmFi@temp#1{%
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname#1\endcsname\relax
\chardef\EmFi@plain=\@ne
\fi
}%
\EmFi@temp{NeedsTeXFormat}%
\EmFi@temp{ProvidesPackage}%
\EmFi@temp{DeclareOption}%
\EmFi@temp{ExecuteOptions}%
\EmFi@temp{ProcessOptions}%
\ifnum\EmFi@plain=\@ne
\def\EmFi@temp#1{%
\expandafter\let\csname EmFi@Org#1\expandafter\endcsname
\csname#1\endcsname
\expandafter\def\csname#1\endcsname
}%
\EmFi@temp{NeedsTeXFormat}#1{}%
\EmFi@temp{ProvidesPackage}#1[#2]{}% hash-ok
\EmFi@temp{DeclareOption}#1{}%
\EmFi@temp{ExecuteOptions}#1{}%
\EmFi@temp{ProcessOptions}{}%
% \end{macrocode}
% \begin{macro}{\KV@errx}
% \LaTeX's option processing is not available with
% \plainTeX. Thus we define the default error
% command \cs{KV@errx} here, also using package
% \xpackage{infwarerr}'s \cs{@PackageError}.
% \begin{macrocode}
\def\KV@errx#1{%
\@PackageError{keyval}{#1}\@ehc
}%
% \end{macrocode}
% \end{macro}
% Other macros from \LaTeX's kernel that are used by
% package \xpackage{keyval}.
% \begin{macro}{\@ifnextchar}
% \begin{macrocode}
\expandafter\ifx\csname @ifnextchar\endcsname\relax
\def\@ifnextchar#1#2#3{%
\let\reserved@d=#1%
\def\reserved@a{#2}%
\def\reserved@b{#3}%
\futurelet\@let@token\@ifnch
}%
\def\@ifnch{%
\ifx\@let@token\@sptoken
\let\reserved@c\@xifnch
\else
\ifx\@let@token\reserved@d
\let\reserved@c\reserved@a
\else
\let\reserved@c\reserved@b
\fi
\fi
\reserved@c
}%
\begingroup
\def\:{\global\let\@sptoken= }%
\: % this makes \@sptoken a space token
\def\:{\@xifnch}%
\expandafter\gdef\: {%
\futurelet\@let@token\@ifnch
}%
\endgroup
\fi
% \end{macrocode}
% \end{macro}
% \begin{macro}{\@namedef}
% \begin{macrocode}
\expandafter\ifx\csname @namedef\endcsname\relax
\def\@namedef#1{%
\expandafter\def\csname#1\endcsname
}%
\fi
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\fi
\EmFi@RequirePackage{keyval}[1999/03/16]%
\ifnum\EmFi@plain=\@ne
\def\EmFi@temp#1{%
\expandafter\let\csname#1\expandafter\endcsname
\csname EmFi@Org#1\endcsname
}%
\EmFi@temp{NeedsTeXFormat}%
\EmFi@temp{ProvidesPackage}%
\EmFi@temp{DeclareOption}%
\EmFi@temp{ExecuteOptions}%
\EmFi@temp{ProcessOptions}%
\fi
\fi
% \end{macrocode}
%
% \begin{macro}{\EmFi@GlobalKey}
% \begin{macrocode}
\def\EmFi@GlobalKey#1#2{%
\global\expandafter\let\csname KV@#1@#2\expandafter\endcsname
\csname KV@#1@#2\endcsname
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@GlobalDefaultKey}
% \begin{macrocode}
\def\EmFi@GlobalDefaultKey#1#2{%
\EmFi@GlobalKey{#1}{#2}%
\global\expandafter\let
\csname KV@#1@#2@default\expandafter\endcsname
\csname KV@#1@#2@default\endcsname
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\EmFi@DefineKey}
% \begin{macrocode}
\def\EmFi@DefineKey#1#2{%
\define@key{EmFi}{#1}{%
\expandafter\def\csname EmFi@#1\endcsname{##1}%
}%
\expandafter\def\csname EmFi@#1\endcsname{#2}%
}
% \end{macrocode}
% \end{macro}
% Subtype of the embedded file (optional).
% \begin{macrocode}
\EmFi@DefineKey{mimetype}{}
% \end{macrocode}
% File specification string.
% \begin{macrocode}
\EmFi@DefineKey{filespec}{\EmFi@file}
% \end{macrocode}
% File system (optional).
% \begin{macrocode}
\EmFi@DefineKey{filesystem}{}
% \end{macrocode}
% Description (optional).
% \begin{macrocode}
\EmFi@DefineKey{desc}{}
% \end{macrocode}
% Method for converting text to PDF strings.
% \begin{macrocode}
\EmFi@DefineKey{stringmethod}{%
\ifx\pdfstringdef\@undefined
escape%
\else
\ifx\pdfstringdef\relax
escape%
\else
psd%
\fi
\fi
}
% \end{macrocode}
%
% Initial view of the collection.
% \begin{macrocode}
\define@key{EmFi}{view}[]{%
\EdefSanitize\EmFi@temp{#1}%
\def\EmFi@next{%
\global\EmFi@collectiontrue
}%
\ifx\EmFi@temp\empty
\let\EmFi@view\EmFi@S@details
\else\ifx\EmFi@temp\EmFi@S@details
\let\EmFi@view\EmFi@S@details
\else\ifx\EmFi@temp\EmFi@S@tile
\let\EmFi@view\EmFi@S@tile
\else\ifx\EmFi@temp\EmFi@S@hidden
\let\EmFi@view\EmFi@S@hidden
\else
\let\EmFi@next\relax
\EmFi@Error{%
Unknown value `\EmFi@temp' for key `view'.\MessageBreak
Supported values: `details', `tile', `hidden'.%
}\@ehc
\fi\fi\fi\fi
\EmFi@next
}
% \end{macrocode}
% \begin{macrocode}
\EmFi@DefineKey{initialfile}{}
% \end{macrocode}
%
% \begin{macro}{\embedfilesetup}
% \begin{macrocode}
\def\embedfilesetup{%
\ifEmFi@finished
\def\EmFi@next##1{}%
\EmFi@Error{%
\string\embedfilefield\space after \string\embedfilefinish
}{%
The list of embedded files is already written.%
}%
\else
\def\EmFi@next{%
\setkeys{EmFi}%
}%
\fi
\EmFi@next
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\EmFi@schema}
% \begin{macrocode}
\def\EmFi@schema{}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@order}
% \begin{macrocode}
\gdef\EmFi@order{0}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@@order}
% \begin{macrocode}
\let\EmFi@@order\relax
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@fieldlist}
% \begin{macrocode}
\def\EmFi@fieldlist{}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@sortcase}
% \begin{macrocode}
\def\EmFi@sortcase{0}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\embedfilefield}
% \begin{macrocode}
\def\embedfilefield#1#2{%
\ifEmFi@finished
\EmFi@Error{%
\string\embedfilefield\space after \string\embedfilefinish
}{%
The list of embedded files is already written.%
}%
\else
\global\EmFi@collectiontrue
\EdefSanitize\EmFi@key{#1}%
\expandafter\ifx\csname KV@EmFi@\EmFi@key.prefix\endcsname\relax
\begingroup
\count@=\EmFi@order
\advance\count@ 1 %
\xdef\EmFi@order{\the\count@}%
\let\EmFi@title\EmFi@key
\let\EmFi@type\EmFi@S@text
\EmFi@visibletrue
\EmFi@editfalse
\setkeys{EmFiFi}{#2}%
\EmFi@convert\EmFi@title\EmFi@title
\xdef\EmFi@schema{%
\EmFi@schema
/\pdfescapename{\EmFi@key}<<%
/Subtype/%
\ifx\EmFi@type\EmFi@S@date D%
\else\ifx\EmFi@type\EmFi@S@number N%
\else\ifx\EmFi@type\EmFi@S@file F%
\else\ifx\EmFi@type\EmFi@S@desc Desc%
\else\ifx\EmFi@type\EmFi@S@moddate ModDate%
\else\ifx\EmFi@type\EmFi@S@creationdate CreationDate%
\else\ifx\EmFi@type\EmFi@S@size Size%
\else S%
\fi\fi\fi\fi\fi\fi\fi
/N(\EmFi@title)%
\EmFi@@order{\EmFi@order}%
\ifEmFi@visible
\else
/V false%
\fi
\ifEmFi@edit
/E true%
\fi
>>%
}%
\let\do\relax
\xdef\EmFi@fieldlist{%
\EmFi@fieldlist
\do{\EmFi@key}%
}%
\ifx\EmFi@type\EmFi@S@text
\define@key{EmFi}{\EmFi@key.value}{%
\EmFi@itemtrue
\def\EmFi@temp{##1}%
\EmFi@convert\EmFi@temp\EmFi@temp
\expandafter\def\csname EmFi@V@#1%
\expandafter\endcsname\expandafter{%
\expandafter(\EmFi@temp)%
}%
}%
\EmFi@GlobalKey{EmFi}{\EmFi@key.value}%
\else\ifx\EmFi@type\EmFi@S@date
\define@key{EmFi}{\EmFi@key.value}{%
\EmFi@itemtrue
\def\EmFi@temp{##1}%
\EmFi@convert\EmFi@temp\EmFi@temp
\expandafter\def\csname EmFi@V@#1%
\expandafter\endcsname\expandafter{%
\expandafter(\EmFi@temp)%
}%
}%
\EmFi@GlobalKey{EmFi}{\EmFi@key.value}%
\else\ifx\EmFi@type\EmFi@S@number
\define@key{EmFi}{\EmFi@key.value}{%
\EmFi@itemtrue
\expandafter\EdefSanitize\csname EmFi@V@#1\endcsname{ ##1}%
}%
\EmFi@GlobalKey{EmFi}{\EmFi@key.value}%
\fi\fi\fi
\define@key{EmFi}{\EmFi@key.prefix}{%
\EmFi@itemtrue
\expandafter\def\csname EmFi@P@#1\endcsname{##1}%
}%
\EmFi@GlobalKey{EmFi}{\EmFi@key.prefix}%
\define@key{EmFiSo}{\EmFi@key}[ascending]{%
\EdefSanitize\EmFi@temp{##1}%
\ifx\EmFi@temp\EmFi@S@ascending
\def\EmFi@temp{true}%
\else\ifx\EmFi@temp\EmFi@S@descending
\def\EmFi@temp{false}%
\else
\def\EmFi@temp{}%
\EmFi@Error{%
Unknown sort order `\EmFi@temp'.\MessageBreak
Supported values: `\EmFi@S@ascending', %
`\EmFi@S@descending
}\@ehc
\fi\fi
\ifx\EmFi@temp\empty
\else
\xdef\EmFi@sortkeys{%
\EmFi@sortkeys
/\pdfescapename{#1}%
}%
\ifx\EmFi@sortorders\empty
\global\let\EmFi@sortorders\EmFi@temp
\gdef\EmFi@sortcase{1}%
\else
\xdef\EmFi@sortorders{%
\EmFi@sortorders
\space
\EmFi@temp
}%
\xdef\EmFi@sortcase{2}%
\fi
\fi
}%
\EmFi@GlobalDefaultKey{EmFiSo}\EmFi@key
\endgroup
\else
\EmFi@Error{%
Field `\EmFi@key' is already defined%
}\@ehc
\fi
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\define@key{EmFiFi}{type}{%
\EdefSanitize\EmFi@temp{#1}%
\ifx\EmFi@temp\EmFi@S@text
\let\EmFi@type\EmFi@temp
\else\ifx\EmFi@temp\EmFi@S@date
\let\EmFi@type\EmFi@temp
\else\ifx\EmFi@temp\EmFi@S@number
\let\EmFi@type\EmFi@temp
\else\ifx\EmFi@temp\EmFi@S@file
\let\EmFi@type\EmFi@temp
\else\ifx\EmFi@temp\EmFi@S@desc
\let\EmFi@type\EmFi@temp
\else\ifx\EmFi@temp\EmFi@S@moddate
\let\EmFi@type\EmFi@temp
\else\ifx\EmFi@temp\EmFi@S@creationdate
\let\EmFi@type\EmFi@temp
\else\ifx\EmFi@temp\EmFi@S@size
\let\EmFi@type\EmFi@temp
\else
\EmFi@Error{%
Unknown type `\EmFi@temp'.\MessageBreak
Supported types: `text', `date', `number', `file',\MessageBreak
`desc', `moddate', `creationdate', `size'%
}%
\fi\fi\fi\fi\fi\fi\fi\fi
}
% \end{macrocode}
% \begin{macrocode}
\define@key{EmFiFi}{title}{%
\def\EmFi@title{#1}%
}
% \end{macrocode}
% \begin{macro}{\EmFi@setboolean}
% \begin{macrocode}
\def\EmFi@setboolean#1#2{%
\EdefSanitize\EmFi@temp{#2}%
\ifx\EmFi@temp\EmFi@S@true
\csname EmFi@#1true\endcsname
\else
\ifx\EmFi@temp\EmFi@S@false
\csname EmFi@#1false\endcsname
\else
\EmFi@Error{%
Unknown value `\EmFi@temp' for key `#1'.\MessageBreak
Supported values: `true', `false'%
}\@ehc
\fi
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\define@key{EmFiFi}{visible}[true]{%
\EmFi@setboolean{visible}{#1}%
}
% \end{macrocode}
% \begin{macrocode}
\define@key{EmFiFi}{edit}[true]{%
\EmFi@setboolean{edit}{#1}%
}
% \end{macrocode}
%
% \begin{macro}{\EmFi@sortkeys}
% \begin{macrocode}
\def\EmFi@sortkeys{}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@sortorders}
% \begin{macrocode}
\def\EmFi@sortorders{}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\embedfilesort}
% \begin{macrocode}
\def\embedfilesort{%
\setkeys{EmFiSo}%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Embed the file}
%
% \begin{macro}{\embedfile}
% \begin{macrocode}
\def\embedfile{%
\@ifnextchar[\EmFi@embedfile{\EmFi@embedfile[]}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@embedfile}
% \begin{macrocode}
\def\EmFi@embedfile[#1]#2{%
\ifEmFi@finished
\EmFi@Error{%
\string\embedfile\space after \string\embedfilefinish
}{%
The list of embedded files is already written.%
}%
\else
\begingroup
\def\EmFi@file{#2}%
\ifx\EmFi@file\EmFi@initialfile
\global\EmFi@initialfiletrue
\fi
\setkeys{EmFi}{#1}%
\expandafter\ifx\expandafter\\\pdffilesize{\EmFi@file}\\%
\EmFi@Error{%
File `\EmFi@file' not found%
}{%
The unknown file is not embedded.%
}%
\else
\EmFi@convert\EmFi@filespec\EmFi@@filespec
\ifx\EmFi@desc\empty
\let\EmFi@@desc\empty
\else
\EmFi@convert\EmFi@desc\EmFi@@desc
\fi
\ifEmFi@item
\let\do\EmFi@do
\immediate\pdfobj{%
<<%
\EmFi@fieldlist
>>%
}%
\edef\EmFi@ci{\the\pdflastobj}%
\fi
\immediate\pdfobj stream attr{%
/Type/EmbeddedFile%
\ifx\EmFi@mimetype\empty
\else
/Subtype/\pdfescapename{\EmFi@mimetype}%
\fi
/Params<<%
/ModDate(\pdffilemoddate{\EmFi@file})%
/Size \pdffilesize{\EmFi@file}%
/CheckSum<\pdfmdfivesum file{\EmFi@file}>%
>>%
}file{\EmFi@file}\relax
\immediate\pdfobj{%
<<%
/Type/Filespec%
\ifx\EmFi@filesystem\empty
\else
/FS/\pdfescapename{\EmFi@filesystem}%
\fi
/F(\EmFi@@filespec)%
\ifx\EmFi@@desc\empty
\else
/Desc(\EmFi@@desc)%
\fi
/EF<<%
/F \the\pdflastobj\space 0 R%
>>%
\ifEmFi@item
/CI \EmFi@ci\space 0 R%
\fi
>>%
}%
\EmFi@add{%
\EmFi@@filespec
}{\the\pdflastobj\space 0 R}%
\fi
\endgroup
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@do}
% \begin{macrocode}
\def\EmFi@do#1{%
\expandafter\ifx\csname EmFi@P@#1\endcsname\relax
\expandafter\ifx\csname EmFi@V@#1\endcsname\relax
\else
/\pdfescapename{#1}\csname EmFi@V@#1\endcsname
\fi
\else
/\pdfescapename{#1}<<%
\expandafter\ifx\csname EmFi@V@#1\endcsname\relax
\else
/D\csname EmFi@V@#1\endcsname
\fi
/P(\csname EmFi@P@#1\endcsname)%
>>%
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\EmFi@convert}
% \begin{macrocode}
\def\EmFi@convert#1#2{%
\ifnum\pdfstrcmp{\EmFi@stringmethod}{psd}=0 %
\pdfstringdef\EmFi@temp{#1}%
\let#2\EmFi@temp
\else
\edef#2{\pdfescapestring{#1}}%
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\global\let\EmFi@list\empty
% \end{macrocode}
% \begin{macro}{\EmFi@add}
% Sorting is done by the insertion sort algorithm.
% Probably the sorting could be done more reliable.
% However, the PDF specification is not too clear to me
% regarding precise sorting rules (how to deal with
% different encodings, escaped characters, \dots).
% \begin{macrocode}
\def\EmFi@add#1#2{%
\begingroup
\edef\key{\pdfescapehex{#1}}%
\ifx\EmFi@list\empty
\xdef\EmFi@list{\noexpand\do{\key}{#2}}%
\else
\def\do##1##2{%
\ifnum\pdfstrcmp{##1}{\key}>0 %
\edef\x{%
\toks@{%
\the\toks@%
\noexpand\do{\key}{#2}%
\noexpand\do{##1}{##2}%
}%
}%
\x
\def\do####1####2{%
\toks@\expandafter{\the\toks@\do{####1}{####2}}%
}%
\def\stop{%
\xdef\EmFi@list{\the\toks@}%
}%
\else
\toks@\expandafter{\the\toks@\do{##1}{##2}}%
\fi
}%
\def\stop{%
\xdef\EmFi@list{\the\toks@\noexpand\do{\key}{#2}}%
}%
\toks@{}%
\EmFi@list\stop
\fi
\endgroup
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\embedfilefinish}
% \begin{macrocode}
\def\embedfilefinish{%
\ifEmFi@finished
\EmFi@Error{%
Too many invocations of \string\embedfilefinish
}{%
The list of embedded files is already written.%
}%
\else
\ifx\EmFi@list\empty
\else
% \end{macrocode}
% Write |/EmbeddedFiles| entry.
% \begin{macrocode}
\global\EmFi@finishedtrue
\begingroup
\def\do##1##2{%
<##1>##2%
}%
\immediate\pdfobj{%
<<%
/Names[\EmFi@list]%
>>%
}%
\pdfnames{%
/EmbeddedFiles \the\pdflastobj\space 0 R%
}%
\endgroup
% \end{macrocode}
% Write collection objects.
% \begin{macrocode}
\ifEmFi@initialfile
\EmFi@collectiontrue
\fi
\ifEmFi@collection
\ifEmFi@initialfile
\else
\ifx\EmFi@initialfile\empty
\EmFi@convert\EmFi@initialfile\EmFi@initialfile
\else
\@PackageWarningNoLine{embedfile}{%
Missing initial file `\EmFi@initialfile'\MessageBreak
among the embedded files%
}%
\EmFi@initialfilefalse
\fi
\fi
\ifcase\EmFi@sortcase
\def\EmFi@temp{}%
\or
\def\EmFi@temp{%
/S\EmFi@sortkeys
/A \EmFi@sortorders
}%
\else
\def\EmFi@temp{%
/S[\EmFi@sortkeys]%
/A[\EmFi@sortorders]%
}%
\fi
\def\EmFi@@order##1{%
\ifnum\EmFi@order>1 %
/O ##1%
\fi
}%
\immediate\pdfobj{%
<<%
\ifx\EmFi@schema\empty
\else
/Schema<<\EmFi@schema>>%
\fi
\ifEmFi@initialfile
/D(\EmFi@initialfile)%
\fi
\ifx\EmFi@view\EmFi@S@tile
/View/T%
\else\ifx\EmFi@view\EmFi@S@hidden
/View/H%
\fi\fi
\ifx\EmFi@temp\empty
\EmFi@temp
\else
/Sort<<\EmFi@temp>>%
\fi
>>%
}%
\pdfcatalog{%
/Collection \the\pdflastobj\space0 R%
}%
\fi
\fi
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname AtEndDocument\endcsname\relax
\else
\AtEndDocument{\embedfilefinish}%
\fi
% \end{macrocode}
%
% \begin{macrocode}
\EmFi@AtEnd
%</package>
% \end{macrocode}
%
% \section{Test}
%
% \subsection{Catcode checks for loading}
%
% \begin{macrocode}
%<*test1>
% \end{macrocode}
% \begin{macrocode}
\catcode`\@=11 %
\def\RestoreCatcodes{}
\count@=0 %
\loop
\edef\RestoreCatcodes{%
\RestoreCatcodes
\catcode\the\count@=\the\catcode\count@\relax
}%
\ifnum\count@<255 %
\advance\count@\@ne
\repeat
\def\RangeCatcodeInvalid#1#2{%
\count@=#1\relax
\loop
\catcode\count@=15 %
\ifnum\count@<#2\relax
\advance\count@\@ne
\repeat
}
\def\Test{%
\RangeCatcodeInvalid{0}{47}%
\RangeCatcodeInvalid{58}{64}%
\RangeCatcodeInvalid{91}{96}%
\RangeCatcodeInvalid{123}{255}%
\catcode`\@=12 %
\catcode`\\=0 %
\catcode`\{=1 %
\catcode`\}=2 %
\catcode`\#=6 %
\catcode`\[=12 %
\catcode`\]=12 %
\catcode`\%=14 %
\catcode`\ =10 %
\catcode13=5 %
\input embedfile.sty\relax
\RestoreCatcodes
}
\Test
\csname @@end\endcsname
\end
% \end{macrocode}
% \begin{macrocode}
%</test1>
% \end{macrocode}
%
% \subsection{Simple test}
%
% \begin{macrocode}
%<*test2>
\input embedfile.sty\relax
\embedfile[%
stringmethod=escape,%
mimetype=plain/text,%
desc={LaTeX docstrip source archive for package `embedfile'}%
]{embedfile.dtx}
\nopagenumbers
Test (plain-\TeX): {\tt embedfile.dtx} should be embedded.%
\embedfilefinish
\bye
%</test2>
% \end{macrocode}
% \begin{macrocode}
%<*test3>
\NeedsTeXFormat{LaTeX2e}
\let\SavedJobname\jobname
\def\jobname{embedfile}
\RequirePackage{dtx-attach}[2007/10/28]
\let\jobname\SavedJobname
\documentclass{minimal}
\begin{document}
Test (\LaTeX): \texttt{embedfile.dtx} should be embedded.%
\end{document}
%</test3>
% \end{macrocode}
%
% \section{Installation}
%
% \subsection{Download}
%
% \paragraph{Package.} This package is available on
% CTAN\footnote{\url{ftp://ftp.ctan.org/tex-archive/}}:
% \begin{description}
% \item[\CTAN{macros/latex/contrib/oberdiek/embedfile.dtx}] The source file.
% \item[\CTAN{macros/latex/contrib/oberdiek/embedfile.pdf}] Documentation.
% \end{description}
%
%
% \paragraph{Bundle.} All the packages of the bundle `oberdiek'
% are also available in a TDS compliant ZIP archive. There
% the packages are already unpacked and the documentation files
% are generated. The files and directories obey the TDS standard.
% \begin{description}
% \item[\CTAN{macros/latex/contrib/oberdiek/oberdiek-tds.zip}]
% \end{description}
% \emph{TDS} refers to the standard ``A Directory Structure
% for \TeX\ Files'' (\CTAN{tds/tds.pdf}). Directories
% with \xfile{texmf} in their name are usually organized this way.
%
% \subsection{Bundle installation}
%
% \paragraph{Unpacking.} Unpack the \xfile{oberdiek-tds.zip} in the
% TDS tree (also known as \xfile{texmf} tree) of your choice.
% Example (linux):
% \begin{quote}
% |unzip oberdiek-tds.zip -d ~/texmf|
% \end{quote}
%
% \paragraph{Script installation.}
% Check the directory \xfile{TDS:scripts/oberdiek/} for
% scripts that need further installation steps.
% Package \xpackage{attachfile2} comes with the Perl script
% \xfile{pdfatfi.pl} that should be installed in such a way
% that it can be called as \texttt{pdfatfi}.
% Example (linux):
% \begin{quote}
% |chmod +x scripts/oberdiek/pdfatfi.pl|\\
% |cp scripts/oberdiek/pdfatfi.pl /usr/local/bin/|
% \end{quote}
%
% \subsection{Package installation}
%
% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
% \docstrip\ archive. The files are extracted by running the
% \xfile{.dtx} through \plainTeX:
% \begin{quote}
% \verb|tex embedfile.dtx|
% \end{quote}
%
% \paragraph{TDS.} Now the different files must be moved into
% the different directories in your installation TDS tree
% (also known as \xfile{texmf} tree):
% \begin{quote}
% \def\t{^^A
% \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
% embedfile.sty & tex/latex/oberdiek/embedfile.sty\\
% dtx-attach.sty & tex/latex/oberdiek/dtx-attach.sty\\
% embedfile.pdf & doc/latex/oberdiek/embedfile.pdf\\
% embedfile-example-plain.tex & doc/latex/oberdiek/embedfile-example-plain.tex\\
% embedfile-example-collection.tex & doc/latex/oberdiek/embedfile-example-collection.tex\\
% test/embedfile-test1.tex & doc/latex/oberdiek/test/embedfile-test1.tex\\
% test/embedfile-test2.tex & doc/latex/oberdiek/test/embedfile-test2.tex\\
% test/embedfile-test3.tex & doc/latex/oberdiek/test/embedfile-test3.tex\\
% embedfile.dtx & source/latex/oberdiek/embedfile.dtx\\
% \end{tabular}^^A
% }^^A
% \sbox0{\t}^^A
% \ifdim\wd0>\linewidth
% \begingroup
% \advance\linewidth by\leftmargin
% \advance\linewidth by\rightmargin
% \edef\x{\endgroup
% \def\noexpand\lw{\the\linewidth}^^A
% }\x
% \def\lwbox{^^A
% \leavevmode
% \hbox to \linewidth{^^A
% \kern-\leftmargin\relax
% \hss
% \usebox0
% \hss
% \kern-\rightmargin\relax
% }^^A
% }^^A
% \ifdim\wd0>\lw
% \sbox0{\small\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\footnotesize\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\scriptsize\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\tiny\t}^^A
% \ifdim\wd0>\linewidth
% \lwbox
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \end{quote}
% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
% TDS installing feature, then some files can already be in the right
% place, see the documentation of \docstrip.
%
% \subsection{Refresh file name databases}
%
% If your \TeX~distribution
% (\teTeX, \mikTeX, \dots) relies on file name databases, you must refresh
% these. For example, \teTeX\ users run \verb|texhash| or
% \verb|mktexlsr|.
%
% \subsection{Some details for the interested}
%
% \paragraph{Attached source.}
%
% The PDF documentation on CTAN also includes the
% \xfile{.dtx} source file. It can be extracted by
% AcrobatReader 6 or higher. Another option is \textsf{pdftk},
% e.g. unpack the file into the current directory:
% \begin{quote}
% \verb|pdftk embedfile.pdf unpack_files output .|
% \end{quote}
%
% \paragraph{Unpacking with \LaTeX.}
% The \xfile{.dtx} chooses its action depending on the format:
% \begin{description}
% \item[\plainTeX:] Run \docstrip\ and extract the files.
% \item[\LaTeX:] Generate the documentation.
% \end{description}
% If you insist on using \LaTeX\ for \docstrip\ (really,
% \docstrip\ does not need \LaTeX), then inform the autodetect routine
% about your intention:
% \begin{quote}
% \verb|latex \let\install=y\input{embedfile.dtx}|
% \end{quote}
% Do not forget to quote the argument according to the demands
% of your shell.
%
% \paragraph{Generating the documentation.}
% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
% the documentation. The process can be configured by the
% configuration file \xfile{ltxdoc.cfg}. For instance, put this
% line into this file, if you want to have A4 as paper format:
% \begin{quote}
% \verb|\PassOptionsToClass{a4paper}{article}|
% \end{quote}
% An example follows how to generate the
% documentation with pdf\LaTeX:
% \begin{quote}
%\begin{verbatim}
%pdflatex embedfile.dtx
%makeindex -s gind.ist embedfile.idx
%pdflatex embedfile.dtx
%makeindex -s gind.ist embedfile.idx
%pdflatex embedfile.dtx
%\end{verbatim}
% \end{quote}
%
% \begin{thebibliography}{9}
% \bibitem{attachfile}
% Scott Pakin: \textit{The \xpackage{attachfile} package};
% 2005/02/20 v1.2;
% \CTAN{macros/latex/contrib/attachfile/}.
%
% \bibitem{attachfile2}
% Heiko Oberdiek: \textit{The \xpackage{attachfile2} package};
% 2006/08/16 v2.2;
% \CTAN{macros/latex/contrib/oberdiek/attachfile2.pdf}.
%
% \bibitem{pdfspec}
% Adobe Systems Incorporated:
% \href{http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference.pdf}%
% {\textit{PDF Reference, Sixth Edition, Version 1.7}},%
% Oktober 2006;
% \url{http://www.adobe.com/devnet/pdf/pdf_reference.html}.
%
% \bibitem{mime}
% Network Working Group: RFC 2046, \textit{Multipurpose Internet Mail Extensions (MIME) Part Two:
% Media Types}, November 1996; \url{http://www.rfc-editor.org/}.
%
% \bibitem{types}
% IANA (Internet Assigned Numbers Authority):
% \textit{MIME Media Types}, May 2006;
% \url{http://www.iana.org/assignments/media-types/}.
%
% \end{thebibliography}
%
% \begin{History}
% \begin{Version}{2006/08/16 v1.0}
% \item
% First public version.
% \end{Version}
% \begin{Version}{2007/04/11 v1.1}
% \item
% Line ends sanitized.
% \end{Version}
% \begin{Version}{2007/09/09 v1.2}
% \item
% Fixes for plain-TeX, wrapper for package \xpackage{keyval} added.
% \item
% Catcode section rewritten.
% \end{Version}
% \begin{Version}{2007/10/28 v2.0}
% \item
% Collection support added (PDF 1.7).
% \end{Version}
% \end{History}
%
% \PrintIndex
%
% \Finale
\endinput
|