I'm using MiKTeX 2.9 on a Windows 7 Home Premium 64-bit computer.

I have been experimenting with using attachfile2 to make a link to an embedded LaTeX file. When I compile the following document, named test.tex,

\attachfilesetup{color = myred}
\jobname.tex \textattachfile{test.tex}{view source code}

it works as expected, producing the name of the file and a link:

enter image description here

But when I replace test.tex with \jobname.tex in the \textattachfile command, I get the following error (I am using TeXstudio 2.6.2):

enter image description here

Even putting \expandafter right before \textattachfile, which as far as I understand should ensure that \textattachfile never even sees the command \jobname, doesn't help.

What's going on?

Further observations (not sure if relevant):

  • When I use attachfile instead of attachfile2, it works fine with the \jobname input (of course, the only difference being that I can't use my custom color, which is the reason I wanted to use attachfile2 in the first place).

  • As I mentioned, I'm using TeXstudio. This editor has a convenient feature where it (at least attempts to) detect the commands that are defined by any included packages, and then highlights any commands it doesn't recognize. When I use the attachfile package, the commands \attachfilesetup and \textattachfile are recognized; when I use the attachfile2 package, they are not recognized. Perhaps my copy of the attachfile2 package is broken somehow? MiKTeX tells me that I have the oberdiek bundle installed, which is apparently where attachfile2 lives.

  • I also tried using the currfile package, which provides a macro \currfilename. Nothing different happens when I replace \jobname.tex with \currfilename; it works and doesn't work in the same cases.


Package attachfile had read the backslash in the argument of \textattachfile with verbatim catcode before version 2011/03/27 v1.5b. Package attachfile2 was written in that time before and has followed attachfile in this.

Now (2011/03/27 v1.5b) package attachfile reads the backslash with the usual catcode in \textattachfile to support \jobname (and other macros).

I have updated attachfile2 accordingly: 2013/07/29 v2.10. The package is available here until I release my updated bundle to CTAN later (this year hopefully). The source file attachfile2.dtx is embedded as file attachment. The package file attachfile2.sty with the driver files are unpacked by running plain TeX (or iniTeX) on attachfile2.dtx.

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.