This is a follow-up question to (not only) beamer: Automatically Attach Graphic Files (to the PDF Output) that are Used in \includegraphics Command answered beautifully by David Carlisle.
1st Question Block
I would like to attach a text file with the same file name (and same destination) as the picture that contains the source for example.
It would be perfect if this could be "missing file tolerant" (only attach the text file if it's avaialble).
Here's a pseudocode for that:
\includegraphics[width=0.5\textwidth]{example-image.png}
\textattachfile{example-image.png}{}
% If possible
\textattachfile{example-image.txt}{} % <-- Text file containing the source for example.
2nd Question Block
- Is there a way to have an additional option in the
\includegraphicscommand likemyAttach=falseso that I can deactivate the attaching for specific pictures? - Default (no option given) should be that the picture and the text file are attached.
Here's a pseudocode for that:
\includegraphics[width=0.5\textwidth, myAttach = false]{example-image.png}
% If "myAttach = false" is not mentioned
\textattachfile{example-image.png}{}
% If possible AND if "myAttach = false" is not mentioned
\textattachfile{example-image.txt}{} % <-- Text file containing the source for example.
MWE so far (result from previous question)
\documentclass{beamer}
\usepackage{graphicx}
\usepackage{attachfile}
\makeatletter
\let\saved@Gin@setfile\Gin@setfile
\def\Gin@setfile#1#2#3{%
\saved@Gin@setfile{#1}{#2}{#3}%
\textattachfile{#3}{}}
\makeatother
\begin{document}
% For example image, see https://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}

pdfpages. I cannot include a pdf -- it looks like that is somehow also sees the new optionattachand that it doesn't "like" it. Should i open a new question? – Dr. Manuel Kuehner Feb 15 '17 at 18:52\let\Gin@setfile\saved@Gin@setfileto put the original definition back – David Carlisle Feb 15 '17 at 19:11\let\Gin@setfile\saved@Gin@setfile)? – Dr. Manuel Kuehner Feb 15 '17 at 19:29\newcommand\mypdfpages[2][]{{\let\Gin@setfile\saved@Gin@setfile\pdfpages[#1]{#2}}}then use\mypdfpagesprobably works (untested:-) – David Carlisle Feb 15 '17 at 23:01