10

Suppose you have a (PDF)LaTeX file where you include pdf pictures via \includegraphics.

Now, if you want to share the LaTeX file with another person, you always have to send not only the LaTeX file itself but also all the included pdf files containing the pictures. This is pretty inconvenient for recipient.

It would be much more comfortable to copy the pdf source code right into the LaTeX file so that only one file has to be sent. Is that possible?

lpdbw
  • 8,330
  • 1
    That's really not a good idea. Better send a zip file. – Stephan Lehmke Sep 03 '12 at 13:12
  • 4
    Most recipients shouldn't find it inconvenient to receive a zip file of all the needed files? The alternative would be to (for example) base64 encode the pdf file so it is all safe characters and put it in a filecontents environment in the latex file and then specify a graphic rule which base64 decodes the file that latex will then write. But then you have to make sure the recipient's latex setup allows calling external scripts (and that they have a necessary decoder) which is harder to setup usually than simply unzipping an archive. – David Carlisle Sep 03 '12 at 13:14
  • Ah, OK. Wasn't aware it's so difficult. Then of course a zip file seems to be more convenient. Then, maybe one could think of closing/deleting the question!? @moderators: Feel free to do so. – lpdbw Sep 03 '12 at 13:21
  • 1
    @DavidCarlisle: Make your comment to an answer, then there's no need for closing/deleting! – Speravir Sep 03 '12 at 14:06
  • @Speravir answer added – David Carlisle Sep 03 '12 at 14:11

4 Answers4

10

Most recipients shouldn't find it inconvenient to receive a zip file of all the needed files?

The alternative would be to (for example) base64 encode the pdf file so it is all safe characters and put it in a filecontents environment in the latex file and then specify a graphic rule which base64 decodes the file that latex will then write. But then you have to make sure the recipient's latex setup allows calling external scripts (and that they have a necessary decoder) which is harder to setup usually than simply unzipping an archive.

David Carlisle
  • 757,742
3

You can use the attachfile package. Abstract:

This package defines an \attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it. The package also gives you control over the corresponding icon's properties and various other associated metadata.

So, you can attach all files needed ((La)TeX source, PDF images or a zip archive) into your PDF file.

(Obviously, if you want to group only sources LaTeX and PDF images without the resulting PDF file, David Carlisle's answer is more appropriate.)

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • 3
    That's a bit indirect, isn't it. As the main purpose here is not the PDF file but the LaTeX source, it seems a bit like abusing PDF as an inferior zip format... – Stephan Lehmke Sep 03 '12 at 13:39
  • @StephanLehmke It is very practical in many cases : in a tutorial for example... Do you think the PDF format is of inferior quality than the ZIP format? ;-) – Paul Gaborit Sep 03 '12 at 13:49
  • Well it's not mainly meant for storing files, is it? A larger document might include thousands of files; there I'd rather trust a dedicated file format. – Stephan Lehmke Sep 03 '12 at 14:06
  • 1
    @StephanLehmke If it's only the source code of the PDF file, I find it better than carrying a zip file around since one doesn't need to extract or open the zip file for the PDF file. And the source code can be extracted whenever needed. – percusse Sep 03 '12 at 14:21
  • 2
    @percusse It wasn't my understanding that the PDF was supposed to be distributed; only the sources. – Stephan Lehmke Sep 03 '12 at 14:34
  • @StephanLehmke You are certainly right and I probably misunderstood the question. I leave my answer anyway because it responds to the practical aspect and can be useful in other situations. – Paul Gaborit Sep 03 '12 at 20:21
1

Inline encoding of images in LaTeX files isn't for human usage, it's for writing converters. Right now, any converter into LaTeX clutters the current directory with images or subdirectories, often containing large numbers of tiny files. People need to remember to remove them and copy them when they move the converted file around. It would be nice to have an alternative to this.

Mike
  • 11
1

4 years ago, someone by the name of Mike Ashley posted a GitHub gist that exactly solves the OP's original problem.

mhucka
  • 595
  • 5
  • 14
  • 1
    That link doesn't seem to exist anymore?? – user53964 Oct 24 '14 at 13:07
  • Shoot, that's too bad. I looked around and he also seems to have written the answer in response to a tex.sx question here: http://stackoverflow.com/a/1921858/743730 – mhucka Oct 29 '14 at 01:37