I have a small graphic that is part of my document. It's PDF, is 193 lines, and has some binary data mixed with its postscript. I'm currently using the graphicx package and including the pdf as a separate file. Is there a way I can inline it directly in my latex source?
I don't think there is a way to inline binary data in LaTeX. You could recreate graphics as vector type images with various packages (such as Asymptote recommended by lpthnc). If you're really clever you could write some TeX to store the data in array format and recreate it, but I don't think there's a package to do it simply.
you should also take a look at the pdfpages
package. all kinds of options for including PDFs in your PDF document.
pdfpages: http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages/pdfpages.pdf
OK, I think this does what you want, but unless you really need to do something like this, other solutions are better.
To be able to use this solution, you need to:
- enable shell escape in your Latex command (
-shell-escape
command line option). Shell escape is disabled by default because of security reasons. - have access to
uuencode
anduudecode
programs where you're compiling the file.
Let's say your graphic is graphic.png
, and your main document is doc.tex
. First, encode graphic.png
and append it to the end (the encoded data is all text):
$ cat graphic.png | uuencode graphic.jpg >>doc.tex
Then, make sure you have this before you include the graphic in doc.tex
:
\immediate\write18{cat \jobname.tex | uudecode}
For example, here's a document I created:
\documentclass{article}
\immediate\write18{cat \jobname.tex | uudecode}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{graphic}
\end{document}
%%% Do not touch the data below, this is added by uuencode.
begin 644 graphic.png
..... (stripped a lot of lines) ...
`
end
Then, this will work:
$ pdflatex -shell-escape doc
As I said, there are much nicer and better solutions, and unless you really have to have one source file, don't do this.
Here's a solution I devised:
- convert the pdf to postscript using
pdftops
(part of the xpdf package), - convert the postscript to ASCII-only, and
- embed the postscript using the graphicx package and the
\special
macro.
A drawback is that embedding postscript using \special requires me to emit dvi instead of pdf. It would be nice to improve this solution to allow pdf to be emitted directly.
The latex source will look something like this.
\noindent\vbox to 112pt{\vfil\hbox to 248pt{\special{" gsave
currentfile /ASCIIHexDecode filter cvx exec
25 21 50 53 2d 41 64 6f 62 65 2d 33 2e 30 20 45
50 53 46 2d 33 2e 30 0a 25 20 50 72 6f 64 75 63
65 64 20 62 79 20 78 70 64 66 2f 70 64 66 74 6f
70 73 20 33 2e 30 32 0a 25 25 43 72 65 61 74 6f
...
65 72 0a 65 6e 64 0a 25 25 44 6f 63 75 6d 65 6e
74 53 75 70 70 6c 69 65 64 52 65 73 6f 75 72 63
65 73 3a 0a 25 25 45 4f 46 0a
>
grestore
}
\hfil}}
I made a gist at github that provides a complete example.