
我正在嘗試修改命令\includegraphics{}
以將所包含文件的名稱(包括其路徑和擴展名)寫入文字檔案。到目前為止我所擁有的是:
\makeatletter
\newwrite\myfile
\immediate\openout\myfile=myfigures.txt
\let\TempCmd\Ginclude@graphics
\renewcommand{\Ginclude@graphics}[1]{\TempCmd{#1}\immediate\write\myfile{#1}}
\makeatother
唯一的問題是,如果未指定檔案副檔名,則不會寫入檔案副檔名。例如,如果我mypic.eps
在一個名為 的子資料夾中寫入figures
,並且我寫入\includegraphics{figures/mypic}
,那麼只有當我想要寫入的內容時myfigures.txt
才會寫入它。figures/mypic
figures/mypic.eps
我嘗試在graphicx.sty和snapshot.sty中閒逛,看看我是否能弄清楚它們如何處理文件擴展名,並自己將一些東西組合在一起,但我還沒有弄清楚。如果我放在\filename@parse{#1}
那裡,我什麼都得不到\filename@ext
。
這是我的最小工作範例(只需提供您選擇的一些圖像):
\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newwrite\myfile
\immediate\openout\myfile=myfigures.txt
\let\TempCmd\Ginclude@graphics
\renewcommand{\Ginclude@graphics}[1]{\TempCmd{#1}\immediate\write\myfile{#1}}
\makeatother
\begin{document}
\includegraphics{mypic}
\end{document}
答案1
graphics
已經在嘗試各種擴展,並根據選擇的後端確定您使用的文件,因此您需要在調用後端實際包含文件之前掛載在那裡,而不是在頂級命令中。
\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newwrite\myfile
\immediate\openout\myfile=myfigures.txt
\let\TempCmd\Gin@setfile
\def\Gin@setfile#1#2#3{\TempCmd{#1}{#2}{#3}\immediate\write\myfile{#3}}
\makeatother
\begin{document}
\includegraphics{mypic}
\end{document}
生產
mypic.png