The situation is the following, for certain short latex files, I embed the source in the PDF it self. That can save me time in an emergency if I need to modify the source of a PDF without having to look for the original source (which can be in a different computer far away). This is no rocket science, I simply do:


However in certain situations I don't want other people that have the PDF to look at the Latex source, (for example because of all the comments. Think of a CV)

Of course I can encrypt the embedded file

zip myself.zip --encrypt myself.tex

and use


(note: in reality I have to change the extension .zip to something else because Acrobat refuses to open embedded zip files)

But then I have to run the external command each time (and also suffer from the interactive zip password input).

Something like this would be ideal if exists but I am open to other possibilities:

\embedfile[password=aaa]{myself.tex} %not working code

I don't want the ultimate security but only a layer of hiding of the embedded file.

This can be also useful for embedding other related material, like original graphics or original data tables, etc. not just tex sources.

  • While I like the idea of having the source code nearby, I'd definitely get rid of the attached source code before submitting anything like a CV to someone who shouldn't see the source. It's as easy as commenting out the respective line. I'm having a hard time imagining this "emergency" you're referring to. Nonetheless, it's an interesting question from a technical point of view.
    – doncherry
    Aug 18 '11 at 21:57
  • 4
    One suggestion I have is to use GnuPG to encrypt your myself.tex file and then embed it in the PDF. You can encrypt the tex file in either ASCII (myself.tex.asc -- bigger size but portable) or binary (myself.tex.pgp -- smaller size) formats. Aug 18 '11 at 22:04

It seems that there is not such thing as native encryption (binary or text) of files from TeX. An option would be to issue a command before compilation or a shell command in order to encrypt the file before it is embedded. Doing a little further research I found that there are indeed ways to specify the password non interactively

 \immediate\write18{zip -j -e -P mypassword -r \jobname.tex.zeep \jobname.tex}


 $ zip -j -e -P mypassword -r $0.zeep $0
 $ pdflatex -shell-escape $0

zip can also be replaced by openssl des3 -salt -pass pass:mypassword -in $0 -out $0.de3;

zip is nicer because it opens from the PDF reader using just a double click on the attachments. I also use the extension zeep to avoid stupid email filters.

This is not extremely secure because the password will be visible (still not for the person receiving only the PDF), hopefully it will be a simple passphrase easy to remember at any point.

Thanks Paulo for the inspiration.


I routinely attach source (and other related documents) to a compiled PDF using embedfile, so I can definitely relate to having that 'luxury'. Protecting individual attachments within a PDF is not possible, AFAIK. Not even Adobe Acrobat allows this security of it's attachments. Although this may be old news, you can protect the entire PDF using Acrobat's security features. These are the availabilities (when viewed in Reader):

PDF security settings

Now, you can actually perform this 'intermediate' step (encryption via some other program and attach it to the PDF) using automation, depending on your editor and OS. For example, TeXniCCenter allows for setting up compilation (or building) profiles which allows for batch post-production. Then you can attach an encrypted version of your source to the output PDF using the (free, command line) PDF Toolkit - it provides an attach_files option. If you're running on Linux, a makefile would probably be able to do the same.

  • thanks, I don't see what it the security feature that will 'Not Allow' opening attachments. Yes, a makefile can help, I wonder if there is any program for encrypting with password that won't ask for it interactively.
    – alfC
    Aug 18 '11 at 22:29
  • @alfC: There is no Opening of attachments setting. I've updated the image to reflect Acrobat 9's available settings. Just checked and zip is prompted for a password. However, pdftk does not prompt (haven't tested it - I'm going by the man page and examples) but only works on PDF.
    – Werner
    Aug 18 '11 at 23:18
  • 2
    Actually, encrypting only the attachments is possible since PDF 1.6 (in Adobe Acrobat, the feature is called "Encrypt Only File Attachments", cf. the Acrobat X help). It is implemented using a technique called "crypt filters" - however I don't whether it is possible to implement this in LaTeX.
    – diabonas
    Feb 22 '12 at 12:09

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.