The attachfile package allows files to be embedded within the output PDF of a pdfLaTeX document, and the attachfile2 extends this for dvips use as well.

In an article, the author of dvipdfmx gives a recipe for doing the same thing with that driver instead:

this is a text file to be embedded

\special{pdf:fstream @myfile (example.txt)}%
\special{pdf:ann bbox 0 0 10 10 <<
  /Subtype /FileAttachment /FS << 
    /Type /Filespec /F (example.txt)
      /EF << /F @myfile >> >> 
  /Name /PushPin >>}

However, when I compile this with latex+dvipdfmx, I get the following warning:

** WARNING ** Could not open file: example.txt
** WARNING ** Interpreting special command fstream (pdf:) failed.
** WARNING ** >> at page="1" position="(168.14, 707.125)" (in PDF)
** WARNING ** >> xxx "pdf:fstream @myfile (example.txt)"
** WARNING ** Object @myfile used, but not defined. Replaced by null.

Does anyone know what I'm going wrong? (TeX Live 2010, Mac OS X.) It would be great to be able to embed files using this method, since that would facilitate XeTeX use with the attachfile packages.

Update: things seem to work fine in TeX Live 2009. I'm thinking that this is a bug in the latest version of dvipdfmx. Any confirmation on this?

  • 1
    And the big followup question is: who's got the time to incorporate this into attachfile2? – Will Robertson Sep 27 '10 at 8:34
  • 2
    dvipdfmx is now supported in a new version of attachfile2 (2010/09/27 v2.6), which can be found on CTAN. – diabonas May 27 '11 at 11:09

Thanks to Akira Kakuto on the TeX Live mailing list for the answer to this. The current directory is no longer searched for security reasons, so the relative path must be included in the filename:

\special{pdf:fstream @myfile (./example.txt)}%
\special{pdf:ann bbox 0 0 10 10 <<
  /Subtype /FileAttachment /FS << 
    /Type /Filespec /F (./example.txt)
      /EF << /F @myfile >> >> 
  /Name /PushPin >>}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.