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?
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
\IfFileExists{image.png}{}{\write18{...}}
would help with the only-downloading-once problem.
Commented
Nov 16, 2010 at 9:06
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.
(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:
ConTeXt (LuaTeX)
. It didn't work when I tried ConTeXt
(pdfTeX)
.I just added this option in the v2.3 of robust-externalize
(if CTAN does not come with it by default, you can just download the .sty file at the root of your project):
\documentclass{article}
\usepackage{robust-externalize}
\robExtConfigure{enable fallback to manual mode} % Optional, but prints instructions if shell-escape is disabled instead of giving a compilation error.
\begin{document}
Here is a cat downloaded online: \includegraphicsWeb[width=3cm]{http://placekitten.com/400/303}.
\end{document}
Make sure to compile the first time with pdflatex -shell-escape foo.tex
(or manually run the generated bash script if you do not want to enable shell escape), once the image is downloaded you do not need shell escape anymore (since the image is cached in the robustExternalize
folder). Note that you can remove all cached pictures which are not used anymore by running python robExt-remove-old-figures.py
.
By default, it uses wget
in linux and curl
in windows (installed by default starting from Windows 10 I think), but this can easily be customized. Cf documentation for details.
For some reason, the SE bot revived this question after 13 years! I notice that none of the previous answers and comments mentions something vital: possible copyright infringement.
Even though (depending on compiler, recency of software, platform, etc.) it is sometimes possible to pull a web image into the document, and even though it is almost always possible to place a locally downloaded image in the document, that image is likely to be the copyrighted work of someone else. The copyright holder may or may not (usually not) grant a license for usage. Just because you can see it freely, does not mean that you can use it, free or not.
Even if the image does not have a copyright notice as its caption, and even if the web page says nothing, does not mean that it is free. You should look through the web site, to see if there is anything that specifically allows you do download and use any content (such as images). Unless there is an explicit declaration of copyright by someone who can be identified, and that copyright holder grants you explicit license to use it for your purpose, then do not use it.
You may still provide a hyperlink, because this does not involve copying the content. But be aware that links change. What's to stop some prankster from posting an equation, then later changing that image to something naughty?
\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.