TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have tried

\includegraphics{http://www.site.com/path/to/figure.png}

But this returns the error

ERROR: Package pdftex.def Error: File
`http://www.website.com/path/to/figure.png'
not found.

Are there other options?

share|improve this question
13  
ConTeXt supports this natively. \externalfigure[http://www.site.com/path/to/figure.png] just works. Behind the scenes, ConTeXt downloads the file to the luatex cache once, and from then on just reuses the figure. – Aditya Nov 16 '10 at 4:36
2  
do you want to add this as an answer? That way, I can select it. – David LeBauer Nov 16 '10 at 5:07
up vote 49 down vote accepted

you could use \write18 and a curl or wget script to grab the image from the web and download it to your directory.

\documentclass{article}
\usepackage{graphicx} % includegraphics command is implemented here
\begin{document}

\write18{wget http://www.some-site.com/path/to/image.png}
\includegraphics{image.png}

\end{document}

note however, that recent versions of miktex and texlive come with restricted versions of \write18, and it some cases you must pass an option to latex to enable it, as in:

pdflatex --shell-escape test.tex
share|improve this answer
    
could you please provide example code in your answer? I did not realize that it was possible to use bash code within latex, although I do use Sweave so I can understand the principle. – David LeBauer Nov 15 '10 at 22:04
    
nice! I guess that this underscores the point that I only need to download the image once in any case. But this approach seems like it would help with portability. – David LeBauer Nov 16 '10 at 3:09
18  
\IfFileExists{image.png}{}{\write18{...}} would help with the only-downloading-once problem. – Will Robertson Nov 16 '10 at 9:06
1  
Could this be done programmatically somehow, maybe with a \renewcommand such that includegraphics can just take the url as an argument? – cboettig Oct 9 '12 at 1:23

Short answer: no. You will need to download the image and use it locally if you want to include it in your document. pdfTeX and XeTeX do not include the necessary code to grab an image from an arbitrary location.

Of course, you can link to an image at at remote location. You can make use of the hyperref package to include a suitable link. You might do this using a bit of text:

\href{http://somewhere.com/someplace/some.jpg}{picture here}

or by downloading a local copy and then pointing to the online version

\href{http://somewhere.com/someplace/some.jpg}{\incudegraphics{some.jpg}}

I note from the comments that LuaTeX does include the necessary library to download a copy of an image itself. That would make inclusion possible directly, but I don't know of a pre-build solution for LuaLaTeX. I guess that would be a separate answer in any case.

share|improve this answer
    
I am not sure if I understand, it seems to me that your short answer contradicts your second answer. And, could you please provide an example of how can I use hyperref to do this? – David LeBauer Nov 16 '10 at 3:07
    
@David: I've added a bit more detail – Joseph Wright Nov 16 '10 at 7:07
    
I'm trying this kind of reference, but it seems to fail - has the relevant functionality been removed? (I'm getting a "some.jpg is missing" error) – blueberryfields May 14 '13 at 17:48

(Copying from the comments section)

ConTeXt supports this natively:

http://wiki.contextgarden.net/What_is_ConTeXt

The following:

\externalfigure[http://www.site.com/path/to/figure.png] 

just works. Behind the scenes, ConTeXt downloads the file to the luatex cache once, and from then on just reuses the figure.


My additional notes:

  • If you have MacTeX, you don't need to do any extra installation. Just change the typesetting option inside your TeX editor.
  • I couldn't get this to work in TeXShop, but it works fine in TeXWorks. Also, I had to use ConTeXt (LuaTeX). It didn't work when I tried ConTeXt (pdfTeX).
share|improve this answer
    
Well, this doesn't answer the question which is about embedding a remote image file using LaTeX. – AlexG Jan 5 at 8:06
    
But it does solve what the user is trying to do, which he explicitly said he is happy to mark as correct. And I started using ConTeXt as a result of what the comment said. Please read up on the XY problem (meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Sridhar-Sarnobat Jan 10 at 7:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.