I'm using the attachfile LaTeX package (in PDFLaTeX) to embed files in a PDF and I've run into a difficulty regarding what I suspect is the 'filename' of the embedded file.

I can attach/embed files in the following manner:

\textattachfile[author=Zapp Brannigan, color=0 0 0]{my_directory/my_file.dat}{\detokenize{my_file.dat}}

The file seems to be embedded successfully in the resulting PDF and is accessible, but the file name suggested by the Evince PDF viewer when selecting to "Save Attachment As..." on the link for the attached file is the following:


So, you can see that it is including the path of the original file in this 'filename'. Obviously, there are difficulties when one tries to save the attached file under this suggested filename.

How might I go about changing this suggested filename to something such as my_file.dat? I've experimented and I've consulted documentation on the attachfile package and have not been able to come up with an answer.

Just as a quick note: I am disinclined to use a package other than attachfile because, in reality, my code is more complicated than that shown; I'm including custom icons for various file types, as permitted by the attachfile package. However, I'll keep an open mind.

Thank you very much for any thoughts you may have on the matter.

  • 1
    Moving my_file.dat one directory level upwards, i.e. \textattachfile[author=Zapp Brannigan, color=0 0 0]{my_file.dat}{\detokenize{my_file.dat}}, should solve the problem (if you are in a hurry), but of course this is no real solution. The attachfile2 package "is a further development of Scott Pakin’s package attachfile for pdfTEX. Apart from bug fixes, package attachfile2 adds support for dvips, some new options, gets and writes meta information data about the attached files."
    – Stephen
    Commented Aug 3, 2012 at 18:10
  • With Adobe Reader (on Mac OS X) I get my_file.dat without any reference to my_directory.
    – egreg
    Commented Aug 3, 2012 at 20:13

2 Answers 2


I haven't tried to get TeX to automatically parse the filename component for you (but if you're interested, I'm sure someone else could help with that), but the following patches the \textattachfile macro to require an extra argument, the name of the file as it should appear in the attachment, which has no relation to the name of the file on the hard disk when the PDF is created. That is, the syntax is now \textattachfile[options]{physicalfilepath}{text}{virtualfilename}.


    \def\atfi@textcolor(##1 ##2 ##3)##4{%

% now have to pass an extra argument to \textattachfile, the filename you want the viewer to see (note that Adobe Reader appears to 'hide' the path component)
\textattachfile[author=Zapp Brannigan, color=0 0 0]{my_directory/my_file.dat}{\detokenize{my_file.dat}}{filename_seen_by_viewer.txt}

In your case, you would probably want to change filename_seen_by_viewer.txt to my_file.dat, but I left it like this to illustrate more clearly.

(Just grepping the PDF file for my_directory should be sufficient to indicate that it works.)


An enhancement of this package is called attachfile2 and among other things allows setting a different name with the ucfilespec option. In which case you would remove the folder part. See this answer.

You must log in to answer this question.

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