4
  • I like to attach the graphic files that I use in a beamer presentation to the generated pdf file.
  • The background is, that I want to enable my colleagues at work to be able to use the graphic files e. g. in PowerPoint (I am the only one using LaTeX at work).
  • I can attach the graphic files using the attachfile package.

Is there a way to automatize this, so that every \includegraphics automatically embeds/attaches the used graphic file?

It would be perfect if I still can use the \includegraphics command unchanged so that I can use this with already existing presentations.

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{attachfile}

\begin{document}

% For example image, see http://tex.stackexchange.com/questions/231738    

\begin{frame}[c]
\frametitle{Frame With Image}
\centering
\includegraphics[width=0.5\textwidth]{example-image.png} 
\textattachfile{example-image.png}{}
\end{frame}

\end{document}

enter image description here

1 Answer 1

7

If you want to generate

\includegraphics[width=0.5\textwidth]{example-image.png} 
\textattachfile{example-image.png}{}

for each image the simplest would be to use

\xgr[width=0.5\textwidth]{example-image.png} 

with \xgr defined in your preamble by

\newcommand\xgr[1][]{%
  \includegraphics[#1]{#2}%
  \textattachfile{#2}{}}

If you want to use \includegraphics (and better as it allows includegraphics to find the real filename if you omit the extension) use

\makeatletter
\let\saved@Gin@setfile\Gin@setfile
\def\Gin@setfile#1#2#3{%
\saved@Gin@setfile{#1}{#2}{#3}%
\textattachfile{#3}{}}
\makeatother

\Gin@setfile is the last "common" macro in the \includegraphics internals which is called after it has resolved any missing extension and looked up the file on the graphics path. it then calls driver-specific code that is different fro pdftex or latex/dvips etc to actually include the image.

#3 is the full filename with extension,

#1 is the "file type" (which determines which internal inclusion macros will be used, typically eps or pdf or some name representing bitmap types, details depend on the driver and which file types it supports,

#2 is the "read file" such as example-image.bb used to find size information from bitmap files, mostly.

So the above just adds a call to attachfile to attach #3.

5
  • Thanks - I wasn't clear enough. It would be perfect if I still can use the includegraphics command unchanged so that I can use this with already existing presentations. Jan 15, 2017 at 15:56
  • @Dr.ManuelKuehner try now Jan 15, 2017 at 16:02
  • Wow - works perfectly in the MWE. It would be great if you could elaborate a bit what you have done (I accept the answer anyway of course). It looks to the untrained eye that you changed some internal commands from the graphicx package?! Jan 15, 2017 at 16:05
  • @Dr.ManuelKuehner well yes but it's my code so doesn't feel that "internal" to me:-) I'll add some words Jan 15, 2017 at 16:07
  • I did not notice that until now - well apparently your packages are legion :) (ctan.org/author/carlisle) Jan 15, 2017 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .