Graphics, Figures & Tables ⇒ Can you embed graphics in LaTeX code?
Can you embed graphics in LaTeX code?
I'm using pdflatex to generate PDF files from LaTeX code, and the LaTeX is being generated on the fly by a web page. Because pdflatex is being run by the web server, it only has access to one file (the LaTeX code) so I can't use any of the commands which refer to external image files for security reasons.
I'm wondering whether there's a way to embed the image data within the LaTeX code, so that I can place images into my final PDF file without using any external files.
Does anyone know if this is possible?
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Can you embed graphics in LaTeX code?
Re: Can you embed graphics in LaTeX code?
If you're asking about raster graphics like png or jpeg files then I think you may be stuck. A possibility is to use potrace or another tracing utility to turn a raster graphic into a vector graphic and then transform that into pgf or Tikz.
I am a little confused though. Do you mean that the result of pdfLaTeX can read only .tex files and write whatever it likes? LaTeX likes to write a whole bunch of files when it processes and it seems rather odd that it be allowed to do that and not to use other files in the same directory as the source or below. I can see no reason not to allow the upload of graphics files so long as the interface is carefully coded...
Re: Can you embed graphics in LaTeX code?
I'll have to look into TikZ, thanks for the suggestion.
I suppose in theory it would be possible to stick an image file alongside the .tex file before processing, but because everything happens in the temp directory and all the filenames are randomly generated I don't trust it to work properly every time. For example if the image file could not be created, I suspect pdflatex would still successfully produce a PDF file without the image. Maybe I'm just being overly cautious, but I'd much rather have everything in one input .tex file - less room for error and less error handling code required!
Can you embed graphics in LaTeX code?
http://sourceforge.net/projects/eps2pgf/
You'll be able to put the contents of the file generated into your tex source file. Be warned though, depending on how complex the graphic is this can slow down the compilation!
I'm not sure if this still works, but I once coaxed Inkscape into converting an eps file into TikZ.
Can you embed graphics in LaTeX code?
Code: Select all
ERROR: A PostScript error occurred.
ERROR: Type: Error: /undefined in q
ERROR: Operand stack (max top 10 items):
ERROR: (empty)
ERROR: Execution failed due to a PostScript error in the input file.
I decided this was going to be too difficult so I relented and tried to make it work the "normal" way, referencing an external image file. Unfortunately that doesn't seem to work either - regardless of what produces the image (I tried Inkscape and epstopdf) I get this error from pdflatex:
Code: Select all
Error: May not be a PDF file (continuing anyway)
Error: PDF file is damaged - attempting to reconstruct xref table...
Error: Couldn't find trailer dictionary
Error: Couldn't read xref table
!pdfTeX error: pdflatex (file ./logoc.pdf): xpdf: reading PDF image failed
==> Fatal error occurred, no output PDF file produced!
