-
Notifications
You must be signed in to change notification settings - Fork 3
/
embedfile.dtx
1987 lines (1962 loc) · 57.4 KB
/
embedfile.dtx
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
% \iffalse meta-comment
%
% File: embedfile.dtx
% Version: 2023-01-12 v2.12
% Info: Embed files into PDF
%
% Copyright (C)
% 2006-2011 Heiko Oberdiek
% 2016-2023 Oberdiek Package Support Group
% https://github.com/ho-tex/embedfile/issues
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
% https://www.latex-project.org/lppl/lppl-1-3c.txt
% and the latest version of this license is in
% https://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainers of this work are
% Heiko Oberdiek and the Oberdiek Package Support Group
% https://github.com/ho-tex/embedfile/issues
%
% The Base Interpreter refers to any `TeX-Format',
% because some files are installed in TDS:tex/generic//.
%
% 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,
% embedfile-test4.tex.
%
% Distribution:
% CTAN:macros/latex/contrib/embedfile/embedfile.dtx
% CTAN:macros/latex/contrib/embedfile/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}
%
% Program 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/generic/embedfile/embedfile.sty
% TDS:tex/generic/embedfile/dtx-attach.sty
% TDS:doc/latex/embedfile/embedfile.pdf
% TDS:doc/latex/embedfile/embedfile-example-plain.tex
% TDS:doc/latex/embedfile/embedfile-example-collection.tex
% TDS:source/latex/embedfile/embedfile.dtx
%
%<*ignore>
\begingroup
\catcode123=1 %
\catcode125=2 %
\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 2023-01-12 v2.12 Embed files into PDF (HO)}
\Msg{************************************************************************}
\keepsilent
\askforoverwritefalse
\let\MetaPrefix\relax
\preamble
This is a generated file.
Project: embedfile
Version: 2023-01-12 v2.12
Copyright (C)
2006-2011 Heiko Oberdiek
2016-2023 Oberdiek Package Support Group
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. This version of this license is in
https://www.latex-project.org/lppl/lppl-1-3c.txt
and the latest version of this license is in
https://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
This work has the LPPL maintenance status "maintained".
The Current Maintainers of this work are
Heiko Oberdiek and the Oberdiek Package Support Group
https://github.com/ho-tex/embedfile/issues
The Base Interpreter refers to any `TeX-Format',
because some files are installed in TDS:tex/generic//.
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,
embedfile-test4.tex.
\endpreamble
\let\MetaPrefix\DoubleperCent
\generate{%
\file{embedfile.ins}{\from{embedfile.dtx}{install}}%
\file{embedfile.drv}{\from{embedfile.dtx}{driver}}%
\usedir{tex/generic/embedfile}%
\file{embedfile.sty}{\from{embedfile.dtx}{package}}%
\usedir{tex/latex/embedfile}%
\file{dtx-attach.sty}{\from{embedfile.dtx}{dtxattach}}%
\usedir{doc/latex/embedfile}%
\file{embedfile-example-plain.tex}{\from{embedfile.dtx}{exampleplain}}%
\file{embedfile-example-collection.tex}{\from{embedfile.dtx}{examplecollection}}%
% \usedir{doc/latex/embedfile/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}}%
% \file{embedfile-test4.tex}{\from{embedfile.dtx}{test4}}%
}
\catcode32=13\relax% active space
\let =\space%
\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}%
[2023-01-12 v2.12 Embed files into PDF (HO)]%
\documentclass{ltxdoc}
\usepackage{holtxdoc}[2011/11/22]
\begin{document}
\DocInput{embedfile.dtx}%
\end{document}
%</driver>
% \fi
%
%
%
% \GetFileInfo{embedfile.drv}
%
% \title{The \xpackage{embedfile} package}
% \date{2023-01-12 v2.12}
% \author{Heiko Oberdiek\thanks
% {Please report any issues at \url{https://github.com/ho-tex/embedfile/issues}}}
%
% \maketitle
%
% \begin{abstract}
% This package embeds files to a PDF document.
% Currently the only supported drivers are \pdfTeX\ $>=$ 1.30 and lua\TeX\ 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 mentioned 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 (8-bit, path separators, \dots), look into
% the PDF specification (\cite{pdfspec}).
% There are rules how these file names must be written/encoded.
% Avoid 8-bit characters
% and other special characters, the behaviour is currently undefined.
% Use option \xoption{ucfilespec} for more funny file names.
% The string method, see below, is |escape| since version 2.4.
%
% This name is also used as entry in a name tree
% (see PDF specification: |/EmbeddedFiles|). Therefore the
% value for \xoption{filespec} must be unique among all
% embedded files. Also key \xoption{initialfiles} refers
% to this name, if the file name and the value of \xoption{filespec}
% are different.
% \item[\xoption{ucfilespec}]
% Since PDF 1.7 the file name may be provided in Unicode.
% It must be provided for PDF/A-3.
% By default the \xoption{filespec} is used.
% The conversion of the option value into a PDF string
% is controlled by option \xoption{stringmethod}.
% Non-ascii chars can look funny if hyperref is not loaded!
% \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{afrelationship}]
% This adds the /AFRelationship key to the filespec dictionary. The value is
% a pdf name with or without the leading slash.
% Typical values are \verb|Source|, \verb|Data|, \verb|Alternative|,
% \verb|Schema| or \verb|Unspecified|. Mandatory for PDF/A-3.
% \item[\xoption{stringmethod}]
% The package must convert the values of the keys \xoption{ucfilespec}
% and \xoption{desc} into a PDF string (before version 2.4: \xoption{filespec}
% and \xoption{desc}). 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}.
% \item[\xoption{id}]
% The value must be an unique name. Macros
% \cs{embedfileifobjectexists} and \cs{embedfilegetobject}
% are using this name later.
% \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}
% Acrobat Reader 10 shows the embedded files in the left panel
% and adds a new column for the compressed size.
%
% 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. There must be an \cs{embedfile} command
% somewhere whose value for key \xoption{filespec} is used here.
% The \cs{embedfile} command can drop option \xoption{filespec}
% if the file name is not different.
% \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{Export of object references}
%
% Caution: This feature is still experimental. It may be even removed
% in future versions. Therefore feedback would be nice, if someone
% has a useful application for this feature.
%
% Object numbers are saved, if \xoption{id} is given in \cs{embedfile}.
% The following objects are supported:
% \begin{itemize}
% \item \texttt{EmbeddedFile}
% \item \texttt{Filespec}
% \end{itemize}
%
% \begin{declcs}{embedfileifobjectexists} \M{id} \M{type}
% \M{then} \M{else}
% \end{declcs}
% Macro \cs{embedfileifobjectexists} tests whether object of \meta{type}
% is available for the embedded file identified by \meta{id}.
%
% \begin{declcs}{embedfilegetobject} \M{id} \M{type}
% \end{declcs}
% Macro \cs{embedfilegetobject} expands to the full object reference
% object of \meta{type} for the embedded file identified by \meta{id}.
%
% \subsubsection{Example}
%
%\begin{quote}
%\begin{verbatim}
%\embedfile[id={foo}]{foo.pdf}
%\embedfileifobjectexists{foo}{Filespec}{%
% \typeout{%
% FileSpec object for `foo': %
% \embedfilegetobject{foo}{Filespec}%
% }%
%}{%
% \typeout{No Filespec object for `foo'}%
%}
%\end{verbatim}
%\end{quote}
%
% \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>
%<<END
% 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
%END
%</exampleplain>
% \end{macrocode}
%
% \subsubsection{Collection example}
%
% \begin{macrocode}
%<*examplecollection>
%<<END
\NeedsTeXFormat{LaTeX2e}
\documentclass{article}
\usepackage[bookmarks=false]{hyperref}
% provides \pdfstringdef that is then used by `title' and
% other keys.
\usepackage{embedfile}[2019/12/03]
\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}
%END
%</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 \CTANpkg{oberdiek}.
% It also serves as small example for the use of the package with \LaTeX.
%
% \begin{macrocode}
%<*dtxattach>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dtx-attach}
[2023-01-12 v2.12 Embed \string\jobname.dtx (HO)]%
\RequirePackage{embedfile}[2019/12/03]
\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\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode35=6 % #
\catcode39=12 % '
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode58=12 % :
\catcode64=11 % @
\catcode123=1 % {
\catcode125=2 % }
\expandafter\let\expandafter\x\csname ver@embedfile.sty\endcsname
\ifx\x\relax % plain-TeX, first loading
\else
\def\empty{}%
\ifx\x\empty % LaTeX, first loading,
% variable is initialized, but \ProvidesPackage not yet seen
\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}%
\aftergroup\endinput
\fi
\fi
\endgroup%
% \end{macrocode}
% Package identification:
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode35=6 % #
\catcode39=12 % '
\catcode40=12 % (
\catcode41=12 % )
\catcode44=12 % ,
\catcode45=12 % -
\catcode46=12 % .
\catcode47=12 % /
\catcode58=12 % :
\catcode64=11 % @
\catcode91=12 % [
\catcode93=12 % ]
\catcode123=1 % {
\catcode125=2 % }
\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\@undefined
\xdef#1{#3}%
\fi
\ifx#1\relax
\xdef#1{#3}%
\fi
}%
\fi
\expandafter\x\csname ver@embedfile.sty\endcsname
\ProvidesPackage{embedfile}%
[2023-01-12 v2.12 Embed files into PDF (HO)]%
% \end{macrocode}
%
% \subsection{Catcodes}
%
% \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode123=1 % {
\catcode125=2 % }
\catcode64=11 % @
\def\x{\endgroup
\expandafter\edef\csname EmFi@AtEnd\endcsname{%
\endlinechar=\the\endlinechar\relax
\catcode13=\the\catcode13\relax
\catcode32=\the\catcode32\relax
\catcode35=\the\catcode35\relax
\catcode61=\the\catcode61\relax
\catcode64=\the\catcode64\relax
\catcode123=\the\catcode123\relax
\catcode125=\the\catcode125\relax
}%
}%
\x\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode35=6 % #
\catcode64=11 % @
\catcode123=1 % {
\catcode125=2 % }
\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{62}{12}% >
\TMP@EnsureCode{91}{12}% [
\TMP@EnsureCode{93}{12}% ]
\TMP@EnsureCode{96}{12}% `
\edef\EmFi@AtEnd{\EmFi@AtEnd\noexpand\endinput}
% \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]%
\ifcsname EmFi@Error\endcsname
\else
\def\EmFi@Error{%
\@PackageError{embedfile}%
}
\fi
% \end{macrocode}
% \end{macro}
%
% Luatex compat
% \begin{macrocode}
\ifx\pdfextension\@undefined\else
\protected\def\pdflastobj {\numexpr\pdffeedback lastobj\relax}
\protected\def\pdfnames {\pdfextension names }
\protected\def\pdfobj {\pdfextension obj }
\protected\def\pdfcatalog {\pdfextension catalog }
\let\pdfoutput \outputmode
\fi
% \end{macrocode}
%
% \subsection{Check for recent \pdfTeX\ in PDF mode}
%
% Load package \xpackage{iftex} and check mode.
% \begin{macrocode}
\EmFi@RequirePackage{iftex}[2019/11/07]
\ifpdf
\else
\EmFi@Error{%
Missing pdfTeX or luaTeX in PDF mode%
}{%
Currently other drivers are not supported. %
Package loading is aborted.%
}%
\expandafter\EmFi@AtEnd
\fi%
% \end{macrocode}
% \begin{macrocode}
\EmFi@RequirePackage{pdftexcmds}[2007/11/11]
\EmFi@RequirePackage{ltxcmds}[2010/03/01]
\EmFi@RequirePackage{kvsetkeys}[2010/03/01]
\EmFi@RequirePackage{kvdefinekeys}[2010/03/01]
% \end{macrocode}
% Check version.
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pdf@filesize\endcsname\relax
\EmFi@Error{%
Unsupported pdfTeX version%
}{%
At least version 1.30 is necessary. Package loading is aborted.%
}%
\expandafter\EmFi@AtEnd
\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/11/11]
% \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@afrelationship}
% \begin{macrocode}
\EmFi@temp{afrelationship}
% \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}
\ltx@newif\ifEmFi@collection
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@sort}
% \begin{macrocode}
\ltx@newif\ifEmFi@sort
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@visible}
% \begin{macrocode}
\ltx@newif\ifEmFi@visible
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@edit}
% \begin{macrocode}
\ltx@newif\ifEmFi@edit
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@item}
% \begin{macrocode}
\ltx@newif\ifEmFi@item
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@finished}
% \begin{macrocode}
\ltx@newif\ifEmFi@finished
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifEmFi@id}
% \begin{macrocode}
\ltx@newif\ifEmFi@id
% \end{macrocode}
% \end{macro}
%
% \subsection{Key value definitions}
%
% \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}
%