オプションを使用して \includegraphics コマンドで使用されるグラフィック ファイルを (PDF 出力に) 自動的に添付する

オプションを使用して \includegraphics コマンドで使用されるグラフィック ファイルを (PDF 出力に) 自動的に添付する

これは次の質問に対するフォローアップです(だけでなく) ビーマー: \includegraphics コマンドで使用されるグラフィック ファイルを (PDF 出力に) 自動的に添付する美しく答えたデビッド・カーライル

1番目の質問ブロック

  1. たとえば、ソースを含む画像と同じファイル名 (および同じ宛先) のテキスト ファイルを添付したいと思います。

  2. これが「欠落ファイル許容型」(利用可能な場合のみテキスト ファイルを添付) であれば完璧です。

以下にその疑似コードを示します。

\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.

2番目の質問ブロック

  1. 特定の写真の添付を無効にすることができるように、\includegraphicsコマンドに追加のオプションを設定する方法はありますか?myAttach=false
  2. デフォルト(オプションが指定されていない場合)では、画像とテキスト ファイルが添付されます。

以下にその疑似コードを示します。

\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 (前回の質問の結果)

\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}

答え1

何かのようなもの

\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}%
\ifGin@attach
\textattachfile{#3}{}%
{\def\Gin@ext{.txt}%
\IfFileExists{#3}{%
\textattachfile{#3}{}%
}{\PackageWarning{graphicx}{no #3 to attach}}%
}%
\fi
}
\newif\ifGin@attach\Gin@attachtrue
\define@key{Gin}{attach}[true]{%
  \lowercase{\Gin@boolkey{#1}}{attach}}

\makeatother

\begin{document}

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

\begin{frame}[c]
\frametitle{Frame With Image}
\centering
\includegraphics[width=0.3\textwidth]{example-image.png} 
\includegraphics[width=0.3\textwidth]{example-image-a.png} 
\includegraphics[width=0.3\textwidth,attach=false]{example-image-b.png} 
\end{frame}

\end{document}

ここに画像の説明を入力してください

( のみがexample-image-a.txt利用可能であった例)

関連情報