# Adding to a pdf file the LaTeX code to generate it [duplicate]

I often make some pdf files (not so long) using LaTeX. I often need to later modify these files and I often can not do this because I lost the tex source file. You will say: "Be more careful!"....

Leaving out jokes, I am thinking of a way of creating a pdf file with included the LaTeX code for generating it, but I don't know how to do it (I do not even know if it is possible). The only thing I can imagine is to save the code in the pdf metadata but I don't know how much space they can occupy and a problem is that I would like also to preserve the spacing of the code (indentation and breakline).

So my questions are:

1. Do you think using metadata is a good idea? What about the size (disk space) and the spacing of the code?
2. Have you any other idea to do it?
-

## migrated from stackoverflow.comOct 11 '13 at 21:08

This question came from our site for professional and enthusiast programmers.

## marked as duplicate by Fran, Werner, Thorsten, Torbjørn T., m0nhawkOct 12 '13 at 6:43

TeX files are very small, they are consistently smaller than their output. Unless your document contains many images, you won't notice a size increase. I would caution against distributing your files like this, though. –  Sean Allred Nov 12 '13 at 6:35

Use the attachfile package to include the source code tex file as an attachment to the PDF.

-

You should keep your TeX files under revision control so that you won't lose them so easily.

-
Addendum: TeX files under revision control and backed up on the cloud. –  Sean Allred Nov 12 '13 at 6:33