I am currently in the process of writing a document using plain TeX and would like to be able to attach other relevant files to the resulting pdf. I have experience using the attachfile, attachfile2 and embedfile packages (successfully) for this purpose (in LaTeX) in the past.

Whilst I could revert to using LaTeX, I would prefer to define a suitable macro for use in plain TeX. I have read the relevant sections of the pdf specification as well as the pdfTeX user manual however I have not yet been able to create a macro which makes this possible.

I would greatly appreciate any thoughts and/or assistance.

Edit 1: Reference Documents

Please find below links to relevant reference documents:

Edit 2: Current Solution Approach

System Information:

  • Fedora 20
  • pdfTeX 3.1415926

Please find below the code for a minimal working example as well as my current approach which uses only plain TeX and pdfTeX primitives.

File: alphabet.txt

This is the file that is to be attached to the document.


File: minimal.tex

This file makes use of the attachfile2 package to demonstrate how this can be achieved using LaTeX (pdfLaTeX).


    Hello, world!

    \textattachfile{alphabet.txt}{some annotation}


File: test.tex

\def\res@space{ }



    \immediate\pdfobj stream attr{%
        /Type /EmbeddedFile
        /Params <<
            /Size \pdffilesize{#1}
            /ModDate (\pdffilemoddate{#1})
            /CheckSum <\pdfmdfivesum file {#1}>
    } file {#1}

    \immediate\pdfxform 1

            /Type /Filespec
            /FS (#1)
            /EF <<
                /F \the\res@count@obj@file\res@space 0 R

    \pdfannot   width \the\res@box@wd
                height \the\res@box@ht
                depth \the\res@box@dp {
        /Subtype /FileAttachment
        /AP <<
            /N \the\res@count@obj@xform\res@space 0 R
            /R \the\res@count@obj@xform\res@space 0 R
            /D \the\res@count@obj@xform\res@space 0 R
        /F \the\res@count@obj@file
        /FS \the\res@count@obj@fspec\res@space 0 R

\def\res@attachfile#1#2{%    Arg 1:  Annotation
                        %    Arg 2:  Name of file to be attached

Hello, world!

\res@attachfile{some annotation}{alphabet.txt}


Provided that alphabet.txt is stored in the same directory, the desired output can be produced by running:

pdflatex minimal.tex

My current approach is capable of producing a .pdf file which is viewable using Document Viewer (I have not yet checked whether it is capable of being opened by Adobe Reader). The .pdf can be produced by running:

pdftex test.tex

By comparing the output between the two approaches, it appears that the attachment is being embedded correctly. I am not however, able to 'see' the annotation on the pdf and I am unable to open the attachment.

It would be much appreciated if someone could identify the error for me.

  • 2
    Oh! It is very nice that you are thinking of plain TeX equivalents of LaTeX constructions! Difficult, but very interesting. And BTW Welcome to TeX.sx! Oct 19, 2014 at 22:57
  • When you say you'd rather define suitable macros for use in plain TeX, do you mean that you explicitly wish to circumvent the miniltx.tex macros?
    – 1010011010
    Oct 19, 2014 at 23:27
  • @1010011010 Thank you for making me aware of the miniltx.tex macros. It would be my preference to avoid using the miniltx.tex macros in order to avoid introducing dependencies. The purpose of that package appears to be introducing a minimal set of macros to plain TeX in order to make it possible to include LaTeX files directly. Please correct me if I am wrong as I only briefly looked at the file. Oct 19, 2014 at 23:57
  • @PrzemysławScherwentke Thank you for your welcome! Oct 20, 2014 at 0:02
  • 1
    @MarcelKorpel I used a MWE of \input navigator \embeddedfile[foo]{bar}[baz]{159.txt} ABC \finishpdffile \bye with XeTeX and it works for me in Acrobat Pro.
    – ChrisS
    Oct 24, 2014 at 0:12

1 Answer 1


The navigator package allows access to links, attachments and other PDF features in Plain TeX, LaTeX and ConteXt. If you add

\input navigator

to your preamble and


to the end of your document, you can attach a file to your document with

\embeddedfile[<description>]{<object name>}[<alternate file name>]{<file>}

where <description> is the description listed in the PDF viewer, <object name> is the internal name of the attachment, <alternate file name> is the file name listed in the PDF viewer and <file> is, of course, the file you want to attach.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .